[fix](planner) trying register constnat slotRef to table cause NPE (#18356)

could reproduced by:

CREATE TABLE t (
name varchar(128)
) ENGINE=OLAP
UNIQUE KEY(name)
DISTRIBUTED BY HASH(name) BUCKETS 1;

insert into t values('abc');

SELECT cd
FROM
(SELECT cast(now() as string) cd FROM t) t1
JOIN
(select cast(now() as string) td from t GROUP BY now()) t2
ON t1.cd = t2.td;

ERROR 1105 (HY000): errCode = 2, detailMessage = Unexpected exception: null
This commit is contained in:
AKIRA
2023-04-06 12:50:12 +09:00
committed by GitHub
parent 9a916cffe4
commit 4ec6aa1691
5 changed files with 84 additions and 8 deletions

View File

@ -1195,7 +1195,7 @@ public class Analyzer {
registerConstantConjunct(id, conjunct);
}
}
markConstantConjunct(conjunct, fromHavingClause);
markConstantConjunct(conjunct, fromHavingClause, false);
}
}
@ -1211,7 +1211,7 @@ public class Analyzer {
}
public void registerMigrateFailedConjuncts(InlineViewRef ref, Expr e) throws AnalysisException {
markConstantConjunct(e, false);
markConstantConjunct(e, false, false);
Set<Expr> exprSet = globalState.migrateFailedConjuncts.computeIfAbsent(ref, (k) -> new HashSet<>());
exprSet.add(e);
}
@ -1824,7 +1824,7 @@ public class Analyzer {
if (rhsRef.getJoinOp().isInnerJoin()) {
globalState.ijClauseByConjunct.put(conjunct.getId(), rhsRef);
}
markConstantConjunct(conjunct, false);
markConstantConjunct(conjunct, false, true);
}
}
@ -1836,9 +1836,9 @@ public class Analyzer {
* No-op if the conjunct is not constant or is outer joined.
* Throws an AnalysisException if there is an error evaluating `conjunct`
*/
private void markConstantConjunct(Expr conjunct, boolean fromHavingClause)
private void markConstantConjunct(Expr conjunct, boolean fromHavingClause, boolean join)
throws AnalysisException {
if (!conjunct.isConstant() || isOjConjunct(conjunct)) {
if (!conjunct.isConstant() || isOjConjunct(conjunct) || join) {
return;
}
if ((!fromHavingClause && !hasEmptySpjResultSet)

View File

@ -1521,7 +1521,6 @@ public class QueryPlanTest extends TestWithFeService {
sqls.add("explain select k3, dense_rank() OVER () AS rank FROM baseall where 1 =2;");
sqls.add("explain select rank from (select k3, dense_rank() OVER () AS rank FROM baseall) a where 1 =2;");
sqls.add("explain select * from baseall join bigtable as b where 1 = 2");
sqls.add("explain select * from baseall join bigtable as b on null = 2");
for (String sql : sqls) {
String explainString = getSQLPlanOrErrorMsg(sql);