提交 9616af46 authored 作者: Thomas Mueller's avatar Thomas Mueller

When the system property h2.lobInDatabase is set, reading a BLOB is a bit faster…

When the system property h2.lobInDatabase is set, reading a BLOB is a bit faster because the length is not read.
上级 9eb61c50
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>The SimpleResultSet now has a feature to not close the result set after reading the last row. <ul><li>When the system property h2.lobInDatabase is set, reading a BLOB is a bit faster
because the length is not read.
</li><li>The SimpleResultSet now has a feature to not close the result set after reading the last row.
</li><li>Native fulltext search: the ignore list doesn't need to be all uppercase now. </li><li>Native fulltext search: the ignore list doesn't need to be all uppercase now.
</li><li>Improved statistics output in the Recover tool. </li><li>Improved statistics output in the Recover tool.
</li><li>Issue 269: GROUP BY queries with a column or having clause that contains IN(SELECT ...) </li><li>Issue 269: GROUP BY queries with a column or having clause that contains IN(SELECT ...)
......
...@@ -174,21 +174,26 @@ public class LobStorage { ...@@ -174,21 +174,26 @@ public class LobStorage {
private int seq; private int seq;
private CompressTool compress; private CompressTool compress;
public LobInputStream(Connection conn, long lob) throws IOException { public LobInputStream(Connection conn, long lob, long byteCount) throws IOException {
this.conn = conn; this.conn = conn;
try { this.lob = lob;
this.lob = lob; if (byteCount == -1) {
PreparedStatement prep = conn.prepareStatement( try {
"SELECT BYTE_COUNT FROM " + LOBS + " WHERE ID = ?"); this.lob = lob;
prep.setLong(1, lob); PreparedStatement prep = conn.prepareStatement(
ResultSet rs = prep.executeQuery(); "SELECT BYTE_COUNT FROM " + LOBS + " WHERE ID = ?");
if (!rs.next()) { prep.setLong(1, lob);
throw DbException.get(ErrorCode.IO_EXCEPTION_1, "Missing lob: "+ lob).getSQLException(); ResultSet rs = prep.executeQuery();
if (!rs.next()) {
throw DbException.get(ErrorCode.IO_EXCEPTION_1, "Missing lob: "+ lob).getSQLException();
}
remainingBytes = rs.getLong(1);
rs.close();
} catch (SQLException e) {
throw DbException.convertToIOException(e);
} }
remainingBytes = rs.getLong(1); } else {
rs.close(); remainingBytes = byteCount;
} catch (SQLException e) {
throw DbException.convertToIOException(e);
} }
} }
...@@ -310,11 +315,12 @@ public class LobStorage { ...@@ -310,11 +315,12 @@ public class LobStorage {
* Get the input stream for the given lob. * Get the input stream for the given lob.
* *
* @param lobId the lob id * @param lobId the lob id
* @param byteCount the number of bytes to read, or -1 if not known
* @return the stream * @return the stream
*/ */
public InputStream getInputStream(long lobId) throws IOException { public InputStream getInputStream(long lobId, long byteCount) throws IOException {
init(); init();
return new LobInputStream(conn, lobId); return new LobInputStream(conn, lobId, byteCount);
} }
private ValueLobDb addLob(InputStream in, long maxLength, int type) { private ValueLobDb addLob(InputStream in, long maxLength, int type) {
......
...@@ -276,8 +276,9 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo ...@@ -276,8 +276,9 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
return new BufferedInputStream(new FileStoreInputStream(store, handler, false, alwaysClose), return new BufferedInputStream(new FileStoreInputStream(store, handler, false, alwaysClose),
Constants.IO_BUFFER_SIZE); Constants.IO_BUFFER_SIZE);
} }
long byteCount = (type == Value.BLOB) ? precision : -1;
try { try {
return lobStorage.getInputStream(lobId); return lobStorage.getInputStream(lobId, byteCount);
} catch (IOException e) { } catch (IOException e) {
throw DbException.convertIOException(e, toString()); throw DbException.convertIOException(e, toString());
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论