Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b4f18991
提交
b4f18991
authored
6月 08, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recursive queries with many rows could throw an IndexOutOfBoundsException.
上级
56f4e91a
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
43 行增加
和
13 行删除
+43
-13
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+7
-7
TableView.java
h2/src/main/org/h2/table/TableView.java
+6
-5
TestRecursiveQueries.java
h2/src/test/org/h2/test/db/TestRecursiveQueries.java
+28
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
b4f18991
...
...
@@ -18,7 +18,8 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The auto-server mode can't be combined with an in-memory database.
<ul><li>
Recursive queries with many rows could throw an IndexOutOfBoundsException.
</li><li>
The auto-server mode can't be combined with an in-memory database.
This invalid combination wasn't detected so far.
Now trying to open a database in this way fails.
</li><li>
Improved performance for reading and writing date and time values.
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
b4f18991
...
...
@@ -157,10 +157,10 @@ public class ViewIndex extends BaseIndex {
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
if
(
recursive
)
{
if
(
view
.
getRecursiveResult
()
!=
null
)
{
ResultInterface
r
=
view
.
getRecursiveResult
();
r
.
reset
();
return
new
ViewCursor
(
table
,
r
);
ResultInterface
recResult
=
view
.
getRecursiveResult
(
session
);
if
(
recResult
!=
null
)
{
r
ecResult
.
reset
();
return
new
ViewCursor
(
table
,
r
ecResult
);
}
if
(
query
==
null
)
{
query
=
(
Query
)
createSession
.
prepare
(
querySQL
,
true
);
...
...
@@ -174,14 +174,14 @@ public class ViewIndex extends BaseIndex {
throw
DbException
.
get
(
ErrorCode
.
SYNTAX_ERROR_2
,
"recursive queries without UNION ALL"
);
}
Query
left
=
union
.
getLeft
();
ResultInterface
r
=
left
.
query
(
0
);
LocalResult
r
=
left
.
query
(
0
);
LocalResult
result
=
union
.
getEmptyResult
();
while
(
r
.
next
())
{
result
.
addRow
(
r
.
currentRow
());
}
Query
right
=
union
.
getRight
();
r
.
reset
();
view
.
setRecursiveResult
(
r
);
view
.
setRecursiveResult
(
r
,
session
);
while
(
true
)
{
r
=
right
.
query
(
0
);
if
(
r
.
getRowCount
()
==
0
)
{
...
...
@@ -191,7 +191,7 @@ public class ViewIndex extends BaseIndex {
result
.
addRow
(
r
.
currentRow
());
}
r
.
reset
();
view
.
setRecursiveResult
(
r
);
view
.
setRecursiveResult
(
r
,
session
);
}
return
new
ViewCursor
(
table
,
result
);
}
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
b4f18991
...
...
@@ -20,6 +20,7 @@ import org.h2.index.Index;
import
org.h2.index.IndexType
;
import
org.h2.index.ViewIndex
;
import
org.h2.message.DbException
;
import
org.h2.result.LocalResult
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.schema.Schema
;
...
...
@@ -50,7 +51,7 @@ public class TableView extends Table {
private
long
maxDataModificationId
;
private
User
owner
;
private
Query
topQuery
;
private
ResultInterface
recursiveResult
;
private
LocalResult
recursiveResult
;
private
boolean
tableExpression
;
public
TableView
(
Schema
schema
,
int
id
,
String
name
,
String
querySQL
,
ArrayList
<
Parameter
>
params
,
String
[]
columnNames
,
...
...
@@ -443,12 +444,12 @@ public class TableView extends Table {
return
viewQuery
.
isEverything
(
ExpressionVisitor
.
DETERMINISTIC_VISITOR
);
}
public
void
setRecursiveResult
(
ResultInterface
recursiveResult
)
{
this
.
recursiveResult
=
recursiveResult
;
public
void
setRecursiveResult
(
LocalResult
value
,
Session
session
)
{
this
.
recursiveResult
=
value
.
createShallowCopy
(
session
)
;
}
public
ResultInterface
getRecursiveResult
()
{
return
recursiveResult
;
public
ResultInterface
getRecursiveResult
(
Session
session
)
{
return
recursiveResult
==
null
?
null
:
recursiveResult
.
createShallowCopy
(
session
)
;
}
public
void
setTableExpression
(
boolean
tableExpression
)
{
...
...
h2/src/test/org/h2/test/db/TestRecursiveQueries.java
浏览文件 @
b4f18991
...
...
@@ -27,6 +27,34 @@ public class TestRecursiveQueries extends TestBase {
}
public
void
test
()
throws
Exception
{
testWrongLinkLargeResult
();
testSimple
();
}
private
void
testWrongLinkLargeResult
()
throws
Exception
{
deleteDb
(
"recursiveQueries"
);
Connection
conn
=
getConnection
(
"recursiveQueries"
);
Statement
stat
;
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");
stat
.
execute
(
"with recursive rec_test(depth, parent, child) as ( "
+
"select 0, parent, child from test where parent = '/' "
+
"union all "
+
"select depth+1, i.parent, i.child from test i join rec_test r "
+
"on (r.child = i.parent) where depth<10 "
+
") select * from rec_test"
);
conn
.
close
();
deleteDb
(
"recursiveQueries"
);
}
private
void
testSimple
()
throws
Exception
{
deleteDb
(
"recursiveQueries"
);
Connection
conn
=
getConnection
(
"recursiveQueries"
);
Statement
stat
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论