Skip to content

Commit c798e6d

Browse files
authored
planner: fix null-safe equality partition pruning (pingcap#68425)
close pingcap#65991
1 parent 5a972f0 commit c798e6d

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

pkg/planner/core/issuetest/planner_issue_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,20 @@ ORDER BY t1.a, t2.a, t3.a, var`
918918
"10 <nil> <nil> 6",
919919
))
920920
})
921+
922+
// constant-left-nulleq-partition-pruning
923+
testkit.RunTestUnderCascades(t, func(t *testing.T, tk *testkit.TestKit, cascades, caller string) {
924+
resetTestDB(t, tk)
925+
tk.MustExec("create table t_range(a int) partition by range(a) (partition p0 values less than (10), partition p1 values less than maxvalue)")
926+
tk.MustExec("insert into t_range values (1), (11), (null)")
927+
tk.MustQuery("select /* issue:65991 */ a from t_range where 1 <=> a").Check(testkit.Rows("1"))
928+
tk.MustQuery("select /* issue:65991 */ a from t_range where null <=> a").Check(testkit.Rows("<nil>"))
929+
930+
tk.MustExec("create table t_range_cols(a int) partition by range columns(a) (partition p0 values less than (10), partition p1 values less than (maxvalue))")
931+
tk.MustExec("insert into t_range_cols values (1), (11), (null)")
932+
tk.MustQuery("select /* issue:65991 */ a from t_range_cols where 1 <=> a").Check(testkit.Rows("1"))
933+
tk.MustQuery("select /* issue:65991 */ a from t_range_cols where null <=> a").Check(testkit.Rows("<nil>"))
934+
})
921935
}
922936

923937
func TestOnlyFullGroupCantFeelUnaryConstant(t *testing.T) {

pkg/planner/core/rule/rule_partition_processor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,9 @@ func opposite(op string) string {
16911691
return ast.GE
16921692
case ast.GE:
16931693
return ast.LE
1694+
case ast.NullEQ:
1695+
// Null-safe equality is symmetric, so flipping operands keeps the same operator.
1696+
return ast.NullEQ
16941697
}
16951698
panic("invalid input parameter" + op)
16961699
}

0 commit comments

Comments
 (0)