提交 dfe2078c authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Delay creation of index conditions for ON conditions to avoid NPE

上级 6801c1e5
...@@ -21,6 +21,10 @@ Change Log ...@@ -21,6 +21,10 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Issue #1762: NullPointerException in Parser. Introduced in 1.4.198
</li>
<li>PR #1768: Add more context-sensitive keywords
</li>
<li>Issue #1758: sequence restart issue with 1.4.198 <li>Issue #1758: sequence restart issue with 1.4.198
</li> </li>
<li>Issue #1759: SELECT &#8230; FOR UPDATE returns old data in 1.4.198 <li>Issue #1759: SELECT &#8230; FOR UPDATE returns old data in 1.4.198
......
...@@ -1382,6 +1382,7 @@ public class Select extends Query { ...@@ -1382,6 +1382,7 @@ public class Select extends Query {
private double preparePlan(boolean parse) { private double preparePlan(boolean parse) {
TableFilter[] topArray = topFilters.toArray(new TableFilter[0]); TableFilter[] topArray = topFilters.toArray(new TableFilter[0]);
for (TableFilter t : topArray) { for (TableFilter t : topArray) {
t.createIndexConditions();
t.setFullCondition(condition); t.setFullCondition(condition);
} }
......
...@@ -93,6 +93,11 @@ public class TableFilter implements ColumnResolver { ...@@ -93,6 +93,11 @@ public class TableFilter implements ColumnResolver {
*/ */
private Expression filterCondition; private Expression filterCondition;
/**
* Initial ON condition.
*/
private Expression onCondition;
/** /**
* The complete join condition. * The complete join condition.
*/ */
...@@ -709,18 +714,32 @@ public class TableFilter implements ColumnResolver { ...@@ -709,18 +714,32 @@ public class TableFilter implements ColumnResolver {
* @param on the condition * @param on the condition
*/ */
public void mapAndAddFilter(Expression on) { public void mapAndAddFilter(Expression on) {
this.onCondition = on;
on.mapColumns(this, 0, Expression.MAP_INITIAL); on.mapColumns(this, 0, Expression.MAP_INITIAL);
addFilterCondition(on, true); addFilterCondition(on, true);
on.createIndexConditions(session, this);
if (nestedJoin != null) { if (nestedJoin != null) {
on.mapColumns(nestedJoin, 0, Expression.MAP_INITIAL); on.mapColumns(nestedJoin, 0, Expression.MAP_INITIAL);
on.createIndexConditions(session, nestedJoin);
} }
if (join != null) { if (join != null) {
join.mapAndAddFilter(on); join.mapAndAddFilter(on);
} }
} }
public void createIndexConditions() {
if (onCondition != null) {
onCondition.createIndexConditions(session, this);
if (nestedJoin != null) {
onCondition.createIndexConditions(session, nestedJoin);
}
}
if (join != null) {
join.createIndexConditions();
}
if (nestedJoin != null) {
nestedJoin.createIndexConditions();
}
}
public TableFilter getJoin() { public TableFilter getJoin() {
return join; return join;
} }
......
...@@ -785,3 +785,20 @@ SELECT T1.X1, T2.X2, T3.X3, T4.X4, T5.X5 FROM ( ...@@ -785,3 +785,20 @@ SELECT T1.X1, T2.X2, T3.X3, T4.X4, T5.X5 FROM (
> -- -- -- -- -- > -- -- -- -- --
> 1 1 1 1 1 > 1 1 1 1 1
> rows: 1 > rows: 1
CREATE TABLE A(X INT);
> ok
CREATE TABLE B(Y INT);
> ok
CREATE TABLE C(Z INT);
> ok
SELECT A.X FROM A JOIN B ON A.X = B.Y AND B.Y >= COALESCE((SELECT Z FROM C FETCH FIRST ROW ONLY), 0);
> X
> -
> rows: 0
DROP TABLE A, B, C;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论