提交 293baaea authored 作者: Thomas Mueller's avatar Thomas Mueller

Nested UNION/INTERSECT queries with brackets could produce the wrong result if…

Nested UNION/INTERSECT queries with brackets could produce the wrong result if used within a subquery.
上级 05c6a343
......@@ -950,8 +950,19 @@ public class Parser {
Table table;
String alias = null;
if (readIf("(")) {
if (isToken("SELECT") || isToken("FROM")) {
// need to read ahead, it could be a nested union or join:
// select 1 from (((select 1) union (select 1)) union (select 1));
// select * from ((test d1 inner join test d2 on d1.id = d2.id)
// inner join test d3 on d1.id = d3.id) inner join test d4
// on d4.id = d1.id;
int start = lastParseIndex;
while (readIf("(")) {
// ignore, but go back later
}
if (isToken("SELECT") || isToken("FROM")) {
parseIndex = start;
read();
start = lastParseIndex;
int paramIndex = parameters.size();
Query query = parseSelectUnion();
read(")");
......@@ -971,6 +982,8 @@ public class Parser {
alias = session.getNextSystemIdentifier(sqlCommand);
table = TableView.createTempView(s, session.getUser(), alias, query, currentSelect);
} else {
parseIndex = start;
read();
TableFilter top = readTableFilter(fromOuter);
top = readJoin(top, currentSelect, fromOuter);
read(")");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论