diff --git a/pkg/planner/core/issuetest/planner_issue_test.go b/pkg/planner/core/issuetest/planner_issue_test.go index 9c1839b8887929..091661cd3c21f2 100644 --- a/pkg/planner/core/issuetest/planner_issue_test.go +++ b/pkg/planner/core/issuetest/planner_issue_test.go @@ -86,3 +86,25 @@ func Test53726(t *testing.T) { " └─TableReader_11 2.00 root data:TableFullScan_10", " └─TableFullScan_10 2.00 cop[tikv] table:t7 keep order:false")) } + +func TestIssue54803(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(` + CREATE TABLE t1db47fc1 ( + col_67 time NOT NULL DEFAULT '16:58:45', + col_68 tinyint(3) unsigned DEFAULT NULL, + col_69 bit(6) NOT NULL DEFAULT b'11110', + col_72 double NOT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + PARTITION BY HASH (col_68) PARTITIONS 5; + `) + tk.MustQuery(`EXPLAIN SELECT TRIM(t1db47fc1.col_68) AS r0 + FROM t1db47fc1 + WHERE ISNULL(t1db47fc1.col_68) + GROUP BY t1db47fc1.col_68 + HAVING ISNULL(t1db47fc1.col_68) OR t1db47fc1.col_68 IN (62, 200, 196, 99) + LIMIT 106149535; + `).Check(testkit.Rows()) +} diff --git a/pkg/planner/core/rule_partition_processor.go b/pkg/planner/core/rule_partition_processor.go index 582bce9414f60e..7c3549fd29edfc 100644 --- a/pkg/planner/core/rule_partition_processor.go +++ b/pkg/planner/core/rule_partition_processor.go @@ -156,10 +156,16 @@ func (s *partitionProcessor) getUsedHashPartitions(ctx base.PlanContext, return nil, err } partCols, colLen := getPartColumnsForHashPartition(hashExpr) + if !ctx.GetSessionVars().InRestrictedSQL { + fmt.Println("here") + } detachedResult, err := ranger.DetachCondAndBuildRangeForPartition(ctx.GetRangerCtx(), conds, partCols, colLen, ctx.GetSessionVars().RangeMaxSize) if err != nil { return nil, err } + if !ctx.GetSessionVars().InRestrictedSQL { + fmt.Println("here") + } ranges := detachedResult.Ranges used := make([]int, 0, len(ranges)) tc := ctx.GetSessionVars().StmtCtx.TypeCtx()