Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7e5ab118
Unverified
提交
7e5ab118
authored
7 年前
作者:
Noel Grandin
提交者:
GitHub
7 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #906 from katzyn/join
Fix obscure error on non-standard SELECT * FROM A LEFT JOIN B NATURAL JOIN C
上级
7b0abb0e
8d8f86cf
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
102 行增加
和
29 行删除
+102
-29
Parser.java
h2/src/main/org/h2/command/Parser.java
+8
-8
Optimizer.java
h2/src/main/org/h2/command/dml/Optimizer.java
+1
-1
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+14
-20
joins.sql
h2/src/test/org/h2/test/scripts/joins.sql
+79
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
7e5ab118
...
@@ -1733,7 +1733,7 @@ public class Parser {
...
@@ -1733,7 +1733,7 @@ public class Parser {
on
=
readExpression
();
on
=
readExpression
();
}
}
top
=
getNested
(
top
);
top
=
getNested
(
top
);
join
.
addJoin
(
top
,
true
,
false
,
on
);
join
.
addJoin
(
top
,
true
,
on
);
top
=
join
;
top
=
join
;
}
else
if
(
readIf
(
"LEFT"
))
{
}
else
if
(
readIf
(
"LEFT"
))
{
readIf
(
"OUTER"
);
readIf
(
"OUTER"
);
...
@@ -1744,7 +1744,7 @@ public class Parser {
...
@@ -1744,7 +1744,7 @@ public class Parser {
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
.
addJoin
(
join
,
true
,
false
,
on
);
top
.
addJoin
(
join
,
true
,
on
);
}
else
if
(
readIf
(
"FULL"
))
{
}
else
if
(
readIf
(
"FULL"
))
{
throw
getSyntaxError
();
throw
getSyntaxError
();
}
else
if
(
readIf
(
"INNER"
))
{
}
else
if
(
readIf
(
"INNER"
))
{
...
@@ -1755,7 +1755,7 @@ public class Parser {
...
@@ -1755,7 +1755,7 @@ public class Parser {
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
.
addJoin
(
join
,
false
,
false
,
on
);
top
.
addJoin
(
join
,
false
,
on
);
}
else
if
(
readIf
(
"JOIN"
))
{
}
else
if
(
readIf
(
"JOIN"
))
{
join
=
readTableFilter
();
join
=
readTableFilter
();
top
=
readJoin
(
top
,
false
);
top
=
readJoin
(
top
,
false
);
...
@@ -1763,11 +1763,11 @@ public class Parser {
...
@@ -1763,11 +1763,11 @@ public class Parser {
if
(
readIf
(
"ON"
))
{
if
(
readIf
(
"ON"
))
{
on
=
readExpression
();
on
=
readExpression
();
}
}
top
.
addJoin
(
join
,
false
,
false
,
on
);
top
.
addJoin
(
join
,
false
,
on
);
}
else
if
(
readIf
(
"CROSS"
))
{
}
else
if
(
readIf
(
"CROSS"
))
{
read
(
"JOIN"
);
read
(
"JOIN"
);
join
=
readTableFilter
();
join
=
readTableFilter
();
top
.
addJoin
(
join
,
false
,
false
,
null
);
top
.
addJoin
(
join
,
false
,
null
);
}
else
if
(
readIf
(
"NATURAL"
))
{
}
else
if
(
readIf
(
"NATURAL"
))
{
read
(
"JOIN"
);
read
(
"JOIN"
);
join
=
readTableFilter
();
join
=
readTableFilter
();
...
@@ -1799,7 +1799,7 @@ public class Parser {
...
@@ -1799,7 +1799,7 @@ public class Parser {
}
}
}
}
}
}
top
.
addJoin
(
join
,
false
,
nested
,
on
);
top
.
addJoin
(
join
,
false
,
on
);
}
else
{
}
else
{
break
;
break
;
}
}
...
@@ -1817,7 +1817,7 @@ public class Parser {
...
@@ -1817,7 +1817,7 @@ public class Parser {
TableFilter
top
=
new
TableFilter
(
session
,
getDualTable
(
true
),
TableFilter
top
=
new
TableFilter
(
session
,
getDualTable
(
true
),
joinTable
,
rightsChecked
,
currentSelect
,
n
.
getOrderInFrom
(),
joinTable
,
rightsChecked
,
currentSelect
,
n
.
getOrderInFrom
(),
null
);
null
);
top
.
addJoin
(
n
,
false
,
true
,
null
);
top
.
setNestedJoin
(
n
);
return
top
;
return
top
;
}
}
...
@@ -2490,7 +2490,7 @@ public class Parser {
...
@@ -2490,7 +2490,7 @@ public class Parser {
int
idx
=
filters
.
indexOf
(
rightFilter
);
int
idx
=
filters
.
indexOf
(
rightFilter
);
if
(
idx
>=
0
)
{
if
(
idx
>=
0
)
{
filters
.
remove
(
idx
);
filters
.
remove
(
idx
);
leftFilter
.
addJoin
(
rightFilter
,
true
,
false
,
r
);
leftFilter
.
addJoin
(
rightFilter
,
true
,
r
);
}
else
{
}
else
{
rightFilter
.
mapAndAddFilter
(
r
);
rightFilter
.
mapAndAddFilter
(
r
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Optimizer.java
浏览文件 @
7e5ab118
...
@@ -247,7 +247,7 @@ class Optimizer {
...
@@ -247,7 +247,7 @@ class Optimizer {
TableFilter
[]
f2
=
bestPlan
.
getFilters
();
TableFilter
[]
f2
=
bestPlan
.
getFilters
();
topFilter
=
f2
[
0
];
topFilter
=
f2
[
0
];
for
(
int
i
=
0
;
i
<
f2
.
length
-
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
f2
.
length
-
1
;
i
++)
{
f2
[
i
].
addJoin
(
f2
[
i
+
1
],
false
,
false
,
null
);
f2
[
i
].
addJoin
(
f2
[
i
+
1
],
false
,
null
);
}
}
if
(
parse
)
{
if
(
parse
)
{
return
;
return
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
7e5ab118
...
@@ -637,29 +637,15 @@ public class TableFilter implements ColumnResolver {
...
@@ -637,29 +637,15 @@ public class TableFilter implements ColumnResolver {
*
*
* @param filter the joined table filter
* @param filter the joined table filter
* @param outer if this is an outer join
* @param outer if this is an outer join
* @param nested if this is a nested join
* @param on the join condition
* @param on the join condition
*/
*/
public
void
addJoin
(
TableFilter
filter
,
boolean
outer
,
boolean
nested
,
Expression
on
)
{
public
void
addJoin
(
TableFilter
filter
,
boolean
outer
,
Expression
on
)
{
if
(
on
!=
null
)
{
if
(
on
!=
null
)
{
on
.
mapColumns
(
this
,
0
);
on
.
mapColumns
(
this
,
0
);
TableFilterVisitor
visitor
=
new
MapColumnsVisitor
(
on
);
TableFilterVisitor
visitor
=
new
MapColumnsVisitor
(
on
);
visit
(
visitor
);
visit
(
visitor
);
filter
.
visit
(
visitor
);
filter
.
visit
(
visitor
);
}
}
if
(
nested
)
{
if
(
nestedJoin
!=
null
)
{
throw
DbException
.
throwInternalError
();
}
nestedJoin
=
filter
;
filter
.
joinOuter
=
outer
;
if
(
outer
)
{
visit
(
new
JOIVisitor
());
}
if
(
on
!=
null
)
{
filter
.
mapAndAddFilter
(
on
);
}
}
else
{
if
(
join
==
null
)
{
if
(
join
==
null
)
{
join
=
filter
;
join
=
filter
;
filter
.
joinOuter
=
outer
;
filter
.
joinOuter
=
outer
;
...
@@ -670,9 +656,17 @@ public class TableFilter implements ColumnResolver {
...
@@ -670,9 +656,17 @@ public class TableFilter implements ColumnResolver {
filter
.
mapAndAddFilter
(
on
);
filter
.
mapAndAddFilter
(
on
);
}
}
}
else
{
}
else
{
join
.
addJoin
(
filter
,
outer
,
false
,
on
);
join
.
addJoin
(
filter
,
outer
,
on
);
}
}
}
}
/**
* Set a nested joined table.
*
* @param filter the joined table filter
*/
public
void
setNestedJoin
(
TableFilter
filter
)
{
nestedJoin
=
filter
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/joins.sql
浏览文件 @
7e5ab118
...
@@ -668,3 +668,82 @@ DROP TABLE PARENT;
...
@@ -668,3 +668,82 @@ DROP TABLE PARENT;
DROP
TABLE
CHILD
;
DROP
TABLE
CHILD
;
>
ok
>
ok
CREATE
TABLE
A
(
A1
INT
,
A2
INT
);
>
ok
INSERT
INTO
A
VALUES
(
1
,
2
);
>
update
count
:
1
CREATE
TABLE
B
(
B1
INT
,
B2
INT
);
>
ok
INSERT
INTO
B
VALUES
(
1
,
2
);
>
update
count
:
1
CREATE
TABLE
C
(
B1
INT
,
C1
INT
);
>
ok
INSERT
INTO
C
VALUES
(
1
,
2
);
>
update
count
:
1
SELECT
*
FROM
A
LEFT
JOIN
B
ON
TRUE
;
>
A1
A2
B1
B2
>
-- -- -- --
>
1
2
1
2
>
rows
:
1
SELECT
A
.
A1
,
A
.
A2
,
B
.
B1
,
B
.
B2
FROM
A
RIGHT
JOIN
B
ON
TRUE
;
>
A1
A2
B1
B2
>
-- -- -- --
>
1
2
1
2
>
rows
:
1
-- this syntax without ON or USING in not standard
SELECT
*
FROM
A
LEFT
JOIN
B
;
>
A1
A2
B1
B2
>
-- -- -- --
>
1
2
1
2
>
rows
:
1
-- this syntax without ON or USING in not standard
SELECT
A
.
A1
,
A
.
A2
,
B
.
B1
,
B
.
B2
FROM
A
RIGHT
JOIN
B
;
>
A1
A2
B1
B2
>
-- -- -- --
>
1
2
1
2
>
rows
:
1
SELECT
*
FROM
A
LEFT
JOIN
B
ON
TRUE
NATURAL
JOIN
C
;
>
A1
A2
B1
B2
C1
>
-- -- -- -- --
>
1
2
1
2
2
>
rows
:
1
SELECT
A
.
A1
,
A
.
A2
,
B
.
B1
,
B
.
B2
,
C
.
C1
FROM
A
RIGHT
JOIN
B
ON
TRUE
NATURAL
JOIN
C
;
>
A1
A2
B1
B2
C1
>
-- -- -- -- --
>
1
2
1
2
2
>
rows
:
1
-- this syntax without ON or USING in not standard
SELECT
*
FROM
A
LEFT
JOIN
B
NATURAL
JOIN
C
;
>
A1
A2
B1
B2
C1
>
-- -- -- -- --
>
1
2
1
2
2
>
rows
:
1
-- this syntax without ON or USING in not standard
SELECT
A
.
A1
,
A
.
A2
,
B
.
B1
,
B
.
B2
,
C
.
C1
FROM
A
RIGHT
JOIN
B
NATURAL
JOIN
C
;
>
A1
A2
B1
B2
C1
>
-- -- -- -- --
>
1
2
1
2
2
>
rows
:
1
DROP
TABLE
A
;
>
ok
DROP
TABLE
B
;
>
ok
DROP
TABLE
C
;
>
ok
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论