Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1ee1d5a5
提交
1ee1d5a5
authored
11月 26, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new experimental page store
上级
1bf063e5
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
111 行增加
和
57 行删除
+111
-57
PageData.java
h2/src/main/org/h2/index/PageData.java
+16
-1
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+20
-31
PageDataNode.java
h2/src/main/org/h2/index/PageDataNode.java
+68
-19
PageScanCursor.java
h2/src/main/org/h2/index/PageScanCursor.java
+1
-1
PageScanIndex.java
h2/src/main/org/h2/index/PageScanIndex.java
+6
-5
没有找到文件。
h2/src/main/org/h2/index/PageData.java
浏览文件 @
1ee1d5a5
...
@@ -8,6 +8,7 @@ package org.h2.index;
...
@@ -8,6 +8,7 @@ package org.h2.index;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.engine.Session
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.store.DataPageBinary
;
import
org.h2.store.DataPageBinary
;
...
@@ -152,10 +153,16 @@ abstract class PageData {
...
@@ -152,10 +153,16 @@ abstract class PageData {
*
*
* @param id the new parent page id
* @param id the new parent page id
*/
*/
void
setParentPageId
(
int
id
)
{
void
setParentPageId
(
int
id
)
throws
SQLException
{
this
.
parentPageId
=
id
;
this
.
parentPageId
=
id
;
remapChildren
();
}
}
/**
* Update the parent id of all children.
*/
abstract
void
remapChildren
()
throws
SQLException
;
/**
/**
* Remove a row.
* Remove a row.
*
*
...
@@ -164,4 +171,12 @@ abstract class PageData {
...
@@ -164,4 +171,12 @@ abstract class PageData {
*/
*/
abstract
boolean
remove
(
int
key
)
throws
SQLException
;
abstract
boolean
remove
(
int
key
)
throws
SQLException
;
/**
* Get the row for the given key.
*
* @param key the key
* @return the row
*/
abstract
Row
getRow
(
Session
session
,
int
key
)
throws
SQLException
;
}
}
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
1ee1d5a5
...
@@ -9,12 +9,9 @@ package org.h2.index;
...
@@ -9,12 +9,9 @@ package org.h2.index;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Session
;
import
org.h2.engine.Constants
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.store.DataPageBinary
;
import
org.h2.store.DataPageBinary
;
/**
/**
...
@@ -79,7 +76,7 @@ class PageDataLeaf extends PageData {
...
@@ -79,7 +76,7 @@ class PageDataLeaf extends PageData {
void
write
()
throws
SQLException
{
void
write
()
throws
SQLException
{
// make sure rows are read
// make sure rows are read
for
(
int
i
=
0
;
i
<
entryCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
entryCount
;
i
++)
{
getRow
(
i
);
getRow
At
(
i
);
}
}
data
.
reset
();
data
.
reset
();
data
.
writeInt
(
parentPageId
);
data
.
writeInt
(
parentPageId
);
...
@@ -194,7 +191,7 @@ class PageDataLeaf extends PageData {
...
@@ -194,7 +191,7 @@ class PageDataLeaf extends PageData {
* @param index the index
* @param index the index
* @return the row
* @return the row
*/
*/
Row
getRow
(
int
index
)
throws
SQLException
{
Row
getRow
At
(
int
index
)
throws
SQLException
{
Row
r
=
rows
[
index
];
Row
r
=
rows
[
index
];
if
(
r
==
null
)
{
if
(
r
==
null
)
{
data
.
setPos
(
offsets
[
index
]);
data
.
setPos
(
offsets
[
index
]);
...
@@ -213,7 +210,7 @@ class PageDataLeaf extends PageData {
...
@@ -213,7 +210,7 @@ class PageDataLeaf extends PageData {
int
newPageId
=
index
.
getPageStore
().
allocatePage
();
int
newPageId
=
index
.
getPageStore
().
allocatePage
();
PageDataLeaf
p2
=
new
PageDataLeaf
(
index
,
newPageId
,
parentPageId
,
index
.
getPageStore
().
createDataPage
());
PageDataLeaf
p2
=
new
PageDataLeaf
(
index
,
newPageId
,
parentPageId
,
index
.
getPageStore
().
createDataPage
());
for
(
int
i
=
splitPoint
;
i
<
entryCount
;)
{
for
(
int
i
=
splitPoint
;
i
<
entryCount
;)
{
p2
.
addRow
(
getRow
(
splitPoint
));
p2
.
addRow
(
getRow
At
(
splitPoint
));
removeRow
(
splitPoint
);
removeRow
(
splitPoint
);
}
}
return
p2
;
return
p2
;
...
@@ -221,7 +218,7 @@ class PageDataLeaf extends PageData {
...
@@ -221,7 +218,7 @@ class PageDataLeaf extends PageData {
int
getLastKey
()
throws
SQLException
{
int
getLastKey
()
throws
SQLException
{
int
todoRemove
;
int
todoRemove
;
return
getRow
(
entryCount
-
1
).
getPos
();
return
getRow
At
(
entryCount
-
1
).
getPos
();
}
}
public
PageDataLeaf
getNextPage
()
throws
SQLException
{
public
PageDataLeaf
getNextPage
()
throws
SQLException
{
...
@@ -236,6 +233,10 @@ class PageDataLeaf extends PageData {
...
@@ -236,6 +233,10 @@ class PageDataLeaf extends PageData {
return
this
;
return
this
;
}
}
protected
void
remapChildren
()
throws
SQLException
{
int
todoUpdateOverflowPages
;
}
boolean
remove
(
int
key
)
throws
SQLException
{
boolean
remove
(
int
key
)
throws
SQLException
{
int
i
=
find
(
key
);
int
i
=
find
(
key
);
if
(
keys
[
i
]
!=
key
)
{
if
(
keys
[
i
]
!=
key
)
{
...
@@ -244,29 +245,17 @@ class PageDataLeaf extends PageData {
...
@@ -244,29 +245,17 @@ class PageDataLeaf extends PageData {
if
(
entryCount
==
1
)
{
if
(
entryCount
==
1
)
{
return
true
;
return
true
;
}
}
// if (pageData.size() == 1 && !root) {
removeRow
(
i
);
// // the last row has been deleted
write
();
// return oldRow;
return
false
;
// }
}
// pageData.remove(i);
// updateRealByteCount(false, row);
Row
getRow
(
Session
session
,
int
key
)
throws
SQLException
{
// index.updatePage(session, this);
int
index
=
find
(
key
);
// if (i > 0) {
if
(
index
>=
keys
.
length
)
{
// // the first row didn't change
System
.
out
.
println
(
"stop"
);
// return null;
}
// }
return
getRowAt
(
index
);
// if (pageData.size() == 0) {
// return null;
// }
// return getData(0);
// }
// if (comp > 0) {
// r = i;
// } else {
// l = i + 1;
// }
// }
throw
Message
.
getSQLException
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
index
.
getSQL
());
}
}
}
}
h2/src/main/org/h2/index/PageDataNode.java
浏览文件 @
1ee1d5a5
...
@@ -8,11 +8,9 @@ package org.h2.index;
...
@@ -8,11 +8,9 @@ package org.h2.index;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Session
;
import
org.h2.engine.Constants
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.store.DataPageBinary
;
import
org.h2.store.DataPageBinary
;
/**
/**
...
@@ -62,28 +60,36 @@ class PageDataNode extends PageData {
...
@@ -62,28 +60,36 @@ class PageDataNode extends PageData {
index
.
getPageStore
().
writePage
(
pageId
,
data
);
index
.
getPageStore
().
writePage
(
pageId
,
data
);
}
}
int
addRow
(
Row
row
)
throws
SQLException
{
void
addChild
(
int
x
,
int
childPageId
,
int
key
)
{
int
x
=
find
(
row
.
getPos
());
PageData
page
=
index
.
getPage
(
childPageIds
[
x
]);
int
splitPoint
=
page
.
addRow
(
row
);
if
(
splitPoint
==
0
)
{
return
0
;
}
int
pivot
=
page
.
getKey
(
splitPoint
);
PageData
page2
=
page
.
split
(
splitPoint
);
int
[]
newKeys
=
new
int
[
entryCount
+
1
];
int
[]
newKeys
=
new
int
[
entryCount
+
1
];
int
[]
newChildPageIds
=
new
int
[
entryCount
+
2
];
int
[]
newChildPageIds
=
new
int
[
entryCount
+
2
];
if
(
entryCount
>
0
)
{
System
.
arraycopy
(
keys
,
0
,
newKeys
,
0
,
x
);
System
.
arraycopy
(
keys
,
0
,
newKeys
,
0
,
x
);
System
.
arraycopy
(
childPageIds
,
0
,
newChildPageIds
,
0
,
x
);
System
.
arraycopy
(
childPageIds
,
0
,
newChildPageIds
,
0
,
x
+
1
);
if
(
x
<
entryCount
)
{
if
(
x
<
entryCount
)
{
System
.
arraycopy
(
keys
,
x
,
newKeys
,
x
+
1
,
entryCount
-
x
);
System
.
arraycopy
(
keys
,
x
,
newKeys
,
x
+
1
,
entryCount
-
x
);
System
.
arraycopy
(
childPageIds
,
x
,
newChildPageIds
,
x
+
1
,
entryCount
-
x
+
1
);
System
.
arraycopy
(
childPageIds
,
x
,
newChildPageIds
,
x
+
1
,
entryCount
-
x
+
1
);
}
}
newKeys
[
x
]
=
pivot
;
}
newChildPageIds
[
x
]
=
page2
.
getPageId
();
newKeys
[
x
]
=
key
;
newChildPageIds
[
x
+
1
]
=
childPageId
;
keys
=
newKeys
;
keys
=
newKeys
;
childPageIds
=
newChildPageIds
;
childPageIds
=
newChildPageIds
;
entryCount
++;
entryCount
++;
}
int
addRow
(
Row
row
)
throws
SQLException
{
int
x
=
find
(
row
.
getPos
());
PageData
page
=
index
.
getPage
(
childPageIds
[
x
]);
int
splitPoint
=
page
.
addRow
(
row
);
if
(
splitPoint
==
0
)
{
return
0
;
}
int
pivot
=
page
.
getKey
(
splitPoint
);
PageData
page2
=
page
.
split
(
splitPoint
);
page
.
write
();
page2
.
write
();
addChild
(
x
,
page2
.
getPageId
(),
pivot
);
int
maxEntries
=
(
index
.
getPageStore
().
getPageSize
()
-
11
)
/
8
;
int
maxEntries
=
(
index
.
getPageStore
().
getPageSize
()
-
11
)
/
8
;
if
(
entryCount
>=
maxEntries
)
{
if
(
entryCount
>=
maxEntries
)
{
int
todoSplitAtLastInsertionPoint
;
int
todoSplitAtLastInsertionPoint
;
...
@@ -99,8 +105,43 @@ class PageDataNode extends PageData {
...
@@ -99,8 +105,43 @@ class PageDataNode extends PageData {
}
}
PageData
split
(
int
splitPoint
)
throws
SQLException
{
PageData
split
(
int
splitPoint
)
throws
SQLException
{
int
todo
;
int
newPageId
=
index
.
getPageStore
().
allocatePage
();
return
null
;
PageDataNode
p2
=
new
PageDataNode
(
index
,
newPageId
,
parentPageId
,
index
.
getPageStore
().
createDataPage
());
splitPoint
++;
int
firstChild
=
childPageIds
[
splitPoint
];
for
(
int
i
=
splitPoint
;
i
<
entryCount
;)
{
p2
.
addChild
(
p2
.
entryCount
,
childPageIds
[
splitPoint
+
1
],
keys
[
splitPoint
]);
removeChild
(
splitPoint
);
}
int
lastChild
=
childPageIds
[
splitPoint
-
1
];
removeChild
(
splitPoint
-
1
);
childPageIds
[
splitPoint
-
1
]
=
lastChild
;
p2
.
childPageIds
[
0
]
=
firstChild
;
p2
.
remapChildren
();
return
p2
;
}
protected
void
remapChildren
()
throws
SQLException
{
for
(
int
i
=
0
;
i
<
childPageIds
.
length
;
i
++)
{
int
child
=
childPageIds
[
i
];
PageData
p
=
index
.
getPage
(
child
);
p
.
setParentPageId
(
pageId
);
p
.
write
();
}
}
private
void
removeChild
(
int
x
)
{
int
[]
newKeys
=
new
int
[
entryCount
-
1
];
int
[]
newChildPageIds
=
new
int
[
entryCount
];
System
.
arraycopy
(
keys
,
0
,
newKeys
,
0
,
x
);
System
.
arraycopy
(
childPageIds
,
0
,
newChildPageIds
,
0
,
x
+
1
);
if
(
x
<
entryCount
)
{
System
.
arraycopy
(
keys
,
x
+
1
,
newKeys
,
x
,
entryCount
-
x
-
1
);
System
.
arraycopy
(
childPageIds
,
x
+
1
,
newChildPageIds
,
x
,
entryCount
-
x
);
}
keys
=
newKeys
;
childPageIds
=
newChildPageIds
;
entryCount
--;
}
}
/**
/**
...
@@ -172,7 +213,8 @@ class PageDataNode extends PageData {
...
@@ -172,7 +213,8 @@ class PageDataNode extends PageData {
return
false
;
return
false
;
}
}
// this child is now empty
// this child is now empty
if
(
entryCount
==
1
)
{
index
.
getPageStore
().
freePage
(
page
.
getPageId
());
if
(
entryCount
==
0
)
{
// no more children - this page is empty as well
// no more children - this page is empty as well
// it can't be the root otherwise the index would have been
// it can't be the root otherwise the index would have been
// truncated
// truncated
...
@@ -186,7 +228,14 @@ class PageDataNode extends PageData {
...
@@ -186,7 +228,14 @@ class PageDataNode extends PageData {
// otherwise the first row didn't change
// otherwise the first row didn't change
removeRow
(
at
-
1
);
removeRow
(
at
-
1
);
}
}
write
();
return
false
;
return
false
;
}
}
Row
getRow
(
Session
session
,
int
key
)
throws
SQLException
{
int
at
=
find
(
key
);
PageData
page
=
index
.
getPage
(
childPageIds
[
at
]);
return
page
.
getRow
(
session
,
key
);
}
}
}
h2/src/main/org/h2/index/PageScanCursor.java
浏览文件 @
1ee1d5a5
...
@@ -45,7 +45,7 @@ class PageScanCursor implements Cursor {
...
@@ -45,7 +45,7 @@ class PageScanCursor implements Cursor {
return
false
;
return
false
;
}
}
}
}
row
=
current
.
getRow
(
index
);
row
=
current
.
getRow
At
(
index
);
index
++;
index
++;
return
true
;
return
true
;
}
}
...
...
h2/src/main/org/h2/index/PageScanIndex.java
浏览文件 @
1ee1d5a5
...
@@ -62,7 +62,6 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -62,7 +62,6 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
table
.
setRowCount
(
rowCount
);
table
.
setRowCount
(
rowCount
);
}
}
public
void
add
(
Session
session
,
Row
row
)
throws
SQLException
{
public
void
add
(
Session
session
,
Row
row
)
throws
SQLException
{
row
.
setPos
((
int
)
rowCount
);
row
.
setPos
((
int
)
rowCount
);
PageData
root
=
getPage
(
headPos
);
PageData
root
=
getPage
(
headPos
);
...
@@ -75,6 +74,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -75,6 +74,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
int
id
=
store
.
allocatePage
();
int
id
=
store
.
allocatePage
();
page1
.
setPageId
(
id
);
page1
.
setPageId
(
id
);
page1
.
setParentPageId
(
headPos
);
page1
.
setParentPageId
(
headPos
);
page2
.
setParentPageId
(
headPos
);
PageDataNode
newRoot
=
new
PageDataNode
(
this
,
rootPageId
,
Page
.
ROOT
,
store
.
createDataPage
());
PageDataNode
newRoot
=
new
PageDataNode
(
this
,
rootPageId
,
Page
.
ROOT
,
store
.
createDataPage
());
newRoot
.
init
(
page1
,
pivot
,
page2
);
newRoot
.
init
(
page1
,
pivot
,
page2
);
page1
.
write
();
page1
.
write
();
...
@@ -106,7 +106,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -106,7 +106,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
result
=
new
PageDataNode
(
this
,
id
,
parentPageId
,
data
);
result
=
new
PageDataNode
(
this
,
id
,
parentPageId
,
data
);
break
;
break
;
default
:
default
:
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_CORRUPTED_1
,
"type="
+
type
);
throw
Message
.
getSQLException
(
ErrorCode
.
FILE_CORRUPTED_1
,
"
page="
+
id
+
"
type="
+
type
);
}
}
result
.
read
();
result
.
read
();
return
result
;
return
result
;
...
@@ -159,7 +159,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -159,7 +159,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
public
void
truncate
(
Session
session
)
throws
SQLException
{
public
void
truncate
(
Session
session
)
throws
SQLException
{
int
invalidateRowCount
;
int
invalidateRowCount
;
int
todo
;
PageDataLeaf
root
=
new
PageDataLeaf
(
this
,
headPos
,
Page
.
ROOT
,
store
.
createDataPage
());
root
.
write
();
rowCount
=
0
;
rowCount
=
0
;
}
}
...
@@ -168,8 +169,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -168,8 +169,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
}
}
public
Row
getRow
(
Session
session
,
int
key
)
throws
SQLException
{
public
Row
getRow
(
Session
session
,
int
key
)
throws
SQLException
{
int
todo
;
PageData
root
=
getPage
(
headPos
)
;
return
null
;
return
root
.
getRow
(
session
,
key
)
;
}
}
PageStore
getPageStore
()
{
PageStore
getPageStore
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论