diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 7efc16274c792..7f115234ff213 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -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) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index f54675f142d74..56dc38ef291a9 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -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) diff --git a/planner/core/rule_column_pruning.go b/planner/core/rule_column_pruning.go index 933c93b206900..1bb66185a0973 100644 --- a/planner/core/rule_column_pruning.go +++ b/planner/core/rule_column_pruning.go @@ -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:]...)