Skip to content

Commit

Permalink
planner: check nil pointer in rule_result_reorder to avoid panic (#48100
Browse files Browse the repository at this point in the history
) (#48117)

close #45044
  • Loading branch information
ti-chi-bot authored Nov 8, 2023
1 parent 62ec8a7 commit 2a5262b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

func TestIssue46177(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
3 changes: 3 additions & 0 deletions pkg/planner/core/rule_result_reorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a5262b

Please sign in to comment.