Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
59ed4567
提交
59ed4567
authored
10月 06, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Page store: large values in indexed columns could corrupt the index.
上级
64b9cd64
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
132 行增加
和
11 行删除
+132
-11
PageBtree.java
h2/src/main/org/h2/index/PageBtree.java
+0
-1
PageBtreeLeaf.java
h2/src/main/org/h2/index/PageBtreeLeaf.java
+14
-9
PageBtreeNode.java
h2/src/main/org/h2/index/PageBtreeNode.java
+1
-0
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+10
-1
TestPageStore.java
h2/src/test/org/h2/test/unit/TestPageStore.java
+107
-0
没有找到文件。
h2/src/main/org/h2/index/PageBtree.java
浏览文件 @
59ed4567
...
...
@@ -140,7 +140,6 @@ public abstract class PageBtree extends Page {
* @param row the row to add
* @return the split point of this page, or -1 if no split is required
*/
abstract
int
addRowTry
(
SearchRow
row
)
throws
SQLException
;
/**
...
...
h2/src/main/org/h2/index/PageBtreeLeaf.java
浏览文件 @
59ed4567
...
...
@@ -91,11 +91,15 @@ public class PageBtreeLeaf extends PageBtree {
}
int
addRowTry
(
SearchRow
row
)
throws
SQLException
{
return
addRow
(
row
,
true
);
}
private
int
addRow
(
SearchRow
row
,
boolean
tryOnly
)
throws
SQLException
{
int
rowLength
=
index
.
getRowSize
(
data
,
row
,
onlyPosition
);
int
pageSize
=
index
.
getPageStore
().
getPageSize
();
int
last
=
entryCount
==
0
?
pageSize
:
offsets
[
entryCount
-
1
];
if
(
last
-
rowLength
<
start
+
OFFSET_LENGTH
)
{
if
(
entryCount
>
1
)
{
if
(
tryOnly
&&
entryCount
>
1
)
{
int
x
=
find
(
row
,
false
,
true
,
true
);
if
(
entryCount
<
5
)
{
// required, otherwise the index doesn't work correctly
...
...
@@ -107,6 +111,7 @@ public class PageBtreeLeaf extends PageBtree {
int
third
=
entryCount
/
3
;
return
x
<
third
?
third
:
x
>=
2
*
third
?
2
*
third
:
x
;
}
readAllRows
();
onlyPosition
=
true
;
// change the offsets (now storing only positions)
int
o
=
pageSize
;
...
...
@@ -151,7 +156,7 @@ public class PageBtreeLeaf extends PageBtree {
return
-
1
;
}
private
void
removeRow
(
int
i
)
throws
SQLException
{
private
void
removeRow
(
int
at
)
throws
SQLException
{
readAllRows
();
index
.
getPageStore
().
logUndo
(
this
,
data
);
entryCount
--;
...
...
@@ -161,14 +166,14 @@ public class PageBtreeLeaf extends PageBtree {
}
int
[]
newOffsets
=
new
int
[
entryCount
];
SearchRow
[]
newRows
=
new
SearchRow
[
entryCount
];
System
.
arraycopy
(
offsets
,
0
,
newOffsets
,
0
,
i
);
System
.
arraycopy
(
rows
,
0
,
newRows
,
0
,
i
);
int
startNext
=
i
>
0
?
offsets
[
i
-
1
]
:
index
.
getPageStore
().
getPageSize
();
int
rowLength
=
startNext
-
offsets
[
i
];
for
(
int
j
=
i
;
j
<
entryCount
;
j
++)
{
System
.
arraycopy
(
offsets
,
0
,
newOffsets
,
0
,
at
);
System
.
arraycopy
(
rows
,
0
,
newRows
,
0
,
at
);
int
startNext
=
at
>
0
?
offsets
[
at
-
1
]
:
index
.
getPageStore
().
getPageSize
();
int
rowLength
=
startNext
-
offsets
[
at
];
for
(
int
j
=
at
;
j
<
entryCount
;
j
++)
{
newOffsets
[
j
]
=
offsets
[
j
+
1
]
+
rowLength
;
}
System
.
arraycopy
(
rows
,
i
+
1
,
newRows
,
i
,
entryCount
-
i
);
System
.
arraycopy
(
rows
,
at
+
1
,
newRows
,
at
,
entryCount
-
at
);
start
-=
OFFSET_LENGTH
;
offsets
=
newOffsets
;
rows
=
newRows
;
...
...
@@ -182,7 +187,7 @@ public class PageBtreeLeaf extends PageBtree {
int
newPageId
=
index
.
getPageStore
().
allocatePage
();
PageBtreeLeaf
p2
=
PageBtreeLeaf
.
create
(
index
,
newPageId
,
parentPageId
);
for
(
int
i
=
splitPoint
;
i
<
entryCount
;)
{
p2
.
addRow
Try
(
getRow
(
splitPoint
)
);
p2
.
addRow
(
getRow
(
splitPoint
),
false
);
removeRow
(
splitPoint
);
}
return
p2
;
...
...
h2/src/main/org/h2/index/PageBtreeNode.java
浏览文件 @
59ed4567
...
...
@@ -143,6 +143,7 @@ public class PageBtreeNode extends PageBtree {
int
pageSize
=
index
.
getPageStore
().
getPageSize
();
int
last
=
entryCount
==
0
?
pageSize
:
offsets
[
entryCount
-
1
];
if
(
last
-
rowLength
<
start
+
CHILD_OFFSET_PAIR_LENGTH
)
{
readAllRows
();
onlyPosition
=
true
;
// change the offsets (now storing only positions)
int
o
=
pageSize
;
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
59ed4567
...
...
@@ -122,6 +122,9 @@ public class PageDataLeaf extends PageData {
keys
=
new
long
[
entryCount
];
rows
=
new
Row
[
entryCount
];
if
(
type
==
Page
.
TYPE_DATA_LEAF
)
{
if
(
entryCount
!=
1
)
{
Message
.
throwInternalError
(
"entries: "
+
entryCount
);
}
firstOverflowPageId
=
data
.
readInt
();
}
for
(
int
i
=
0
;
i
<
entryCount
;
i
++)
{
...
...
@@ -256,6 +259,9 @@ public class PageDataLeaf extends PageData {
if
(
entryCount
<
0
)
{
Message
.
throwInternalError
();
}
firstOverflowPageId
=
0
;
overflowRowSize
=
0
;
rowRef
=
null
;
int
keyOffsetPairLen
=
2
+
data
.
getVarLongLen
(
keys
[
i
]);
int
[]
newOffsets
=
new
int
[
entryCount
];
long
[]
newKeys
=
new
long
[
entryCount
];
...
...
@@ -333,7 +339,10 @@ public class PageDataLeaf extends PageData {
int
newPageId
=
index
.
getPageStore
().
allocatePage
();
PageDataLeaf
p2
=
PageDataLeaf
.
create
(
index
,
newPageId
,
parentPageId
);
for
(
int
i
=
splitPoint
;
i
<
entryCount
;)
{
p2
.
addRowTry
(
getRowAt
(
splitPoint
));
int
split
=
p2
.
addRowTry
(
getRowAt
(
splitPoint
));
if
(
split
!=
-
1
)
{
Message
.
throwInternalError
(
"split "
+
split
);
}
removeRow
(
splitPoint
);
}
return
p2
;
...
...
h2/src/test/org/h2/test/unit/TestPageStore.java
浏览文件 @
59ed4567
...
...
@@ -7,6 +7,7 @@
package
org
.
h2
.
test
.
unit
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
...
...
@@ -32,6 +33,8 @@ public class TestPageStore extends TestBase {
}
public
void
test
()
throws
Exception
{
testExistingOld
();
testLargeRows
();
testRecoverDropIndex
();
testDropPk
();
testCreatePkLater
();
...
...
@@ -42,6 +45,110 @@ public class TestPageStore extends TestBase {
testFuzzOperations
();
}
private
void
testExistingOld
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
}
Connection
conn
;
deleteDb
(
"pageStore"
);
String
url
;
url
=
"jdbc:h2:"
+
baseDir
+
"/pageStore"
;
conn
=
DriverManager
.
getConnection
(
url
+
";PAGE_STORE=FALSE"
);
conn
.
createStatement
().
execute
(
"create table test(id int) as select 1"
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
);
conn
.
createStatement
().
execute
(
"select * from test"
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
+
";PAGE_STORE=TRUE"
);
conn
.
createStatement
().
execute
(
"create table test(id int) as select 2"
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
);
this
.
assertResult
(
"2"
,
conn
.
createStatement
(),
"select * from test"
);
conn
.
close
();
}
private
void
testLargeRows
()
throws
Exception
{
if
(
config
.
memory
)
{
return
;
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
testLargeRows
(
i
);
}
}
private
void
testLargeRows
(
int
seed
)
throws
Exception
{
deleteDb
(
"pageStore"
);
String
url
=
getURL
(
"pageStore;CACHE_SIZE=16"
,
true
);
Connection
conn
=
null
;
Statement
stat
=
null
;
int
count
=
0
;
try
{
Class
.
forName
(
"org.h2.Driver"
);
conn
=
DriverManager
.
getConnection
(
url
);
stat
=
conn
.
createStatement
();
int
tableCount
=
1
;
PreparedStatement
[]
insert
=
new
PreparedStatement
[
tableCount
];
PreparedStatement
[]
deleteMany
=
new
PreparedStatement
[
tableCount
];
PreparedStatement
[]
updateMany
=
new
PreparedStatement
[
tableCount
];
for
(
int
i
=
0
;
i
<
tableCount
;
i
++)
{
stat
.
execute
(
"create table test"
+
i
+
"(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_test"
+
i
+
" on test"
+
i
+
"(name)"
);
insert
[
i
]
=
conn
.
prepareStatement
(
"insert into test"
+
i
+
" values(?, ? || space(?))"
);
deleteMany
[
i
]
=
conn
.
prepareStatement
(
"delete from test"
+
i
+
" where id between ? and ?"
);
updateMany
[
i
]
=
conn
.
prepareStatement
(
"update test"
+
i
+
" set name=? || space(?) where id between ? and ?"
);
}
Random
random
=
new
Random
(
seed
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
count
=
i
;
PreparedStatement
p
;
if
(
random
.
nextInt
(
100
)
<
95
)
{
p
=
insert
[
random
.
nextInt
(
tableCount
)];
p
.
setInt
(
1
,
i
);
p
.
setInt
(
2
,
i
);
if
(
random
.
nextInt
(
30
)
==
5
)
{
p
.
setInt
(
3
,
3000
);
}
else
{
p
.
setInt
(
3
,
random
.
nextInt
(
100
));
}
p
.
execute
();
}
else
if
(
random
.
nextInt
(
100
)
<
90
)
{
p
=
updateMany
[
random
.
nextInt
(
tableCount
)];
p
.
setInt
(
1
,
i
);
p
.
setInt
(
2
,
random
.
nextInt
(
50
));
int
start
=
random
.
nextInt
(
1
+
i
);
p
.
setInt
(
3
,
start
);
p
.
setInt
(
4
,
start
+
random
.
nextInt
(
50
));
p
.
executeUpdate
();
}
else
{
p
=
deleteMany
[
random
.
nextInt
(
tableCount
)];
int
start
=
random
.
nextInt
(
1
+
i
);
p
.
setInt
(
1
,
start
);
p
.
setInt
(
2
,
start
+
random
.
nextInt
(
100
));
p
.
executeUpdate
();
}
}
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
);
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
url
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"script to '"
+
baseDir
+
"/pageStore.sql'"
);
conn
.
close
();
}
catch
(
Exception
e
)
{
try
{
stat
.
execute
(
"shutdown immediately"
);
}
catch
(
SQLException
e2
)
{
// ignore
}
try
{
conn
.
close
();
}
catch
(
SQLException
e2
)
{
// ignore
}
fail
(
"count: "
+
count
+
" "
+
e
);
}
}
private
void
testRecoverDropIndex
()
throws
SQLException
{
if
(
config
.
memory
)
{
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论