Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
54e6e45c
提交
54e6e45c
authored
1月 07, 2018
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Testing localized fix for lazy eval and recursive
上级
978ff88f
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
33 行删除
+45
-33
Select.java
h2/src/main/org/h2/command/dml/Select.java
+6
-6
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+30
-20
TestGeneralCommonTableQueries.java
...rc/test/org/h2/test/db/TestGeneralCommonTableQueries.java
+9
-7
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
54e6e45c
...
@@ -666,12 +666,12 @@ public class Select extends Query {
...
@@ -666,12 +666,12 @@ public class Select extends Query {
private
boolean
hasRecursiveTopTableView
()
{
private
boolean
hasRecursiveTopTableView
()
{
//check the top table filter only to see if we have a recursive table query
//check the top table filter only to see if we have a recursive table query
if
(
this
.
topTableFilter
.
getTable
().
isTableExpression
()){
//
if(this.topTableFilter.getTable().isTableExpression()){
TableView
v
=
(
TableView
)
this
.
topTableFilter
.
getTable
();
//
TableView v = (TableView)this.topTableFilter.getTable();
if
(
v
.
isRecursive
()){
//
if(v.isRecursive()){
return
true
;
//
return true;
}
//
}
}
//
}
return
false
;
return
false
;
}
}
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
54e6e45c
...
@@ -6,9 +6,9 @@
...
@@ -6,9 +6,9 @@
package
org
.
h2
.
index
;
package
org
.
h2
.
index
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Parser
;
import
org.h2.command.Parser
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
...
@@ -182,16 +182,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -182,16 +182,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
private
Cursor
findRecursive
(
SearchRow
first
,
SearchRow
last
)
{
private
Cursor
findRecursive
(
SearchRow
first
,
SearchRow
last
)
{
assert
recursive
;
assert
recursive
;
ResultInterface
recResult
=
view
.
getRecursiveResult
();
ResultInterface
recursiveResult
=
view
.
getRecursiveResult
();
if
(
recResult
!=
null
)
{
if
(
recursiveResult
!=
null
)
{
recResult
.
reset
();
recursiveResult
.
reset
();
return
new
ViewCursor
(
this
,
recResult
,
first
,
last
);
//System.out.println("findRecursive.return ViewCursor=recResult="+recursiveResult+",first="+first+",last="+last);
return
new
ViewCursor
(
this
,
recursiveResult
,
first
,
last
);
}
}
if
(
query
==
null
)
{
if
(
query
==
null
)
{
Parser
parser
=
new
Parser
(
createSession
);
Parser
parser
=
new
Parser
(
createSession
);
parser
.
setRightsChecked
(
true
);
parser
.
setRightsChecked
(
true
);
parser
.
setSuppliedParameterList
(
originalParameters
);
parser
.
setSuppliedParameterList
(
originalParameters
);
query
=
(
Query
)
parser
.
prepare
(
querySQL
);
query
=
(
Query
)
parser
.
prepare
(
querySQL
);
//System.out.println("findRecursive.querySQL="+querySQL);
query
.
setNeverLazy
(
true
);
query
.
setNeverLazy
(
true
);
}
}
if
(!
query
.
isUnion
())
{
if
(!
query
.
isUnion
())
{
...
@@ -200,35 +202,43 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -200,35 +202,43 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
}
}
SelectUnion
union
=
(
SelectUnion
)
query
;
SelectUnion
union
=
(
SelectUnion
)
query
;
Query
left
=
union
.
getLeft
();
Query
left
=
union
.
getLeft
();
left
.
setNeverLazy
(
true
);
// to ensure the last result is not closed
// to ensure the last result is not closed
left
.
disableCache
();
left
.
disableCache
();
ResultInterface
r
=
left
.
query
(
0
);
ResultInterface
r
esultInterface
=
left
.
query
(
0
);
LocalResult
r
esult
=
union
.
getEmptyResult
();
LocalResult
localR
esult
=
union
.
getEmptyResult
();
// ensure it is not written to disk,
// ensure it is not written to disk,
// because it is not closed normally
// because it is not closed normally
result
.
setMaxMemoryRows
(
Integer
.
MAX_VALUE
);
localResult
.
setMaxMemoryRows
(
Integer
.
MAX_VALUE
);
while
(
r
.
next
())
{
while
(
resultInterface
.
next
())
{
result
.
addRow
(
r
.
currentRow
());
Value
[]
cr
=
resultInterface
.
currentRow
();
//System.out.println("findRecursive.while left resultinterface next row="+Arrays.toString(cr));
localResult
.
addRow
(
cr
);
}
}
Query
right
=
union
.
getRight
();
Query
right
=
union
.
getRight
();
r
.
reset
();
right
.
setNeverLazy
(
true
);
view
.
setRecursiveResult
(
r
);
//System.out.println("right="+right.getSQL());
resultInterface
.
reset
();
view
.
setRecursiveResult
(
resultInterface
);
// to ensure the last result is not closed
// to ensure the last result is not closed
right
.
disableCache
();
right
.
disableCache
();
while
(
true
)
{
while
(
true
)
{
r
=
right
.
query
(
0
);
resultInterface
=
right
.
query
(
0
);
if
(!
r
.
hasNext
())
{
if
(!
resultInterface
.
hasNext
())
{
//System.out.println("right query has no results");
break
;
break
;
}
}
while
(
r
.
next
())
{
while
(
resultInterface
.
next
())
{
result
.
addRow
(
r
.
currentRow
());
Value
[]
cr
=
resultInterface
.
currentRow
();
//System.out.println("findRecursive.while right resultinterface next row="+Arrays.toString(cr));
localResult
.
addRow
(
cr
);
}
}
r
.
reset
();
r
esultInterface
.
reset
();
view
.
setRecursiveResult
(
r
);
view
.
setRecursiveResult
(
r
esultInterface
);
}
}
view
.
setRecursiveResult
(
null
);
view
.
setRecursiveResult
(
null
);
r
esult
.
done
();
localR
esult
.
done
();
return
new
ViewCursor
(
this
,
r
esult
,
first
,
last
);
return
new
ViewCursor
(
this
,
localR
esult
,
first
,
last
);
}
}
/**
/**
...
...
h2/src/test/org/h2/test/db/TestGeneralCommonTableQueries.java
浏览文件 @
54e6e45c
...
@@ -540,9 +540,9 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
...
@@ -540,9 +540,9 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
private
void
testSimple3RowRecursiveQueryWithLazyEval
()
throws
Exception
{
private
void
testSimple3RowRecursiveQueryWithLazyEval
()
throws
Exception
{
String
[]
expectedRowData
=
new
String
[]{
"|
1"
,
"|2"
,
"|3"
};
String
[]
expectedRowData
=
new
String
[]{
"|
6"
,
};
String
[]
expectedColumnTypes
=
new
String
[]{
"
INTEGER
"
};
String
[]
expectedColumnTypes
=
new
String
[]{
"
BIGINT
"
};
String
[]
expectedColumnNames
=
new
String
[]{
"
N
"
};
String
[]
expectedColumnNames
=
new
String
[]{
"
SUM(N)
"
};
// back up the config - to restore it after this test
// back up the config - to restore it after this test
TestAll
backupConfig
=
config
;
TestAll
backupConfig
=
config
;
...
@@ -558,10 +558,12 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
...
@@ -558,10 +558,12 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
config
.
multiThreaded
=
true
;
config
.
multiThreaded
=
true
;
String
SETUP_SQL
=
"--no config set"
;
String
SETUP_SQL
=
"--no config set"
;
String
WITH_QUERY
=
"with recursive r(n) as (\n"
+
String
WITH_QUERY
=
"select sum(n) from (\n"
"(select 1) union all (select n+1 from r where n < 3)\n"
+
+
" with recursive r(n) as (\n"
")\n"
+
+
" (select 1) union all (select n+1 from r where n < 3) \n"
"select n from r"
;
+
" )\n"
+
" select n from r \n"
+
")\n"
;
int
maxRetries
=
10
;
int
maxRetries
=
10
;
int
expectedNumberOfRows
=
expectedRowData
.
length
;
int
expectedNumberOfRows
=
expectedRowData
.
length
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论