Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cc28d22a
提交
cc28d22a
authored
6月 08, 2016
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#299 Nested derrived tables did not always work as expected
上级
8b124771
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
7 行删除
+27
-7
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+13
-7
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+14
-0
没有找到文件。
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
cc28d22a
...
@@ -8,6 +8,7 @@ package org.h2.index;
...
@@ -8,6 +8,7 @@ package org.h2.index;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
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
;
...
@@ -314,7 +315,10 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -314,7 +315,10 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
return
q
;
return
q
;
}
}
int
firstIndexParam
=
view
.
getParameterOffset
(
originalParameters
);
int
firstIndexParam
=
view
.
getParameterOffset
(
originalParameters
);
IntArray
paramIndex
=
new
IntArray
();
// the column index of each parameter
// (for example: paramColumnIndex {0, 0} mean
// param[0] is column 0, and param[1] is also column 0)
IntArray
paramColumnIndex
=
new
IntArray
();
int
indexColumnCount
=
0
;
int
indexColumnCount
=
0
;
for
(
int
i
=
0
;
i
<
masks
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
masks
.
length
;
i
++)
{
int
mask
=
masks
[
i
];
int
mask
=
masks
[
i
];
...
@@ -322,16 +326,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -322,16 +326,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
continue
;
continue
;
}
}
indexColumnCount
++;
indexColumnCount
++;
paramIndex
.
add
(
i
);
// the number of parameters depends on the mask;
if
(
Integer
.
bitCount
(
mask
)
>
1
)
{
// for range queries it is 2: >= x AND <= y
// two parameters for range queries: >= x AND <= y
// but bitMask could also be 7 (=, and <=, and >=)
paramIndex
.
add
(
i
);
int
bitCount
=
Integer
.
bitCount
(
mask
);
for
(
int
j
=
0
;
j
<
bitCount
;
j
++)
{
paramColumnIndex
.
add
(
i
);
}
}
}
}
int
len
=
paramIndex
.
size
();
int
len
=
param
Column
Index
.
size
();
ArrayList
<
Column
>
columnList
=
New
.
arrayList
();
ArrayList
<
Column
>
columnList
=
New
.
arrayList
();
for
(
int
i
=
0
;
i
<
len
;)
{
for
(
int
i
=
0
;
i
<
len
;)
{
int
idx
=
paramIndex
.
get
(
i
);
int
idx
=
param
Column
Index
.
get
(
i
);
columnList
.
add
(
table
.
getColumn
(
idx
));
columnList
.
add
(
table
.
getColumn
(
idx
));
int
mask
=
masks
[
idx
];
int
mask
=
masks
[
idx
];
if
((
mask
&
IndexCondition
.
EQUALITY
)
!=
0
)
{
if
((
mask
&
IndexCondition
.
EQUALITY
)
!=
0
)
{
...
...
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
cc28d22a
...
@@ -34,6 +34,7 @@ public class TestView extends TestBase {
...
@@ -34,6 +34,7 @@ public class TestView extends TestBase {
@Override
@Override
public
void
test
()
throws
SQLException
{
public
void
test
()
throws
SQLException
{
deleteDb
(
"view"
);
deleteDb
(
"view"
);
testSubSubQuery
();
testSubQueryViewIndexCache
();
testSubQueryViewIndexCache
();
testInnerSelectWithRownum
();
testInnerSelectWithRownum
();
testInnerSelectWithRange
();
testInnerSelectWithRange
();
...
@@ -52,6 +53,19 @@ public class TestView extends TestBase {
...
@@ -52,6 +53,19 @@ public class TestView extends TestBase {
deleteDb
(
"view"
);
deleteDb
(
"view"
);
}
}
private
void
testSubSubQuery
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"view"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table test if exists"
);
stat
.
execute
(
"create table test(a int, b int, c int)"
);
stat
.
execute
(
"insert into test values(1, 1, 1)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select 1 x from (select a, b, c from "
+
"(select * from test) bbb where bbb.a >=1 and bbb.a <= 1) sp "
+
"where sp.a = 1 and sp.b = 1 and sp.c = 1"
);
assertTrue
(
rs
.
next
());
conn
.
close
();
}
private
void
testSubQueryViewIndexCache
()
throws
SQLException
{
private
void
testSubQueryViewIndexCache
()
throws
SQLException
{
if
(
config
.
networked
)
{
if
(
config
.
networked
)
{
return
;
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论