Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0a1d5822
提交
0a1d5822
authored
6月 09, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recursive queries with many rows could throw an IndexOutOfBoundsException.
上级
38d97e2f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
37 行增加
和
19 行删除
+37
-19
Query.java
h2/src/main/org/h2/command/dml/Query.java
+12
-6
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+9
-3
TableView.java
h2/src/main/org/h2/table/TableView.java
+7
-4
TestRecursiveQueries.java
h2/src/test/org/h2/test/db/TestRecursiveQueries.java
+9
-6
没有找到文件。
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
0a1d5822
...
...
@@ -61,11 +61,12 @@ public abstract class Query extends Prepared {
*/
protected
boolean
randomAccessResult
;
private
boolean
noCache
;
private
int
lastLimit
;
private
long
lastEvaluated
;
private
LocalResult
lastResult
;
private
Value
[]
lastParameters
;
private
boolean
cacheableChecked
,
cacheable
;
private
boolean
cacheableChecked
;
Query
(
Session
session
)
{
super
(
session
);
...
...
@@ -218,13 +219,17 @@ public abstract class Query extends Prepared {
return
true
;
}
public
void
disableCache
()
{
this
.
noCache
=
true
;
}
private
boolean
sameResultAsLast
(
Session
s
,
Value
[]
params
,
Value
[]
lastParams
,
long
lastEval
)
{
if
(!
cacheableChecked
)
{
long
max
=
getMaxDataModificationId
();
cacheable
=
max
!
=
Long
.
MAX_VALUE
;
noCache
=
max
=
=
Long
.
MAX_VALUE
;
cacheableChecked
=
true
;
}
if
(
!
cacheabl
e
)
{
if
(
noCach
e
)
{
return
false
;
}
Database
db
=
s
.
getDatabase
();
...
...
@@ -269,7 +274,7 @@ public abstract class Query extends Prepared {
*/
LocalResult
query
(
int
limit
,
ResultTarget
target
)
{
fireBeforeSelectTriggers
();
if
(!
session
.
getDatabase
().
getOptimizeReuseResults
())
{
if
(
noCache
||
!
session
.
getDatabase
().
getOptimizeReuseResults
())
{
return
queryWithoutCache
(
limit
,
target
);
}
Value
[]
params
=
getParameterValues
();
...
...
@@ -287,10 +292,11 @@ public abstract class Query extends Prepared {
}
lastParameters
=
params
;
closeLastResult
();
lastResult
=
queryWithoutCache
(
limit
,
target
);
LocalResult
r
=
queryWithoutCache
(
limit
,
target
);
lastResult
=
r
;
this
.
lastEvaluated
=
now
;
lastLimit
=
limit
;
return
lastResult
;
return
r
;
}
private
void
closeLastResult
()
{
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
0a1d5822
...
...
@@ -157,7 +157,7 @@ public class ViewIndex extends BaseIndex {
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
if
(
recursive
)
{
ResultInterface
recResult
=
view
.
getRecursiveResult
(
session
);
ResultInterface
recResult
=
view
.
getRecursiveResult
();
if
(
recResult
!=
null
)
{
recResult
.
reset
();
return
new
ViewCursor
(
table
,
recResult
);
...
...
@@ -174,6 +174,8 @@ public class ViewIndex extends BaseIndex {
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_2
,
"recursive queries without UNION ALL"
);
}
Query
left
=
union
.
getLeft
();
// to ensure the last result isn't closed
left
.
disableCache
();
LocalResult
r
=
left
.
query
(
0
);
LocalResult
result
=
union
.
getEmptyResult
();
while
(
r
.
next
())
{
...
...
@@ -181,7 +183,9 @@ public class ViewIndex extends BaseIndex {
}
Query
right
=
union
.
getRight
();
r
.
reset
();
view
.
setRecursiveResult
(
r
,
session
);
view
.
setRecursiveResult
(
r
);
// to ensure the last result isn't closed
right
.
disableCache
();
while
(
true
)
{
r
=
right
.
query
(
0
);
if
(
r
.
getRowCount
()
==
0
)
{
...
...
@@ -191,8 +195,10 @@ public class ViewIndex extends BaseIndex {
result
.
addRow
(
r
.
currentRow
());
}
r
.
reset
();
view
.
setRecursiveResult
(
r
,
session
);
view
.
setRecursiveResult
(
r
);
}
view
.
setRecursiveResult
(
null
);
result
.
done
();
return
new
ViewCursor
(
table
,
result
);
}
ArrayList
<
Parameter
>
paramList
=
query
.
getParameters
();
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
0a1d5822
...
...
@@ -444,12 +444,15 @@ public class TableView extends Table {
return
viewQuery
.
isEverything
(
ExpressionVisitor
.
DETERMINISTIC_VISITOR
);
}
public
void
setRecursiveResult
(
LocalResult
value
,
Session
session
)
{
this
.
recursiveResult
=
value
.
createShallowCopy
(
session
);
public
void
setRecursiveResult
(
LocalResult
value
)
{
if
(
recursiveResult
!=
null
)
{
recursiveResult
.
close
();
}
this
.
recursiveResult
=
value
;
}
public
ResultInterface
getRecursiveResult
(
Session
session
)
{
return
recursiveResult
==
null
?
null
:
recursiveResult
.
createShallowCopy
(
session
)
;
public
ResultInterface
getRecursiveResult
()
{
return
recursiveResult
;
}
public
void
setTableExpression
(
boolean
tableExpression
)
{
...
...
h2/src/test/org/h2/test/db/TestRecursiveQueries.java
浏览文件 @
0a1d5822
...
...
@@ -38,12 +38,15 @@ public class TestRecursiveQueries extends TestBase {
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(parent varchar(255), child varchar(255))"
);
stat
.
execute
(
"insert into test values('/', 'a'), ('a', 'b1'), ('a', 'b2'), ('a', 'c'), ('c', 'd1'), ('c', 'd2')"
);
// stat.execute("with recursive rec_test(depth, parent, child) as (" +
// "select 0, parent, child from test where parent = '/' " +
// "union all " +
// "select depth+1, r.parent, r.child from test i join rec_test r " +
// "on (i.parent = r.child) where depth<9 " +
// ") select * from rec_test");
ResultSet
rs
=
stat
.
executeQuery
(
"with recursive rec_test(depth, parent, child) as ("
+
"select 0, parent, child from test where parent = '/' "
+
"union all "
+
"select depth+1, r.parent, r.child from test i join rec_test r "
+
"on (i.parent = r.child) where depth<9 "
+
") select count(*) from rec_test"
);
rs
.
next
();
assertEquals
(
29524
,
rs
.
getInt
(
1
));
stat
.
execute
(
"with recursive rec_test(depth, parent, child) as ( "
+
"select 0, parent, child from test where parent = '/' "
+
"union all "
+
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论