Skip to content

Commit

Permalink
plan: fix panic caused by empty schema of LogicalTableDual (#7906)
Browse files Browse the repository at this point in the history
* fix drop view if exist error (#7833)
  • Loading branch information
tianjiqx authored and ngaut committed Oct 16, 2018
1 parent dcf3816 commit de6b582
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,13 @@ func (s *testPlanSuite) TestColumnPruning(c *C) {
3: {"a"},
},
},
//issue 7833
{
sql: "drop view if exists v",
ans: map[int][]string{
1: {},
},
},
}
for _, tt := range tests {
comment := Commentf("for %s", tt.sql)
Expand Down
3 changes: 3 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func (b *PlanBuilder) buildDo(v *ast.DoStmt) (Plan, error) {
RetType: expr.GetType(),
})
}
if dual.schema == nil {
dual.schema = expression.NewSchema()
}
p.SetChildren(dual)
p.self = p
p.SetSchema(schema)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/rule_column_pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (ds *DataSource) PruneColumns(parentUsedCols []*expression.Column) {

// PruneColumns implements LogicalPlan interface.
func (p *LogicalTableDual) PruneColumns(parentUsedCols []*expression.Column) {
used := getUsedList(parentUsedCols, p.schema)
used := getUsedList(parentUsedCols, p.Schema())
for i := len(used) - 1; i >= 0; i-- {
if !used[i] {
p.schema.Columns = append(p.schema.Columns[:i], p.schema.Columns[i+1:]...)
Expand Down

0 comments on commit de6b582

Please sign in to comment.