From 10f0e2c3bcfb727f41f334e4558983fc8c2f98e5 Mon Sep 17 00:00:00 2001 From: Mingcong Han Date: Sun, 22 Mar 2020 20:46:00 +0800 Subject: [PATCH 1/3] cherry pick #15547 to release-3.1 Signed-off-by: sre-bot --- planner/core/integration_test.go | 39 ++++++++++++++++++++++++++++++++ planner/core/planbuilder.go | 10 ++++++++ 2 files changed, 49 insertions(+) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 2acbcdaba4e17..7c7a77db42b2d 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -479,3 +479,42 @@ func (s *testIntegrationSuite) TestTopNByConstFunc(c *C) { "a", )) } +<<<<<<< HEAD +======= + +func (s *testIntegrationSuite) TestSubqueryWithTopN(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b int)") + + var input []string + var output []struct { + SQL string + Plan []string + } + s.testData.GetTestCases(c, &input, &output) + for i, tt := range input { + s.testData.OnRecord(func() { + output[i].SQL = tt + output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) + }) + tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) + } +} + +func (s *testIntegrationSuite) TestIssue15546(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t, pt, vt") + tk.MustExec("create table t(a int, b int)") + tk.MustExec("insert into t values(1, 1)") + tk.MustExec("create table pt(a int primary key, b int) partition by range(a) (" + + "PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30))") + tk.MustExec("insert into pt values(1, 1), (11, 11), (21, 21)") + tk.MustExec("create definer='root'@'localhost' view vt(a, b) as select a, b from t") + tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1")) +} +>>>>>>> adaf8d2... planner: don't reset optFlag when build DataSource from View (#15547) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 3d4f3ead39b0b..2f1eb006a81a7 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -281,7 +281,17 @@ func NewPlanBuilder(sctx sessionctx.Context, is infoschema.InfoSchema, processor // Build builds the ast node to a Plan. func (b *PlanBuilder) Build(ctx context.Context, node ast.Node) (Plan, error) { +<<<<<<< HEAD b.optFlag = flagPrunColumns +======= + b.optFlag |= flagPrunColumns + defer func() { + // if there is something after flagPrunColumns, do flagPrunColumnsAgain + if b.optFlag&flagPrunColumns > 0 && b.optFlag-flagPrunColumns > flagPrunColumns { + b.optFlag |= flagPrunColumnsAgain + } + }() +>>>>>>> adaf8d2... planner: don't reset optFlag when build DataSource from View (#15547) switch x := node.(type) { case *ast.AdminStmt: return b.buildAdmin(ctx, x) From 76f8623b21504ff5dc228552e712434bcaa590fc Mon Sep 17 00:00:00 2001 From: Mingcong Han Date: Mon, 23 Mar 2020 13:23:43 +0800 Subject: [PATCH 2/3] resolve conflicts --- planner/core/integration_test.go | 25 ------------------------- planner/core/planbuilder.go | 10 ---------- 2 files changed, 35 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 7c7a77db42b2d..b42dc0415e59d 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -479,30 +479,6 @@ func (s *testIntegrationSuite) TestTopNByConstFunc(c *C) { "a", )) } -<<<<<<< HEAD -======= - -func (s *testIntegrationSuite) TestSubqueryWithTopN(c *C) { - tk := testkit.NewTestKit(c, s.store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b int)") - - var input []string - var output []struct { - SQL string - Plan []string - } - s.testData.GetTestCases(c, &input, &output) - for i, tt := range input { - s.testData.OnRecord(func() { - output[i].SQL = tt - output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) - }) - tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) - } -} func (s *testIntegrationSuite) TestIssue15546(c *C) { tk := testkit.NewTestKit(c, s.store) @@ -517,4 +493,3 @@ func (s *testIntegrationSuite) TestIssue15546(c *C) { tk.MustExec("create definer='root'@'localhost' view vt(a, b) as select a, b from t") tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1")) } ->>>>>>> adaf8d2... planner: don't reset optFlag when build DataSource from View (#15547) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 2f1eb006a81a7..46473480da94c 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -281,17 +281,7 @@ func NewPlanBuilder(sctx sessionctx.Context, is infoschema.InfoSchema, processor // Build builds the ast node to a Plan. func (b *PlanBuilder) Build(ctx context.Context, node ast.Node) (Plan, error) { -<<<<<<< HEAD - b.optFlag = flagPrunColumns -======= b.optFlag |= flagPrunColumns - defer func() { - // if there is something after flagPrunColumns, do flagPrunColumnsAgain - if b.optFlag&flagPrunColumns > 0 && b.optFlag-flagPrunColumns > flagPrunColumns { - b.optFlag |= flagPrunColumnsAgain - } - }() ->>>>>>> adaf8d2... planner: don't reset optFlag when build DataSource from View (#15547) switch x := node.(type) { case *ast.AdminStmt: return b.buildAdmin(ctx, x) From 55ae1a6de53ccbd64071cf1196f95733aec9c488 Mon Sep 17 00:00:00 2001 From: Mingcong Han Date: Mon, 23 Mar 2020 14:12:04 +0800 Subject: [PATCH 3/3] fix unit test --- planner/core/integration_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b42dc0415e59d..9123ab2b0c5eb 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -485,11 +485,11 @@ func (s *testIntegrationSuite) TestIssue15546(c *C) { tk.MustExec("use test") tk.MustExec("drop table if exists t, pt, vt") - tk.MustExec("create table t(a int, b int)") + tk.MustExec("create table t(a1 int, b1 int)") tk.MustExec("insert into t values(1, 1)") - tk.MustExec("create table pt(a int primary key, b int) partition by range(a) (" + + tk.MustExec("create table pt(a2 int primary key, b2 int) partition by range(a2) (" + "PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30))") tk.MustExec("insert into pt values(1, 1), (11, 11), (21, 21)") - tk.MustExec("create definer='root'@'localhost' view vt(a, b) as select a, b from t") - tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1")) + tk.MustExec("create definer='root'@'localhost' view vt(a1, b1) as select a1, b1 from t") + tk.MustQuery("select * from pt, vt where a2 = a1").Check(testkit.Rows("1 1 1 1")) }