Skip to content

Commit fcb7ddc

Browse files
winorosti-chi-bot
authored andcommitted
planner, executor: split the range for unsigned pk of partition table when limit is used (pingcap#40313)
close pingcap#40309
1 parent 47b5ee4 commit fcb7ddc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

executor/partition_table_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,17 @@ func TestOrderByandLimit(t *testing.T) {
637637
}
638638
}
639639

640+
func TestOrderByOnUnsignedPk(t *testing.T) {
641+
store := testkit.CreateMockStore(t)
642+
643+
tk := testkit.NewTestKit(t, store)
644+
tk.MustExec("use test")
645+
tk.MustExec("create table tunsigned_hash(a bigint unsigned primary key) partition by hash(a) partitions 6")
646+
tk.MustExec("insert into tunsigned_hash values(25), (9279808998424041135)")
647+
tk.MustQuery("select min(a) from tunsigned_hash").Check(testkit.Rows("25"))
648+
tk.MustQuery("select max(a) from tunsigned_hash").Check(testkit.Rows("9279808998424041135"))
649+
}
650+
640651
func TestBatchGetandPointGetwithHashPartition(t *testing.T) {
641652
store := testkit.CreateMockStore(t)
642653

planner/core/task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,6 @@ func (p *PhysicalTopN) pushTopNDownToDynamicPartition(copTsk *copTask) (task, bo
10751075
if !propMatched {
10761076
return nil, false
10771077
}
1078-
10791078
idxScan.Desc = isDesc
10801079
childProfile := copTsk.plan().statsInfo()
10811080
newCount := p.Offset + p.Count
@@ -1103,6 +1102,8 @@ func (p *PhysicalTopN) pushTopNDownToDynamicPartition(copTsk *copTask) (task, bo
11031102
}
11041103
}
11051104
tblScan.Desc = isDesc
1105+
// SplitRangesAcrossInt64Boundary needs the KeepOrder flag. See that func and the struct tableResultHandler for more details.
1106+
tblScan.KeepOrder = true
11061107
childProfile := copTsk.plan().statsInfo()
11071108
newCount := p.Offset + p.Count
11081109
stats := deriveLimitStats(childProfile, float64(newCount))

0 commit comments

Comments
 (0)