From 81cf95f7b1a27714257f34eaa8de761473d7768f Mon Sep 17 00:00:00 2001 From: tianjiqx Date: Tue, 16 Oct 2018 14:47:46 +0800 Subject: [PATCH] elegant fix drop view panic --- planner/core/logical_plan_test.go | 7 +++++++ planner/core/planbuilder.go | 5 +++-- planner/core/preprocess_test.go | 3 --- planner/core/rule_column_pruning.go | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 2b4a4c9687273..6e7d2acf7ca25 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 78333 + { + 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 28f7b25dbf1fa..56dc38ef291a9 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -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) diff --git a/planner/core/preprocess_test.go b/planner/core/preprocess_test.go index 15b7bd0d8240e..17deb8a09d48b 100644 --- a/planner/core/preprocess_test.go +++ b/planner/core/preprocess_test.go @@ -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() 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:]...)