From 3a15439d3c7bd4e1ac4ad357d52856fdefa95331 Mon Sep 17 00:00:00 2001 From: tianjiqx Date: Mon, 15 Oct 2018 23:05:57 +0800 Subject: [PATCH 1/4] fix drop view if exist error (#7833) --- planner/core/planbuilder.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index f54675f142d74..28f7b25dbf1fa 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -227,6 +227,8 @@ func (b *PlanBuilder) buildDo(v *ast.DoStmt) (Plan, error) { RetType: expr.GetType(), }) } + //make dual schema if not + var _ = dual.Schema() p.SetChildren(dual) p.self = p p.SetSchema(schema) From 4c1615d97ff03d5474c42f2077015e36dfb6e3e3 Mon Sep 17 00:00:00 2001 From: tianjiqx Date: Tue, 16 Oct 2018 02:32:09 +0800 Subject: [PATCH 2/4] add unit test for drop view --- planner/core/preprocess_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/planner/core/preprocess_test.go b/planner/core/preprocess_test.go index 17deb8a09d48b..15b7bd0d8240e 100644 --- a/planner/core/preprocess_test.go +++ b/planner/core/preprocess_test.go @@ -194,6 +194,9 @@ 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() From 81cf95f7b1a27714257f34eaa8de761473d7768f Mon Sep 17 00:00:00 2001 From: tianjiqx Date: Tue, 16 Oct 2018 14:47:46 +0800 Subject: [PATCH 3/4] 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:]...) From eb37f22cf8a53d0b10319e88a9e6b0398434a5e1 Mon Sep 17 00:00:00 2001 From: tianjiqx Date: Tue, 16 Oct 2018 14:55:06 +0800 Subject: [PATCH 4/4] fix issue number --- planner/core/logical_plan_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 6e7d2acf7ca25..1f66854f2bbb6 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -1224,7 +1224,7 @@ func (s *testPlanSuite) TestColumnPruning(c *C) { 3: {"a"}, }, }, - //issue 78333 + //issue 7833 { sql: "drop view if exists v", ans: map[int][]string{