Skip to content

Commit

Permalink
planner: make sure limit outputs no more columns than its child (#25345
Browse files Browse the repository at this point in the history
…) (#25517)
  • Loading branch information
ti-srebot authored Jun 21, 2021
1 parent 32cd4a9 commit c8a80a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3229,6 +3229,15 @@ func (s *testIntegrationSuite) TestIssue24281(c *C) {
"UNION select 1 as v1, 2 as v2")
}

func (s *testIntegrationSuite) TestLimitWindowColPrune(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")
tk.MustExec("insert into t values(1)")
tk.MustQuery("select count(a) f1, row_number() over (order by count(a)) as f2 from t limit 1").Check(testkit.Rows("1 1"))
}

func (s *testIntegrationSerialSuite) TestMergeContinuousSelections(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
10 changes: 8 additions & 2 deletions planner/core/rule_column_pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,14 @@ func (p *LogicalLimit) PruneColumns(parentUsedCols []*expression.Column) error {
return nil
}

p.inlineProjection(parentUsedCols)
return p.children[0].PruneColumns(parentUsedCols)
savedUsedCols := make([]*expression.Column, len(parentUsedCols))
copy(savedUsedCols, parentUsedCols)
if err := p.children[0].PruneColumns(parentUsedCols); err != nil {
return err
}
p.schema = nil
p.inlineProjection(savedUsedCols)
return nil
}

func (*columnPruner) name() string {
Expand Down

0 comments on commit c8a80a3

Please sign in to comment.