提交 636da38e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix NPE with some complex join conditions

上级 78afc669
......@@ -265,12 +265,35 @@ public class TableFilter implements ColumnResolver {
if (nestedJoin != null) {
if (item.getNestedJoinPlan() != null) {
nestedJoin.setPlanItem(item.getNestedJoinPlan());
} else {
setScanIndexes(nestedJoin);
}
}
if (join != null) {
if (item.getJoinPlan() != null) {
join.setPlanItem(item.getJoinPlan());
} else {
setScanIndexes(join);
}
}
}
/**
* Set all missing indexes to scan indexes recursively.
*
* @param table filter to start from
*/
private void setScanIndexes(TableFilter filter) {
if (filter.getIndex() == null) {
filter.setIndex(filter.getTable().getScanIndex(session));
}
TableFilter j = filter.join;
if (j != null) {
setScanIndexes(j);
}
j = filter.nestedJoin;
if (j != null) {
setScanIndexes(j);
}
}
......
......@@ -747,3 +747,32 @@ DROP TABLE B;
DROP TABLE C;
> ok
CREATE TABLE T1(X1 INT);
CREATE TABLE T2(X2 INT);
CREATE TABLE T3(X3 INT);
CREATE TABLE T4(X4 INT);
CREATE TABLE T5(X5 INT);
INSERT INTO T1 VALUES (1);
INSERT INTO T1 VALUES (NULL);
INSERT INTO T2 VALUES (1);
INSERT INTO T2 VALUES (NULL);
INSERT INTO T3 VALUES (1);
INSERT INTO T3 VALUES (NULL);
INSERT INTO T4 VALUES (1);
INSERT INTO T4 VALUES (NULL);
INSERT INTO T5 VALUES (1);
INSERT INTO T5 VALUES (NULL);
SELECT T1.X1, T2.X2, T3.X3, T4.X4, T5.X5 FROM (
T1 INNER JOIN (
T2 LEFT OUTER JOIN (
T3 INNER JOIN T4 ON T3.X3 = T4.X4
) ON T2.X2 = T4.X4
) ON T1.X1 = T2.X2
) INNER JOIN T5 ON T2.X2 = T5.X5;
> X1 X2 X3 X4 X5
> -- -- -- -- --
> 1 1 1 1 1
> rows: 1
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论