diff --git a/executor/partition_table_test.go b/executor/partition_table_test.go index b00b04f69620b..85b096c28ff0d 100644 --- a/executor/partition_table_test.go +++ b/executor/partition_table_test.go @@ -728,6 +728,17 @@ func TestOrderByAndLimit(t *testing.T) { } } +func TestOrderByOnUnsignedPk(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table tunsigned_hash(a bigint unsigned primary key) partition by hash(a) partitions 6") + tk.MustExec("insert into tunsigned_hash values(25), (9279808998424041135)") + tk.MustQuery("select min(a) from tunsigned_hash").Check(testkit.Rows("25")) + tk.MustQuery("select max(a) from tunsigned_hash").Check(testkit.Rows("9279808998424041135")) +} + func TestBatchGetandPointGetwithHashPartition(t *testing.T) { store := testkit.CreateMockStore(t) diff --git a/planner/core/task.go b/planner/core/task.go index d50daae83f21c..d68806c5ef1d8 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -1072,7 +1072,6 @@ func (p *PhysicalTopN) pushTopNDownToDynamicPartition(copTsk *copTask) (task, bo if !propMatched { return nil, false } - idxScan.Desc = isDesc childProfile := copTsk.plan().statsInfo() newCount := p.Offset + p.Count @@ -1100,6 +1099,8 @@ func (p *PhysicalTopN) pushTopNDownToDynamicPartition(copTsk *copTask) (task, bo } } tblScan.Desc = isDesc + // SplitRangesAcrossInt64Boundary needs the KeepOrder flag. See that func and the struct tableResultHandler for more details. + tblScan.KeepOrder = true childProfile := copTsk.plan().statsInfo() newCount := p.Offset + p.Count stats := deriveLimitStats(childProfile, float64(newCount))