Skip to content

Commit

Permalink
planner: fix bug when pruning columns for TableDual (#11054) (#11247)
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros authored and zz-jason committed Jul 15, 2019
1 parent 36f9978 commit c705020
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,9 @@ func (s *testSuite) TestTableDual(c *C) {
result.Check(testkit.Rows("1"))
result = tk.MustQuery("Select 1 from dual where 1")
result.Check(testkit.Rows("1"))

tk.MustExec("create table t(a int primary key)")
tk.MustQuery("select t1.* from t t1, t t2 where t1.a=t2.a and 1=0").Check(testkit.Rows())
}

func (s *testSuite) TestTableScan(c *C) {
Expand Down
9 changes: 8 additions & 1 deletion planner/core/rule_column_pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,15 @@ func (p *LogicalTableDual) PruneColumns(parentUsedCols []*expression.Column) err
}
}
for k, cols := range p.schema.TblID2Handle {
if p.schema.ColumnIndex(cols[0]) == -1 {
for i := len(cols) - 1; i >= 0; i-- {
if p.schema.ColumnIndex(cols[i]) == -1 {
cols = append(cols[:i], cols[i+1:]...)
}
}
if len(cols) == 0 {
delete(p.schema.TblID2Handle, k)
} else {
p.schema.TblID2Handle[k] = cols
}
}
return nil
Expand Down

0 comments on commit c705020

Please sign in to comment.