Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6762b765
提交
6762b765
authored
11月 20, 2015
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Batched join for SELECT sub-queries.
上级
508ed18e
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
265 行增加
和
64 行删除
+265
-64
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-1
IndexLookupBatch.java
h2/src/main/org/h2/index/IndexLookupBatch.java
+3
-1
ViewCursor.java
h2/src/main/org/h2/index/ViewCursor.java
+1
-1
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+4
-0
JoinBatch.java
h2/src/main/org/h2/table/JoinBatch.java
+137
-48
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+11
-12
LazyFuture.java
h2/src/main/org/h2/util/LazyFuture.java
+106
-0
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+2
-1
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
6762b765
...
@@ -948,7 +948,7 @@ public class Select extends Query {
...
@@ -948,7 +948,7 @@ public class Select extends Query {
expressionArray
=
new
Expression
[
expressions
.
size
()];
expressionArray
=
new
Expression
[
expressions
.
size
()];
expressions
.
toArray
(
expressionArray
);
expressions
.
toArray
(
expressionArray
);
if
(!
session
.
isParsingView
())
{
if
(!
session
.
isParsingView
())
{
topTableFilter
.
prepareBatch
(
0
);
topTableFilter
.
prepare
Join
Batch
(
0
);
}
}
isPrepared
=
true
;
isPrepared
=
true
;
}
}
...
...
h2/src/main/org/h2/index/IndexLookupBatch.java
浏览文件 @
6762b765
...
@@ -27,9 +27,11 @@ public interface IndexLookupBatch {
...
@@ -27,9 +27,11 @@ public interface IndexLookupBatch {
*
*
* @param first the first row, or null for no limit
* @param first the first row, or null for no limit
* @param last the last row, or null for no limit
* @param last the last row, or null for no limit
* @return {@code false} if this search row pair is known to produce no results
* and thus the given row pair was not added
* @see Index#find(TableFilter, SearchRow, SearchRow)
* @see Index#find(TableFilter, SearchRow, SearchRow)
*/
*/
void
addSearchRows
(
SearchRow
first
,
SearchRow
last
);
boolean
addSearchRows
(
SearchRow
first
,
SearchRow
last
);
/**
/**
* Check if this batch is full.
* Check if this batch is full.
...
...
h2/src/main/org/h2/index/ViewCursor.java
浏览文件 @
6762b765
...
@@ -24,7 +24,7 @@ public class ViewCursor implements Cursor {
...
@@ -24,7 +24,7 @@ public class ViewCursor implements Cursor {
private
final
SearchRow
first
,
last
;
private
final
SearchRow
first
,
last
;
private
Row
current
;
private
Row
current
;
ViewCursor
(
ViewIndex
index
,
LocalResult
result
,
SearchRow
first
,
public
ViewCursor
(
ViewIndex
index
,
LocalResult
result
,
SearchRow
first
,
SearchRow
last
)
{
SearchRow
last
)
{
this
.
table
=
index
.
getTable
();
this
.
table
=
index
.
getTable
();
this
.
index
=
index
;
this
.
index
=
index
;
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
6762b765
...
@@ -347,6 +347,10 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -347,6 +347,10 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
param
.
setValue
(
v
);
param
.
setValue
(
v
);
}
}
public
Query
getQuery
()
{
return
query
;
}
private
Query
getQuery
(
Session
session
,
int
[]
masks
,
private
Query
getQuery
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
Query
q
=
prepareSubQuery
(
querySQL
,
session
,
masks
,
filters
,
filter
,
sortOrder
,
true
);
Query
q
=
prepareSubQuery
(
querySQL
,
session
,
masks
,
filters
,
filter
,
sortOrder
,
true
);
...
...
h2/src/main/org/h2/table/JoinBatch.java
浏览文件 @
6762b765
差异被折叠。
点击展开。
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
6762b765
...
@@ -363,18 +363,21 @@ public class TableFilter implements ColumnResolver {
...
@@ -363,18 +363,21 @@ public class TableFilter implements ColumnResolver {
* @param id join filter id (index of this table filter in join list)
* @param id join filter id (index of this table filter in join list)
* @return join batch if query runs over index which supports batched lookups, {@code null} otherwise
* @return join batch if query runs over index which supports batched lookups, {@code null} otherwise
*/
*/
public
JoinBatch
prepareBatch
(
int
id
)
{
public
JoinBatch
prepare
Join
Batch
(
int
id
)
{
joinBatch
=
null
;
joinBatch
=
null
;
joinFilterId
=
-
1
;
joinFilterId
=
-
1
;
JoinBatch
jb
=
null
;
JoinBatch
jb
=
null
;
if
(
join
!=
null
)
{
if
(
join
!=
null
)
{
jb
=
join
.
prepareBatch
(
id
+
1
);
jb
=
join
.
prepare
Join
Batch
(
id
+
1
);
}
}
IndexLookupBatch
lookupBatch
=
null
;
IndexLookupBatch
lookupBatch
=
null
;
// the globally top table filter does not need batching, if isAlwaysTopTableFilter is false
// For globally top table filter we don't need to create lookup batch, because
// then we either not a top table filter or top table filter in a sub-query which is not
// currently it will not be used (this will be shown in ViewIndex.getPlanSQL()). Probably
// top in outer query, thus we need to enable batching here to allow outer query run batched
// later on it will make sense to create it to better support X IN (...) conditions,
// join against this sub-query
// but this needs to be implemented separately. If isAlwaysTopTableFilter is false
// then we either not a top table filter or top table filter in a sub-query, which
// in turn is not top in outer query, thus we need to enable batching here to allow
// outer query run batched join against this sub-query.
if
(
jb
==
null
&&
select
!=
null
&&
!
isAlwaysTopTableFilter
(
id
))
{
if
(
jb
==
null
&&
select
!=
null
&&
!
isAlwaysTopTableFilter
(
id
))
{
lookupBatch
=
index
.
createLookupBatch
(
this
);
lookupBatch
=
index
.
createLookupBatch
(
this
);
if
(
lookupBatch
!=
null
)
{
if
(
lookupBatch
!=
null
)
{
...
@@ -387,13 +390,9 @@ public class TableFilter implements ColumnResolver {
...
@@ -387,13 +390,9 @@ public class TableFilter implements ColumnResolver {
}
}
joinBatch
=
jb
;
joinBatch
=
jb
;
joinFilterId
=
id
;
joinFilterId
=
id
;
// for globally top table filter we don't need to create lookup batch
// currently it will not be used, probably later on it will make sense
// to create it to better support X IN (...) conditions, but this needs
// to be implemented separately
if
(
lookupBatch
==
null
&&
!
isAlwaysTopTableFilter
(
id
))
{
if
(
lookupBatch
==
null
&&
!
isAlwaysTopTableFilter
(
id
))
{
// index.createLookupBatch will be called
only once because jb can be created only if
// index.createLookupBatch will be called
at most once because jb can be
//
lookupBatch is not null from the first call above
//
created only if lookupBatch is already not null from the call above.
lookupBatch
=
index
.
createLookupBatch
(
this
);
lookupBatch
=
index
.
createLookupBatch
(
this
);
}
}
jb
.
register
(
this
,
lookupBatch
);
jb
.
register
(
this
,
lookupBatch
);
...
...
h2/src/main/org/h2/util/LazyFuture.java
0 → 100644
浏览文件 @
6762b765
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
util
;
import
java.util.concurrent.CancellationException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.message.DbException
;
/**
* Single threaded lazy future.
*
* @param <T>
* @author Sergi Vladykin
*/
public
abstract
class
LazyFuture
<
T
>
implements
Future
<
T
>
{
private
static
final
int
S_READY
=
0
;
private
static
final
int
S_DONE
=
1
;
private
static
final
int
S_ERROR
=
2
;
private
static
final
int
S_CANCELED
=
3
;
private
int
state
=
S_READY
;
private
T
result
;
private
Exception
error
;
/**
* Reset this future to the initial state.
*
* @return {@code false} if it was already in initial state
*/
public
boolean
reset
()
{
if
(
state
==
S_READY
)
{
return
false
;
}
state
=
S_READY
;
result
=
null
;
error
=
null
;
return
true
;
}
/**
* Run computation and produce the result.
*
* @return the result of computation
*/
protected
abstract
T
run
()
throws
Exception
;
@Override
public
boolean
cancel
(
boolean
mayInterruptIfRunning
)
{
if
(
state
!=
S_READY
)
{
return
false
;
}
state
=
S_CANCELED
;
return
true
;
}
@Override
public
T
get
()
throws
InterruptedException
,
ExecutionException
{
switch
(
state
)
{
case
S_READY:
try
{
result
=
run
();
state
=
S_DONE
;
}
catch
(
Exception
e
)
{
error
=
e
;
if
(
e
instanceof
InterruptedException
)
{
throw
(
InterruptedException
)
e
;
}
throw
new
ExecutionException
(
e
);
}
finally
{
if
(
state
!=
S_DONE
)
{
state
=
S_ERROR
;
}
}
return
result
;
case
S_DONE:
return
result
;
case
S_ERROR:
throw
new
ExecutionException
(
error
);
case
S_CANCELED:
throw
new
CancellationException
();
default
:
throw
DbException
.
throwInternalError
();
}
}
@Override
public
T
get
(
long
timeout
,
TimeUnit
unit
)
throws
InterruptedException
,
ExecutionException
{
return
get
();
}
@Override
public
boolean
isCancelled
()
{
return
state
==
S_CANCELED
;
}
@Override
public
boolean
isDone
()
{
return
state
==
S_DONE
;
}
}
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
6762b765
...
@@ -1160,10 +1160,11 @@ public class TestTableEngines extends TestBase {
...
@@ -1160,10 +1160,11 @@ public class TestTableEngines extends TestBase {
}
}
@Override
@Override
public
void
addSearchRows
(
SearchRow
first
,
SearchRow
last
)
{
public
boolean
addSearchRows
(
SearchRow
first
,
SearchRow
last
)
{
assert
!
isBatchFull
();
assert
!
isBatchFull
();
searchRows
.
add
(
first
);
searchRows
.
add
(
first
);
searchRows
.
add
(
last
);
searchRows
.
add
(
last
);
return
true
;
}
}
@Override
@Override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论