Skip to content

Commit

Permalink
planner: Fix predicate simplification panic caused by zero-argument e…
Browse files Browse the repository at this point in the history
…xpressions like rand() (pingcap#56947)

close pingcap#56270
  • Loading branch information
dash12653 authored Nov 14, 2024
1 parent a3c07e0 commit ed2d749
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/planner/core/rule_predicate_simplification.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func findPredicateType(expr expression.Expression) (*expression.Column, predicat
return nil, orPredicate
}
args := v.GetArgs()
if len(args) == 0 {
return nil, otherPredicate
}
col, colOk := args[0].(*expression.Column)
if !colOk {
return nil, otherPredicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,9 @@ NULL NULL 2 2 4 2
show warnings;
Level Code Message
drop table if exists t1, t2, t3, t4;
drop table if exists t0, v0;
drop view if exists v0;
CREATE TABLE t0(c0 INTEGER);
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0 WHERE (CASE t0.c0 WHEN t0.c0 THEN false END );
SELECT t0.c0 FROM v0, t0 WHERE RAND();
c0
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,10 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b order by 1, 2, 3, 4, 5;
show warnings;
drop table if exists t1, t2, t3, t4;

# TestIssue56270
drop table if exists t0, v0;
drop view if exists v0;
CREATE TABLE t0(c0 INTEGER);
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0 WHERE (CASE t0.c0 WHEN t0.c0 THEN false END );
SELECT t0.c0 FROM v0, t0 WHERE RAND();

0 comments on commit ed2d749

Please sign in to comment.