Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
46bf0299
提交
46bf0299
authored
2月 26, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Nest joins only if required
上级
636da38e
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
29 行删除
+25
-29
Parser.java
h2/src/main/org/h2/command/Parser.java
+23
-27
TestNestedJoins.java
h2/src/test/org/h2/test/synth/TestNestedJoins.java
+1
-1
TestOuterJoins.java
h2/src/test/org/h2/test/synth/TestOuterJoins.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
46bf0299
...
@@ -1369,8 +1369,7 @@ public class Parser {
...
@@ -1369,8 +1369,7 @@ public class Parser {
}
else
{
}
else
{
TableFilter
top
;
TableFilter
top
;
top
=
readTableFilter
();
top
=
readTableFilter
();
top
=
readJoin
(
top
,
false
);
top
=
readJoin
(
top
);
top
=
getNested
(
top
);
read
(
")"
);
read
(
")"
);
alias
=
readFromAlias
(
null
);
alias
=
readFromAlias
(
null
);
if
(
alias
!=
null
)
{
if
(
alias
!=
null
)
{
...
@@ -1717,8 +1716,7 @@ public class Parser {
...
@@ -1717,8 +1716,7 @@ public class Parser {
return
command
;
return
command
;
}
}
private
TableFilter
readJoin
(
TableFilter
top
,
boolean
nested
)
{
private
TableFilter
readJoin
(
TableFilter
top
)
{
boolean
joined
=
false
;
TableFilter
last
=
top
;
TableFilter
last
=
top
;
while
(
true
)
{
while
(
true
)
{
TableFilter
join
;
TableFilter
join
;
...
@@ -1727,47 +1725,46 @@ public class Parser {
...
@@ -1727,47 +1725,46 @@ public class Parser {
read
(
"JOIN"
);
read
(
"JOIN"
);
// the right hand side is the 'inner' table usually
// the right hand side is the 'inner' table usually
join
=
readTableFilter
();
join
=
readTableFilter
();
join
=
readJoin
(
join
,
nested
);
join
=
readJoin
(
join
);
Expression
on
=
null
;
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
=
getNested
(
top
);
addJoin
(
join
,
top
,
true
,
on
);
join
.
addJoin
(
top
,
true
,
on
);
top
=
join
;
top
=
join
;
}
else
if
(
readIf
(
"LEFT"
))
{
}
else
if
(
readIf
(
"LEFT"
))
{
readIf
(
"OUTER"
);
readIf
(
"OUTER"
);
read
(
"JOIN"
);
read
(
"JOIN"
);
join
=
readTableFilter
();
join
=
readTableFilter
();
join
=
readJoin
(
join
,
true
);
join
=
readJoin
(
join
);
Expression
on
=
null
;
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
.
addJoin
(
join
,
true
,
on
);
addJoin
(
top
,
join
,
true
,
on
);
}
else
if
(
readIf
(
"FULL"
))
{
}
else
if
(
readIf
(
"FULL"
))
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
else
if
(
readIf
(
"INNER"
))
{
}
else
if
(
readIf
(
"INNER"
))
{
read
(
"JOIN"
);
read
(
"JOIN"
);
join
=
readTableFilter
();
join
=
readTableFilter
();
top
=
readJoin
(
top
,
false
);
top
=
readJoin
(
top
);
Expression
on
=
null
;
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
.
addJoin
(
join
,
false
,
on
);
addJoin
(
top
,
join
,
false
,
on
);
}
else
if
(
readIf
(
"JOIN"
))
{
}
else
if
(
readIf
(
"JOIN"
))
{
join
=
readTableFilter
();
join
=
readTableFilter
();
top
=
readJoin
(
top
,
false
);
top
=
readJoin
(
top
);
Expression
on
=
null
;
Expression
on
=
null
;
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
.
addJoin
(
join
,
false
,
on
);
addJoin
(
top
,
join
,
false
,
on
);
}
else
if
(
readIf
(
"CROSS"
))
{
}
else
if
(
readIf
(
"CROSS"
))
{
read
(
"JOIN"
);
read
(
"JOIN"
);
join
=
readTableFilter
();
join
=
readTableFilter
();
top
.
addJoin
(
join
,
false
,
null
);
addJoin
(
top
,
join
,
false
,
null
);
}
else
if
(
readIf
(
"NATURAL"
))
{
}
else
if
(
readIf
(
"NATURAL"
))
{
read
(
"JOIN"
);
read
(
"JOIN"
);
join
=
readTableFilter
();
join
=
readTableFilter
();
...
@@ -1799,26 +1796,25 @@ public class Parser {
...
@@ -1799,26 +1796,25 @@ public class Parser {
}
}
}
}
}
}
top
.
addJoin
(
join
,
false
,
on
);
addJoin
(
top
,
join
,
false
,
on
);
}
else
{
}
else
{
break
;
break
;
}
}
joined
=
true
;
last
=
join
;
last
=
join
;
}
}
if
(
nested
&&
joined
)
{
top
=
getNested
(
top
);
}
return
top
;
return
top
;
}
}
private
TableFilter
getNested
(
TableFilter
n
)
{
private
void
addJoin
(
TableFilter
top
,
TableFilter
join
,
boolean
outer
,
Expression
on
)
{
if
(
join
.
getJoin
()
!=
null
)
{
String
joinTable
=
Constants
.
PREFIX_JOIN
+
parseIndex
;
String
joinTable
=
Constants
.
PREFIX_JOIN
+
parseIndex
;
TableFilter
top
=
new
TableFilter
(
session
,
getDualTable
(
true
),
TableFilter
n
=
new
TableFilter
(
session
,
getDualTable
(
true
),
joinTable
,
rightsChecked
,
currentSelect
,
n
.
getOrderInFrom
(),
joinTable
,
rightsChecked
,
currentSelect
,
joi
n
.
getOrderInFrom
(),
null
);
null
);
top
.
setNestedJoin
(
n
);
n
.
setNestedJoin
(
join
);
return
top
;
join
=
n
;
}
top
.
addJoin
(
join
,
outer
,
on
);
}
}
private
Prepared
parseExecute
()
{
private
Prepared
parseExecute
()
{
...
@@ -2149,7 +2145,7 @@ public class Parser {
...
@@ -2149,7 +2145,7 @@ public class Parser {
}
}
private
void
parseJoinTableFilter
(
TableFilter
top
,
final
Select
command
)
{
private
void
parseJoinTableFilter
(
TableFilter
top
,
final
Select
command
)
{
top
=
readJoin
(
top
,
false
);
top
=
readJoin
(
top
);
command
.
addTableFilter
(
top
,
true
);
command
.
addTableFilter
(
top
,
true
);
boolean
isOuter
=
false
;
boolean
isOuter
=
false
;
while
(
true
)
{
while
(
true
)
{
...
...
h2/src/test/org/h2/test/synth/TestNestedJoins.java
浏览文件 @
46bf0299
...
@@ -380,7 +380,7 @@ public class TestNestedJoins extends TestBase {
...
@@ -380,7 +380,7 @@ public class TestNestedJoins extends TestBase {
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
sql
=
cleanRemarks
(
rs
.
getString
(
1
));
sql
=
cleanRemarks
(
rs
.
getString
(
1
));
assertEquals
(
"SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 "
+
assertEquals
(
"SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 "
+
"LEFT OUTER JOIN ( PUBLIC.T3 LEFT OUTER JOIN
( PUBLIC.T1 )
"
+
"LEFT OUTER JOIN ( PUBLIC.T3 LEFT OUTER JOIN
PUBLIC.T1
"
+
"ON T1.B = T3.A ) ON T2.B = T1.A"
,
sql
);
"ON T1.B = T3.A ) ON T2.B = T1.A"
,
sql
);
rs
=
stat
.
executeQuery
(
"select distinct t1.a, t2.a, t3.a from t1 "
+
rs
=
stat
.
executeQuery
(
"select distinct t1.a, t2.a, t3.a from t1 "
+
"right outer join t3 on t1.b=t3.a "
+
"right outer join t3 on t1.b=t3.a "
+
...
...
h2/src/test/org/h2/test/synth/TestOuterJoins.java
浏览文件 @
46bf0299
...
@@ -334,7 +334,7 @@ public class TestOuterJoins extends TestBase {
...
@@ -334,7 +334,7 @@ public class TestOuterJoins extends TestBase {
sql
=
cleanRemarks
(
rs
.
getString
(
1
));
sql
=
cleanRemarks
(
rs
.
getString
(
1
));
assertEquals
(
"SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 "
+
assertEquals
(
"SELECT DISTINCT T1.A, T2.A, T3.A FROM PUBLIC.T2 "
+
"LEFT OUTER JOIN ( PUBLIC.T3 "
+
"LEFT OUTER JOIN ( PUBLIC.T3 "
+
"LEFT OUTER JOIN
( PUBLIC.T1 )
ON T1.B = T3.A ) "
+
"LEFT OUTER JOIN
PUBLIC.T1
ON T1.B = T3.A ) "
+
"ON T2.B = T1.A"
,
sql
);
"ON T2.B = T1.A"
,
sql
);
rs
=
stat
.
executeQuery
(
"select distinct t1.a, t2.a, t3.a from t1 "
+
rs
=
stat
.
executeQuery
(
"select distinct t1.a, t2.a, t3.a from t1 "
+
"right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a"
);
"right outer join t3 on t1.b=t3.a right outer join t2 on t2.b=t1.a"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论