Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
4ccf2510
提交
4ccf2510
authored
11月 01, 2017
作者:
andrei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
issue_435
上级
5b6bf351
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
42 行增加
和
13 行删除
+42
-13
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+7
-12
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+4
-1
TestMVTableEngine.java
h2/src/test/org/h2/test/store/TestMVTableEngine.java
+31
-0
没有找到文件。
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
4ccf2510
...
...
@@ -197,7 +197,7 @@ public class MVPrimaryIndex extends BaseIndex {
}
}
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
return
new
MVStoreCursor
(
session
,
map
.
entryIterator
(
min
),
max
);
return
new
MVStoreCursor
(
session
,
map
.
entryIterator
(
min
,
max
)
);
}
@Override
...
...
@@ -270,13 +270,13 @@ public class MVPrimaryIndex extends BaseIndex {
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
ValueLong
v
=
(
ValueLong
)
(
first
?
map
.
firstKey
()
:
map
.
lastKey
());
if
(
v
==
null
)
{
return
new
MVStoreCursor
(
session
,
Collections
.<
Entry
<
Value
,
Value
>>
emptyList
().
iterator
(),
null
);
return
new
MVStoreCursor
(
session
,
Collections
.<
Entry
<
Value
,
Value
>>
emptyList
().
iterator
()
);
}
Value
value
=
map
.
get
(
v
);
Entry
<
Value
,
Value
>
e
=
new
DataUtils
.
MapEntry
<
Value
,
Value
>(
v
,
value
);
List
<
Entry
<
Value
,
Value
>>
list
=
Arrays
.
as
List
(
e
);
MVStoreCursor
c
=
new
MVStoreCursor
(
session
,
list
.
iterator
()
,
v
);
List
<
Entry
<
Value
,
Value
>>
list
=
Collections
.
singleton
List
(
e
);
MVStoreCursor
c
=
new
MVStoreCursor
(
session
,
list
.
iterator
());
c
.
next
();
return
c
;
}
...
...
@@ -356,7 +356,7 @@ public class MVPrimaryIndex extends BaseIndex {
*/
Cursor
find
(
Session
session
,
ValueLong
first
,
ValueLong
last
)
{
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
return
new
MVStoreCursor
(
session
,
map
.
entryIterator
(
first
),
last
);
return
new
MVStoreCursor
(
session
,
map
.
entryIterator
(
first
,
last
)
);
}
@Override
...
...
@@ -385,14 +385,12 @@ public class MVPrimaryIndex extends BaseIndex {
private
final
Session
session
;
private
final
Iterator
<
Entry
<
Value
,
Value
>>
it
;
private
final
ValueLong
last
;
private
Entry
<
Value
,
Value
>
current
;
private
Row
row
;
public
MVStoreCursor
(
Session
session
,
Iterator
<
Entry
<
Value
,
Value
>>
it
,
ValueLong
last
)
{
public
MVStoreCursor
(
Session
session
,
Iterator
<
Entry
<
Value
,
Value
>>
it
)
{
this
.
session
=
session
;
this
.
it
=
it
;
this
.
last
=
last
;
}
@Override
...
...
@@ -415,9 +413,6 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
boolean
next
()
{
current
=
it
.
hasNext
()
?
it
.
next
()
:
null
;
if
(
current
!=
null
&&
current
.
getKey
().
getLong
()
>
last
.
getLong
())
{
current
=
null
;
}
row
=
null
;
return
current
!=
null
;
}
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
4ccf2510
...
...
@@ -1470,7 +1470,7 @@ public class TransactionStore {
* @param from the first key to return
* @return the iterator
*/
public
Iterator
<
Entry
<
K
,
V
>>
entryIterator
(
final
K
from
)
{
public
Iterator
<
Entry
<
K
,
V
>>
entryIterator
(
final
K
from
,
final
K
to
)
{
return
new
Iterator
<
Entry
<
K
,
V
>>()
{
private
Entry
<
K
,
V
>
current
;
private
K
currentKey
=
from
;
...
...
@@ -1507,6 +1507,9 @@ public class TransactionStore {
}
}
final
K
key
=
k
;
if
(
to
!=
null
&&
map
.
getKeyType
().
compare
(
k
,
to
)
>
0
)
{
break
;
}
VersionedValue
data
=
cursor
.
getValue
();
data
=
getValue
(
key
,
readLogId
,
data
);
if
(
data
!=
null
&&
data
.
value
!=
null
)
{
...
...
h2/src/test/org/h2/test/store/TestMVTableEngine.java
浏览文件 @
4ccf2510
...
...
@@ -18,6 +18,7 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Savepoint
;
import
java.sql.Statement
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
...
...
@@ -85,6 +86,7 @@ public class TestMVTableEngine extends TestBase {
testDataTypes
();
testLocking
();
testSimple
();
testReverseDeletePerformance
();
}
private
void
testLobCopy
()
throws
Exception
{
...
...
@@ -1478,4 +1480,33 @@ public class TestMVTableEngine extends TestBase {
conn
.
close
();
}
private
void
testReverseDeletePerformance
()
throws
Exception
{
long
direct
=
0
;
long
reverse
=
0
;
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
reverse
+=
testReverseDeletePerformance
(
true
);
direct
+=
testReverseDeletePerformance
(
false
);
}
System
.
out
.
println
(
"direct: "
+
direct
+
", reverse: "
+
reverse
);
assertTrue
(
"direct: "
+
direct
+
", reverse: "
+
reverse
,
2
*
Math
.
abs
(
reverse
-
direct
)
<
reverse
+
direct
);
}
private
long
testReverseDeletePerformance
(
boolean
reverse
)
throws
Exception
{
deleteDb
(
getTestName
());
String
dbName
=
getTestName
()
+
";MV_STORE=TRUE"
;
try
(
Connection
conn
=
getConnection
(
dbName
))
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE test(id INT PRIMARY KEY, name VARCHAR) AS SELECT x, x || space(1024) || x FROM system_range(1, 1000)"
);
conn
.
setAutoCommit
(
false
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"DELETE FROM test WHERE id = ?"
);
long
start
=
System
.
nanoTime
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
prep
.
setInt
(
1
,
reverse
?
1000
-
i
:
i
);
prep
.
execute
();
}
long
end
=
System
.
nanoTime
();
conn
.
commit
();
return
TimeUnit
.
NANOSECONDS
.
toMillis
(
end
-
start
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论