Skip to content

Commit

Permalink
elegant fix drop view panic
Browse files Browse the repository at this point in the history
  • Loading branch information
tianjiqx committed Oct 16, 2018
1 parent 4c1615d commit 81cf95f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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 78333
{
sql: "drop view if exists v",
ans: map[int][]string{
1: {},
},
},
}
for _, tt := range tests {
comment := Commentf("for %s", tt.sql)
Expand Down
5 changes: 3 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ func (b *PlanBuilder) buildDo(v *ast.DoStmt) (Plan, error) {
RetType: expr.GetType(),
})
}
//make dual schema if not
var _ = dual.Schema()
if dual.schema == nil {
dual.schema = expression.NewSchema()
}
p.SetChildren(dual)
p.self = p
p.SetSchema(schema)
Expand Down
3 changes: 0 additions & 3 deletions planner/core/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ func (s *testValidatorSuite) TestValidator(c *C) {
{"select * from ( select 1 ) a, (select 2) b;", true, nil},
{"select * from (select * from ( select 1 ) a join (select 2) b) b join (select 3) a;", false, nil},
{"select * from (select 1 ) a , (select 2) b, (select * from (select 3) a join (select 4) b) c;", false, nil},

//issue 7833
{"drop view if exists v;", true, nil},
}

store, dom, err := newStoreWithBootstrap()
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 81cf95f

Please sign in to comment.