Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f2c91521
提交
f2c91521
authored
11月 17, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Nested outer joins without brackets were not working as expected.
上级
f96bcd3a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
21 行删除
+53
-21
Parser.java
h2/src/main/org/h2/command/Parser.java
+36
-20
TestNestedJoins.java
h2/src/test/org/h2/test/synth/TestNestedJoins.java
+17
-1
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
f2c91521
...
...
@@ -610,7 +610,6 @@ public class Parser {
return
schema
;
}
private
Schema
getSchema
()
{
return
getSchema
(
schemaName
);
}
...
...
@@ -980,14 +979,12 @@ public class Parser {
}
else
{
TableFilter
top
;
if
(
database
.
getSettings
().
nestedJoins
)
{
String
joinTable
=
Constants
.
PREFIX_JOIN
+
parseIndex
;
top
=
new
TableFilter
(
session
,
getDualTable
(
true
),
joinTable
,
rightsChecked
,
currentSelect
);
TableFilter
n
=
readTableFilter
(
false
);
n
=
readJoin
(
n
,
currentSelect
,
false
);
top
.
addJoin
(
n
,
false
,
true
,
null
);
top
=
readTableFilter
(
false
);
top
=
readJoin
(
top
,
currentSelect
,
false
,
false
);
top
=
getNested
(
top
);
}
else
{
top
=
readTableFilter
(
fromOuter
);
top
=
readJoin
(
top
,
currentSelect
,
fromOuter
);
top
=
readJoin
(
top
,
currentSelect
,
f
alse
,
f
romOuter
);
}
read
(
")"
);
alias
=
readFromAlias
(
null
);
...
...
@@ -1257,25 +1254,25 @@ public class Parser {
return
command
;
}
private
TableFilter
readJoin
(
TableFilter
top
,
Select
command
,
boolean
fromOuter
)
{
private
TableFilter
readJoin
(
TableFilter
top
,
Select
command
,
boolean
nested
,
boolean
fromOuter
)
{
boolean
joined
=
false
;
TableFilter
last
=
top
;
boolean
nestedJoins
=
database
.
getSettings
().
nestedJoins
;
while
(
true
)
{
if
(
readIf
(
"RIGHT"
))
{
readIf
(
"OUTER"
);
read
(
"JOIN"
);
joined
=
true
;
// the right hand side is the 'inner' table usually
TableFilter
newTop
=
readTableFilter
(
fromOuter
);
newTop
=
readJoin
(
newTop
,
command
,
true
);
newTop
=
readJoin
(
newTop
,
command
,
nested
,
true
);
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
}
if
(
nestedJoins
)
{
String
joinTable
=
Constants
.
PREFIX_JOIN
+
parseIndex
;
TableFilter
nt
=
new
TableFilter
(
session
,
getDualTable
(
true
),
joinTable
,
rightsChecked
,
currentSelect
);
nt
.
addJoin
(
top
,
false
,
true
,
null
);
newTop
.
addJoin
(
nt
,
true
,
false
,
on
);
top
=
getNested
(
top
);
newTop
.
addJoin
(
top
,
true
,
false
,
on
);
}
else
{
newTop
.
addJoin
(
top
,
true
,
false
,
on
);
}
...
...
@@ -1284,8 +1281,13 @@ public class Parser {
}
else
if
(
readIf
(
"LEFT"
))
{
readIf
(
"OUTER"
);
read
(
"JOIN"
);
joined
=
true
;
TableFilter
join
=
readTableFilter
(
true
);
top
=
readJoin
(
top
,
command
,
true
);
if
(
nestedJoins
)
{
join
=
readJoin
(
join
,
command
,
true
,
true
);
}
else
{
top
=
readJoin
(
top
,
command
,
false
,
true
);
}
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
...
...
@@ -1296,8 +1298,9 @@ public class Parser {
throw
getSyntaxError
();
}
else
if
(
readIf
(
"INNER"
))
{
read
(
"JOIN"
);
joined
=
true
;
TableFilter
join
=
readTableFilter
(
fromOuter
);
top
=
readJoin
(
top
,
command
,
false
);
top
=
readJoin
(
top
,
command
,
false
,
false
);
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
...
...
@@ -1309,8 +1312,9 @@ public class Parser {
}
last
=
join
;
}
else
if
(
readIf
(
"JOIN"
))
{
joined
=
true
;
TableFilter
join
=
readTableFilter
(
fromOuter
);
top
=
readJoin
(
top
,
command
,
false
);
top
=
readJoin
(
top
,
command
,
false
,
false
);
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
...
...
@@ -1323,6 +1327,7 @@ public class Parser {
last
=
join
;
}
else
if
(
readIf
(
"CROSS"
))
{
read
(
"JOIN"
);
joined
=
true
;
TableFilter
join
=
readTableFilter
(
fromOuter
);
if
(
nestedJoins
)
{
top
.
addJoin
(
join
,
false
,
false
,
null
);
...
...
@@ -1332,6 +1337,7 @@ public class Parser {
last
=
join
;
}
else
if
(
readIf
(
"NATURAL"
))
{
read
(
"JOIN"
);
joined
=
true
;
TableFilter
join
=
readTableFilter
(
fromOuter
);
Column
[]
tableCols
=
last
.
getTable
().
getColumns
();
Column
[]
joinCols
=
join
.
getTable
().
getColumns
();
...
...
@@ -1358,7 +1364,7 @@ public class Parser {
}
}
if
(
nestedJoins
)
{
top
.
addJoin
(
join
,
false
,
false
,
on
);
top
.
addJoin
(
join
,
false
,
nested
,
on
);
}
else
{
top
.
addJoin
(
join
,
fromOuter
,
false
,
on
);
}
...
...
@@ -1367,6 +1373,16 @@ public class Parser {
break
;
}
}
if
(
nested
&&
joined
)
{
top
=
getNested
(
top
);
}
return
top
;
}
private
TableFilter
getNested
(
TableFilter
n
)
{
String
joinTable
=
Constants
.
PREFIX_JOIN
+
parseIndex
;
TableFilter
top
=
new
TableFilter
(
session
,
getDualTable
(
true
),
joinTable
,
rightsChecked
,
currentSelect
);
top
.
addJoin
(
n
,
false
,
true
,
null
);
return
top
;
}
...
...
@@ -1606,7 +1622,7 @@ public class Parser {
}
private
void
parseJoinTableFilter
(
TableFilter
top
,
final
Select
command
)
{
top
=
readJoin
(
top
,
command
,
top
.
isJoinOuter
());
top
=
readJoin
(
top
,
command
,
false
,
top
.
isJoinOuter
());
command
.
addTableFilter
(
top
,
true
);
boolean
isOuter
=
false
;
while
(
true
)
{
...
...
@@ -2025,7 +2041,7 @@ public class Parser {
private
JavaFunction
readJavaFunction
(
Schema
schema
,
String
functionName
)
{
FunctionAlias
functionAlias
=
null
;
if
(
schema
!=
null
)
{
functionAlias
=
schema
.
findFunction
(
functionName
);
functionAlias
=
schema
.
findFunction
(
functionName
);
}
else
{
functionAlias
=
findFunctionAlias
(
session
.
getCurrentSchemaName
(),
functionName
);
}
...
...
@@ -2051,7 +2067,7 @@ public class Parser {
ArrayList
<
Expression
>
params
=
New
.
arrayList
();
do
{
params
.
add
(
readExpression
());
}
while
(
readIf
(
","
));
}
while
(
readIf
(
","
));
read
(
")"
);
Expression
[]
list
=
new
Expression
[
params
.
size
()];
params
.
toArray
(
list
);
...
...
h2/src/test/org/h2/test/synth/TestNestedJoins.java
浏览文件 @
f2c91521
...
...
@@ -242,6 +242,22 @@ public class TestNestedJoins extends TestBase {
ResultSet
rs
;
String
sql
;
/*
create table a(id int);
create table b(id int);
create table c(id int);
select * from a inner join b inner join c on c.id = b.id on b.id = a.id;
drop table a, b, c;
*/
stat
.
execute
(
"create table a(id int)"
);
stat
.
execute
(
"create table b(id int)"
);
stat
.
execute
(
"create table c(id int)"
);
rs
=
stat
.
executeQuery
(
"explain select * from a inner join b inner join c on c.id = b.id on b.id = a.id"
);
assertTrue
(
rs
.
next
());
sql
=
rs
.
getString
(
1
);
assertTrue
(
"nested"
,
sql
.
indexOf
(
"("
)
>=
0
);
stat
.
execute
(
"drop table a, b, c"
);
/*
create table test(id int primary key, x int)
as select x, x from system_range(1, 10);
...
...
@@ -268,7 +284,7 @@ public class TestNestedJoins extends TestBase {
assertTrue
(
rs
.
next
());
sql
=
rs
.
getString
(
1
);
int
todo
;
//
assertTrue("using table scan", sql.indexOf("tableScan") < 0);
//
assertTrue("using table scan", sql.indexOf("tableScan") < 0);
stat
.
execute
(
"drop table test"
);
stat
.
execute
(
"drop table o"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论