Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cf5f5318
提交
cf5f5318
authored
11 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support fast distinct operations
上级
e4fa538d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
79 行增加
和
2 行删除
+79
-2
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+1
-1
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+61
-1
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+17
-0
没有找到文件。
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
cf5f5318
...
...
@@ -399,7 +399,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
boolean
next
()
{
current
=
it
.
next
()
;
current
=
it
.
hasNext
()
?
it
.
next
()
:
null
;
if
(
current
!=
null
&&
current
.
getKey
().
getLong
()
>
last
.
getLong
())
{
current
=
null
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
cf5f5318
...
...
@@ -255,11 +255,61 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
@Override
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
return
find
(
session
,
first
,
false
,
last
);
}
private
Cursor
find
(
Session
session
,
SearchRow
first
,
boolean
bigger
,
SearchRow
last
)
{
ValueArray
min
=
getKey
(
first
);
if
(
min
!=
null
)
{
min
.
getList
()[
keyColumns
-
1
]
=
ValueLong
.
get
(
Long
.
MIN_VALUE
);
}
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
if
(
bigger
&&
min
!=
null
)
{
// search for the next: first skip 1, then 2, 4, 8, until
// we have a higher key; then skip 4, 2,...
// (binary search), until 1
int
offset
=
1
;
while
(
true
)
{
ValueArray
v
=
(
ValueArray
)
map
.
relativeKey
(
min
,
offset
);
if
(
v
!=
null
)
{
boolean
foundHigher
=
false
;
for
(
int
i
=
0
;
i
<
keyColumns
-
1
;
i
++)
{
int
idx
=
columnIds
[
i
];
Value
b
=
first
.
getValue
(
idx
);
if
(
b
==
null
)
{
break
;
}
Value
a
=
v
.
getList
()[
i
];
if
(
database
.
compare
(
a
,
b
)
>
0
)
{
foundHigher
=
true
;
break
;
}
}
if
(!
foundHigher
)
{
offset
+=
offset
;
min
=
v
;
continue
;
}
}
if
(
offset
>
1
)
{
offset
/=
2
;
continue
;
}
if
(
map
.
get
(
v
)
==
null
)
{
min
=
(
ValueArray
)
map
.
higherKey
(
min
);
if
(
min
==
null
)
{
break
;
}
continue
;
}
min
=
v
;
break
;
}
if
(
min
==
null
)
{
return
new
MVStoreCursor
(
session
,
Collections
.<
Value
>
emptyList
().
iterator
(),
null
);
}
}
return
new
MVStoreCursor
(
session
,
map
.
keyIterator
(
min
),
last
);
}
...
...
@@ -386,6 +436,16 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
return
0
;
}
@Override
public
boolean
canFindNext
()
{
return
true
;
}
@Override
public
Cursor
findNext
(
Session
session
,
SearchRow
higherThan
,
SearchRow
last
)
{
return
find
(
session
,
higherThan
,
true
,
last
);
}
@Override
public
void
checkRename
()
{
// ok
...
...
@@ -446,7 +506,7 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
@Override
public
boolean
next
()
{
current
=
it
.
next
()
;
current
=
it
.
hasNext
()
?
it
.
next
()
:
null
;
searchRow
=
null
;
if
(
current
!=
null
)
{
if
(
last
!=
null
&&
compareRows
(
getSearchRow
(),
last
)
>
0
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
cf5f5318
...
...
@@ -1326,6 +1326,23 @@ public class TransactionStore {
}
}
/**
* Get one of the previous or next keys. There might be no value
* available for the returned key.
*
* @param key the key (may not be null)
* @param offset how many keys to skip (-1 for previous, 1 for next)
* @return the key
*/
public
K
relativeKey
(
K
key
,
long
offset
)
{
K
k
=
offset
>
0
?
map
.
ceilingKey
(
key
)
:
map
.
floorKey
(
key
);
if
(
k
==
null
)
{
return
k
;
}
long
index
=
map
.
getKeyIndex
(
k
);
return
map
.
getKey
(
index
+
offset
);
}
/**
* Get the largest key that is smaller than the given key, or null if no
* such key exists.
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论