From 15921e342c6701d836264367f5e2dfdb982bfce1 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 30 Oct 2023 17:54:14 +0800 Subject: [PATCH] fixup --- pkg/planner/core/integration_test.go | 9 +++++++++ pkg/planner/core/rule_result_reorder.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/pkg/planner/core/integration_test.go b/pkg/planner/core/integration_test.go index 1a6688649ecea..2812f778e25d9 100644 --- a/pkg/planner/core/integration_test.go +++ b/pkg/planner/core/integration_test.go @@ -2529,6 +2529,15 @@ func TestIssue46298(t *testing.T) { tk.MustQuery("select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from test.first_range;") } +func TestIssue45044(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec(`use test`) + tk.MustExec(`set tidb_enable_ordered_result_mode = on`) + tk.MustExec(`create table t1(c1 int)`) + tk.MustQuery(`select * from t1 group by t1.c1 having count(1) > 1 order by count(1) limit 10`).Check(testkit.Rows()) // no error +} + // https://github.com/pingcap/tidb/issues/41458 func TestIssue41458(t *testing.T) { store := testkit.CreateMockStore(t) diff --git a/pkg/planner/core/rule_result_reorder.go b/pkg/planner/core/rule_result_reorder.go index 96e8137389b0e..ed340f831ed60 100644 --- a/pkg/planner/core/rule_result_reorder.go +++ b/pkg/planner/core/rule_result_reorder.go @@ -107,6 +107,9 @@ func (rs *resultReorder) extractHandleCol(lp LogicalPlan) *expression.Column { switch x := lp.(type) { case *LogicalSelection, *LogicalLimit: handleCol := rs.extractHandleCol(lp.Children()[0]) + if handleCol == nil { + return nil // fail to extract handle column from the child, just return nil. + } if x.Schema().Contains(handleCol) { // some Projection Operator might be inlined, so check the column again here return handleCol