Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ebd36602
提交
ebd36602
authored
8月 20, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
03d85cbe
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
57 行增加
和
20 行删除
+57
-20
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+34
-0
TableData.java
h2/src/main/org/h2/table/TableData.java
+18
-9
TestMVCC.java
h2/src/test/org/h2/test/mvcc/TestMVCC.java
+5
-11
没有找到文件。
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
ebd36602
...
...
@@ -6,6 +6,7 @@ package org.h2.index;
import
java.sql.SQLException
;
import
org.h2.constant.SysProperties
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
...
...
@@ -15,6 +16,7 @@ import org.h2.result.SearchRow;
import
org.h2.store.Storage
;
import
org.h2.table.Column
;
import
org.h2.table.TableData
;
import
org.h2.util.IntIntHashMap
;
import
org.h2.util.ObjectArray
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
...
...
@@ -29,10 +31,15 @@ public class ScanIndex extends BaseIndex {
private
Storage
storage
;
private
TableData
tableData
;
private
boolean
containsLargeObject
;
private
int
rowCountDiff
;
private
IntIntHashMap
sessionRowCount
;
public
ScanIndex
(
TableData
table
,
int
id
,
Column
[]
columns
,
IndexType
indexType
)
throws
SQLException
{
super
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
if
(
SysProperties
.
MVCC
)
{
sessionRowCount
=
new
IntIntHashMap
();
}
tableData
=
table
;
Database
db
=
table
.
getDatabase
();
if
(!
db
.
isPersistent
()
||
id
<
0
)
{
...
...
@@ -114,8 +121,21 @@ public class ScanIndex extends BaseIndex {
rows
.
set
(
key
,
row
);
}
}
incrementRowCount
(
session
,
1
);
rowCount
++;
}
private
void
incrementRowCount
(
Session
session
,
int
count
)
{
if
(
SysProperties
.
MVCC
)
{
int
id
=
session
.
getId
();
int
current
=
sessionRowCount
.
get
(
id
);
if
(
current
==
-
1
)
{
current
=
0
;
}
sessionRowCount
.
put
(
id
,
current
+
count
);
rowCountDiff
+=
count
;
}
}
public
void
remove
(
Session
session
,
Row
row
)
throws
SQLException
{
if
(
storage
!=
null
)
{
...
...
@@ -135,6 +155,7 @@ public class ScanIndex extends BaseIndex {
rows
.
set
(
key
,
free
);
firstFree
=
key
;
}
incrementRowCount
(
session
,
-
1
);
rowCount
--;
}
...
...
@@ -149,6 +170,19 @@ public class ScanIndex extends BaseIndex {
}
return
cost
;
}
public
long
getRowCount
(
Session
session
)
{
if
(
SysProperties
.
MVCC
)
{
long
count
=
sessionRowCount
.
get
(
session
.
getId
());
if
(
count
==
-
1
)
{
count
=
0
;
}
count
+=
super
.
getRowCount
(
session
);
count
-=
rowCountDiff
;
return
count
;
}
return
super
.
getRowCount
(
session
);
}
Row
getNextRow
(
Session
session
,
Row
row
)
throws
SQLException
{
if
(
storage
==
null
)
{
...
...
h2/src/main/org/h2/table/TableData.java
浏览文件 @
ebd36602
...
...
@@ -83,9 +83,11 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
add
(
session
,
row
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
+
1
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
+
1
)+
" got "
+
rc
);
if
(!
SysProperties
.
MVCC
)
{
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
+
1
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
+
1
)+
" got "
+
rc
);
}
}
}
}
...
...
@@ -96,9 +98,11 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
remove
(
session
,
row
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
)+
" got "
+
rc
);
if
(!
SysProperties
.
MVCC
)
{
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
)+
" got "
+
rc
);
}
}
}
}
...
...
@@ -252,6 +256,9 @@ public class TableData extends Table implements RecordReader {
}
public
long
getRowCount
(
Session
session
)
{
if
(
SysProperties
.
MVCC
)
{
return
getScanIndex
(
session
).
getRowCount
(
session
);
}
return
rowCount
;
}
...
...
@@ -261,9 +268,11 @@ public class TableData extends Table implements RecordReader {
Index
index
=
(
Index
)
indexes
.
get
(
i
);
index
.
remove
(
session
,
row
);
if
(
SysProperties
.
CHECK
)
{
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
-
1
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
-
1
)+
" got "
+
rc
);
if
(!
SysProperties
.
MVCC
)
{
long
rc
=
index
.
getRowCount
(
session
);
if
(
rc
!=
rowCount
-
1
)
{
throw
Message
.
getInternalError
(
"rowCount expected "
+(
rowCount
-
1
)+
" got "
+
rc
);
}
}
}
}
...
...
h2/src/test/org/h2/test/mvcc/TestMVCC.java
浏览文件 @
ebd36602
...
...
@@ -33,17 +33,11 @@ public class TestMVCC {
c1
.
setAutoCommit
(
false
);
c2
.
setAutoCommit
(
false
);
s1
.
execute
(
"CREATE TABLE A(ID INT PRIMARY KEY, SK INT)"
);
s1
.
execute
(
"INSERT INTO A VALUES(1, 2)"
);
test
(
s1
,
"SELECT 1 FROM (SELECT SK FROM PUBLIC.A ORDER BY SK) C WHERE NOT EXISTS(SELECT 1 FROM PUBLIC.A P WHERE C.SK=P.ID)"
,
"1"
);
c1
.
commit
();
test
(
s1
,
"SELECT 1 FROM (SELECT SK FROM PUBLIC.A ORDER BY SK) C WHERE NOT EXISTS(SELECT 1 FROM PUBLIC.A P WHERE C.SK=P.ID)"
,
"1"
);
try
{
s1
.
execute
(
"ALTER TABLE A ADD CONSTRAINT AC FOREIGN KEY(SK) REFERENCES A(ID)"
);
throw
new
Exception
(
"unexpected success"
);
}
catch
(
SQLException
e
)
{
// expected
}
s1
.
execute
(
"CREATE TABLE TEST(ID INT IDENTITY, NAME VARCHAR)"
);
s1
.
execute
(
"INSERT INTO TEST(NAME) VALUES('Ruebezahl')"
);
test
(
s2
,
"SELECT COUNT(*) FROM TEST"
,
"0"
);
test
(
s1
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
s1
.
execute
(
"DROP TABLE TEST"
);
c1
.
commit
();
s1
.
execute
(
"CREATE TABLE TEST(ID INT IDENTITY, NAME VARCHAR)"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论