提交 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
<h1>Change Log</h1>
<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>Improved statistics output in the Recover tool.
</li><li>Issue 269: GROUP BY queries with a column or having clause that contains IN(SELECT ...)
......
......@@ -174,21 +174,26 @@ public class LobStorage {
private int seq;
private CompressTool compress;
public LobInputStream(Connection conn, long lob) throws IOException {
public LobInputStream(Connection conn, long lob, long byteCount) throws IOException {
this.conn = conn;
try {
this.lob = lob;
PreparedStatement prep = conn.prepareStatement(
"SELECT BYTE_COUNT FROM " + LOBS + " WHERE ID = ?");
prep.setLong(1, lob);
ResultSet rs = prep.executeQuery();
if (!rs.next()) {
throw DbException.get(ErrorCode.IO_EXCEPTION_1, "Missing lob: "+ lob).getSQLException();
this.lob = lob;
if (byteCount == -1) {
try {
this.lob = lob;
PreparedStatement prep = conn.prepareStatement(
"SELECT BYTE_COUNT FROM " + LOBS + " WHERE ID = ?");
prep.setLong(1, lob);
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);
rs.close();
} catch (SQLException e) {
throw DbException.convertToIOException(e);
} else {
remainingBytes = byteCount;
}
}
......@@ -310,11 +315,12 @@ public class LobStorage {
* Get the input stream for the given lob.
*
* @param lobId the lob id
* @param byteCount the number of bytes to read, or -1 if not known
* @return the stream
*/
public InputStream getInputStream(long lobId) throws IOException {
public InputStream getInputStream(long lobId, long byteCount) throws IOException {
init();
return new LobInputStream(conn, lobId);
return new LobInputStream(conn, lobId, byteCount);
}
private ValueLobDb addLob(InputStream in, long maxLength, int type) {
......
......@@ -276,8 +276,9 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
return new BufferedInputStream(new FileStoreInputStream(store, handler, false, alwaysClose),
Constants.IO_BUFFER_SIZE);
}
long byteCount = (type == Value.BLOB) ? precision : -1;
try {
return lobStorage.getInputStream(lobId);
return lobStorage.getInputStream(lobId, byteCount);
} catch (IOException e) {
throw DbException.convertIOException(e, toString());
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论