Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b9cafa06
提交
b9cafa06
authored
7月 19, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Storing lobs in the database has been changed. It is now faster.
上级
cedcc7ae
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
20 行删除
+33
-20
LobStorage.java
h2/src/main/org/h2/store/LobStorage.java
+32
-20
TestLob.java
h2/src/test/org/h2/test/db/TestLob.java
+1
-0
没有找到文件。
h2/src/main/org/h2/store/LobStorage.java
浏览文件 @
b9cafa06
...
...
@@ -51,11 +51,13 @@ public class LobStorage {
private
static
final
int
BLOCK_LENGTH
=
20000
;
private
static
final
boolean
HASH
=
true
;
private
static
final
long
UNIQUE
=
0xffff
;
// each entry needs 16 bytes (2 longs)
private
static
final
int
HASH_CACHE_SIZE
=
8
*
1024
;
private
Connection
conn
;
private
HashMap
<
String
,
PreparedStatement
>
prepared
=
New
.
hashMap
();
private
long
nextBlock
;
private
CompressTool
compress
=
CompressTool
.
getInstance
();
private
long
[]
hashBlocks
=
new
long
[
HASH_CACHE_SIZE
*
2
];
private
final
DataHandler
handler
;
private
boolean
init
;
...
...
@@ -83,14 +85,11 @@ public class LobStorage {
stat
.
execute
(
"CREATE TABLE IF NOT EXISTS "
+
LOBS
+
"(ID BIGINT PRIMARY KEY, BYTE_COUNT BIGINT, TABLE INT) HIDDEN"
);
stat
.
execute
(
"CREATE TABLE IF NOT EXISTS "
+
LOB_MAP
+
"(LOB BIGINT, SEQ INT, BLOCK BIGINT, PRIMARY KEY(LOB, SEQ)) HIDDEN"
);
stat
.
execute
(
"CREATE INDEX IF NOT EXISTS INFORMATION_SCHEMA.INDEX_LOB_MAP_DATA_LOB ON "
+
LOB_MAP
+
"(BLOCK, LOB)"
);
stat
.
execute
(
"CREATE TABLE IF NOT EXISTS "
+
LOB_DATA
+
"(BLOCK BIGINT PRIMARY KEY, COMPRESSED INT, DATA BINARY) HIDDEN"
);
stat
.
execute
(
"CREATE TABLE IF NOT EXISTS "
+
LOB_DATA
+
"(BLOCK BIGINT PRIMARY KEY, COMPRESSED INT,
HASH INT,
DATA BINARY) HIDDEN"
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT MAX(BLOCK) FROM "
+
LOB_DATA
);
rs
.
next
();
nextBlock
=
rs
.
getLong
(
1
)
+
1
;
if
(
HASH
)
{
nextBlock
=
Math
.
max
(
UNIQUE
+
1
,
nextBlock
);
}
}
catch
(
SQLException
e
)
{
throw
DbException
.
convert
(
e
);
}
...
...
@@ -405,31 +404,44 @@ public class LobStorage {
if
(
compressAlgorithm
!=
null
)
{
b
=
compress
.
compress
(
b
,
compressAlgorithm
);
}
int
hash
=
Arrays
.
hashCode
(
b
);
if
(
HASH
)
{
block
=
Arrays
.
hashCode
(
b
)
&
UNIQUE
;
PreparedStatement
prep
=
prepare
(
"SELECT COMPRESSED, DATA FROM "
+
LOB_DATA
+
" WHERE BLOCK = ?"
);
prep
.
setLong
(
1
,
block
);
ResultSet
rs
=
prep
.
executeQuery
();
if
(
rs
.
next
())
{
boolean
compressed
=
rs
.
getInt
(
1
)
!=
0
;
byte
[]
compare
=
rs
.
getBytes
(
2
);
if
(
Arrays
.
equals
(
b
,
compare
)
&&
compressed
==
(
compressAlgorithm
!=
null
))
{
blockExists
=
true
;
}
else
{
block
=
nextBlock
++;
block
=
0
;
int
index
=
hash
&
(
HASH_CACHE_SIZE
-
1
);
long
oldHash
=
hashBlocks
[
index
];
int
hashTableAddWhenReading
;
int
hashTableRemoveWhenDeleting
;
if
(
oldHash
==
hash
)
{
long
old
=
hashBlocks
[
index
+
HASH_CACHE_SIZE
];
PreparedStatement
prep
=
prepare
(
"SELECT COMPRESSED, DATA FROM "
+
LOB_DATA
+
" WHERE BLOCK = ?"
);
prep
.
setLong
(
1
,
old
);
ResultSet
rs
=
prep
.
executeQuery
();
if
(
rs
.
next
())
{
boolean
compressed
=
rs
.
getInt
(
1
)
!=
0
;
byte
[]
compare
=
rs
.
getBytes
(
2
);
if
(
Arrays
.
equals
(
b
,
compare
)
&&
compressed
==
(
compressAlgorithm
!=
null
))
{
blockExists
=
true
;
block
=
old
;
}
}
}
if
(!
blockExists
)
{
block
=
nextBlock
++;
}
hashBlocks
[
index
]
=
hash
;
hashBlocks
[
index
+
HASH_CACHE_SIZE
]
=
block
;
}
else
{
block
=
nextBlock
++;
}
if
(!
blockExists
)
{
PreparedStatement
prep
=
prepare
(
"INSERT INTO "
+
LOB_DATA
+
"(BLOCK, COMPRESSED,
DATA) VALUES(
?, ?, ?)"
);
"INSERT INTO "
+
LOB_DATA
+
"(BLOCK, COMPRESSED,
HASH, DATA) VALUES(?,
?, ?, ?)"
);
prep
.
setLong
(
1
,
block
);
prep
.
setInt
(
2
,
compressAlgorithm
==
null
?
0
:
1
);
prep
.
setBytes
(
3
,
b
);
prep
.
setInt
(
3
,
hash
);
prep
.
setBytes
(
4
,
b
);
prep
.
execute
();
}
PreparedStatement
prep
=
prepare
(
...
...
h2/src/test/org/h2/test/db/TestLob.java
浏览文件 @
b9cafa06
...
...
@@ -44,6 +44,7 @@ public class TestLob extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
System
.
setProperty
(
"h2.lobInDatabase"
,
"true"
);
TestBase
.
createCaller
().
init
().
test
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论