Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix bug when pruning columns for TableDual (#11054) #11247

Merged
merged 4 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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