提交 a8424521 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.
上级 3a086f29
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Comparing an column against a constant expression with a higher precision or length <ul><li>Nested UNION/INTERSECT queries with brackets could produce the wrong result if used within a subquery. Example:
select count(*) from (select 1 union (select 2 intersect select 2)) x;
</li><li>Comparing an column against a constant expression with a higher precision or length
than the column could give wrong results (the expression was truncated before comparing). than the column could give wrong results (the expression was truncated before comparing).
</li><li>Improved PostgreSQL compatibility (support SHOW DEFAULT_TRANSACTION_ISOLATION). </li><li>Improved PostgreSQL compatibility (support SHOW DEFAULT_TRANSACTION_ISOLATION).
</li><li>Documentation: the javadocs for Csv.write and read used the wrong default charset. </li><li>Documentation: the javadocs for Csv.write and read used the wrong default charset.
......
...@@ -297,24 +297,24 @@ public class SelectUnion extends Query { ...@@ -297,24 +297,24 @@ public class SelectUnion extends Query {
public String getPlanSQL() { public String getPlanSQL() {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
buff.append('(').append(StringUtils.unEnclose(left.getPlanSQL())).append(')'); buff.append('(').append(left.getPlanSQL()).append(')');
switch (unionType) { switch (unionType) {
case UNION_ALL: case UNION_ALL:
buff.append("UNION ALL "); buff.append(" UNION ALL ");
break; break;
case UNION: case UNION:
buff.append("UNION "); buff.append(" UNION ");
break; break;
case INTERSECT: case INTERSECT:
buff.append("INTERSECT "); buff.append(" INTERSECT ");
break; break;
case EXCEPT: case EXCEPT:
buff.append("EXCEPT "); buff.append(" EXCEPT ");
break; break;
default: default:
Message.throwInternalError("type=" + unionType); Message.throwInternalError("type=" + unionType);
} }
buff.append('(').append(StringUtils.unEnclose(right.getPlanSQL())).append(')'); buff.append('(').append(right.getPlanSQL()).append(')');
Expression[] exprList = expressions.toArray(new Expression[expressions.size()]); Expression[] exprList = expressions.toArray(new Expression[expressions.size()]);
if (sort != null) { if (sort != null) {
buff.append(" ORDER BY ").append(sort.getSQL(exprList, exprList.length)); buff.append(" ORDER BY ").append(sort.getSQL(exprList, exprList.length));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论