Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/partitiontest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 5,
shard_count = 6,
deps = [
"//testkit",
"@com_github_pingcap_failpoint//:failpoint",
Expand Down
11 changes: 11 additions & 0 deletions executor/partitiontest/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,14 @@ func TestPartitionOnMissing(t *testing.T) {
" └─TableReader(Probe) 4.00 root partition:all data:TableRangeScan",
" └─TableRangeScan 4.00 cop[tikv] table:tt1 range: decided by [onmissing.tt2.listid], keep order:false"))
}

func TestIssue45757(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("create table t(id bigint, datecode bigint, c int, index idx(id, datecode)) partition by range(datecode) (partition p0 values less than (20230501), partition p1 values less than (20230601), partition p2 values less than (20230701))")
tk.MustExec("insert into t values (111111111111111, 20230403, 0), (111111111111111, 20230503, 1), (111111111111111, 20230603, 2)")
tk.MustExec("set tidb_partition_prune_mode='static'")
tk.MustQuery("select * from t use index (idx) where id = 111111111111111 and datecode between 20230420 and 20230620 order by datecode limit 2").Check(testkit.Rows("111111111111111 20230503 1", "111111111111111 20230603 2"))
}
13 changes: 11 additions & 2 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,10 +1302,19 @@ func (p *PhysicalTopN) pushPartialTopNDownToCop(copTsk *copTask) (task, bool) {
Count: p.Count,
}
extraInfo, extraCol, hasExtraCol := tryGetPkExtraColumn(p.ctx.GetSessionVars(), tblInfo)
// TODO: sometimes it will add a duplicate `_tidb_rowid` column in ts.schema()
if hasExtraCol {
idxLookup.ExtraHandleCol = extraCol
ts := idxLookup.TablePlans[0].(*PhysicalTableScan)

if !p.SCtx().GetSessionVars().IsDynamicPartitionPruneEnabled() {
extraProj := PhysicalProjection{
Exprs: expression.Column2Exprs(ts.schema.Clone().Columns),
}.Init(p.SCtx(), p.statsInfo(), p.blockOffset, nil)
extraProj.SetSchema(ts.schema.Clone())
extraProj.SetChildren(rootTask.p)
rootTask.p = extraProj
}

idxLookup.ExtraHandleCol = extraCol
ts.Columns = append(ts.Columns, extraInfo)
ts.schema.Append(extraCol)
ts.HandleIdx = []int{len(ts.Columns) - 1}
Expand Down