Skip to content

Commit ed2d749

Browse files
authored
planner: Fix predicate simplification panic caused by zero-argument expressions like rand() (#56947)
close #56270
1 parent a3c07e0 commit ed2d749

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

pkg/planner/core/rule_predicate_simplification.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func findPredicateType(expr expression.Expression) (*expression.Column, predicat
5555
return nil, orPredicate
5656
}
5757
args := v.GetArgs()
58+
if len(args) == 0 {
59+
return nil, otherPredicate
60+
}
5861
col, colOk := args[0].(*expression.Column)
5962
if !colOk {
6063
return nil, otherPredicate

tests/integrationtest/r/planner/core/issuetest/planner_issue.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,9 @@ NULL NULL 2 2 4 2
750750
show warnings;
751751
Level Code Message
752752
drop table if exists t1, t2, t3, t4;
753+
drop table if exists t0, v0;
754+
drop view if exists v0;
755+
CREATE TABLE t0(c0 INTEGER);
756+
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0 WHERE (CASE t0.c0 WHEN t0.c0 THEN false END );
757+
SELECT t0.c0 FROM v0, t0 WHERE RAND();
758+
c0

tests/integrationtest/t/planner/core/issuetest/planner_issue.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,10 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
517517
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
518518
show warnings;
519519
drop table if exists t1, t2, t3, t4;
520+
521+
# TestIssue56270
522+
drop table if exists t0, v0;
523+
drop view if exists v0;
524+
CREATE TABLE t0(c0 INTEGER);
525+
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0 WHERE (CASE t0.c0 WHEN t0.c0 THEN false END );
526+
SELECT t0.c0 FROM v0, t0 WHERE RAND();

0 commit comments

Comments
 (0)