Skip to content

Commit

Permalink
planner/core: fix partition pruning for IN multiple values (#37511)
Browse files Browse the repository at this point in the history
close #37508
  • Loading branch information
tiancaiamao authored Sep 22, 2022
1 parent 11a86a2 commit 28b6ca1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 18 additions & 0 deletions planner/core/integration_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,24 @@ func TestIssue27532(t *testing.T) {
tk.MustExec(`drop table t2`)
}

func TestIssue37508(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'")
tk.MustQuery("select @@tidb_partition_prune_mode").Check(testkit.Rows("dynamic"))
tk.MustExec(`create table t1 (id int, c date) partition by range (to_days(c))
(partition p0 values less than (to_days('2022-01-11')),
partition p1 values less than (to_days('2022-02-11')),
partition p2 values less than (to_days('2022-03-11')));`)
tk.MustExec("analyze table t1")

tk.MustPartition("select * from t1 where c in ('2022-01-23', '2022-01-22');", "p1").Sort().Check(testkit.Rows())
tk.MustPartition("select * from t1 where c in (NULL, '2022-01-23');", "p0,p1").Sort().Check(testkit.Rows())
tk.MustExec(`drop table t1`)
}

func TestRangeColumnsMultiColumn(t *testing.T) {
store := testkit.CreateMockStore(t)

Expand Down
6 changes: 1 addition & 5 deletions planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,13 +1227,9 @@ func partitionRangeForInExpr(sctx sessionctx.Context, args []expression.Expressi
if !ok {
return pruner.fullRange()
}
switch constExpr.Value.Kind() {
case types.KindInt64, types.KindUint64:
case types.KindNull:
if constExpr.Value.Kind() == types.KindNull {
result = append(result, partitionRange{0, 1})
continue
default:
return pruner.fullRange()
}

var val int64
Expand Down
3 changes: 2 additions & 1 deletion testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ func (tk *TestKit) MustPartition(sql string, partitions string, args ...interfac
if len(partitions) == 0 && strings.Contains(rs.rows[i][3], "partition:") {
ok = false
}
if len(partitions) != 0 && strings.Compare(rs.rows[i][3], "partition:"+partitions) == 0 {
// The data format is "table: t1, partition: p0,p1,p2"
if len(partitions) != 0 && strings.HasSuffix(rs.rows[i][3], "partition:"+partitions) {
ok = true
}
}
Expand Down

0 comments on commit 28b6ca1

Please sign in to comment.