Skip to content

Commit

Permalink
planner: incorrect query result using ISNULL
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Jul 23, 2024
1 parent c784592 commit 3f5b05d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
6 changes: 6 additions & 0 deletions pkg/planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3f5b05d

Please sign in to comment.