From 5062e0dc8e7de98b4a5f8683b9864c686b7da66d Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Thu, 23 Dec 2021 14:44:19 +0800 Subject: [PATCH 1/3] fix --- planner/core/find_best_task.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index 166d3adc298b3..242985e0cc909 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -1409,15 +1409,15 @@ func (is *PhysicalIndexScan) addPushedDownSelection(copTask *copTask, p *DataSou } // SplitSelCondsWithVirtualColumn filter the select conditions which contain virtual column -func SplitSelCondsWithVirtualColumn(conds []expression.Expression) ([]expression.Expression, []expression.Expression) { - var filterConds []expression.Expression - for i := len(conds) - 1; i >= 0; i-- { +func SplitSelCondsWithVirtualColumn(conds []expression.Expression) (withoutVirt []expression.Expression, withVirt []expression.Expression) { + for i := range conds { if expression.ContainVirtualColumn(conds[i : i+1]) { - filterConds = append(filterConds, conds[i]) - conds = append(conds[:i], conds[i+1:]...) + withVirt = append(withVirt, conds[i]) + } else { + withoutVirt = append(withoutVirt, conds[i]) } } - return conds, filterConds + return withoutVirt, withVirt } func matchIndicesProp(idxCols []*expression.Column, colLens []int, propItems []property.SortItem) bool { From 6a76ccea0b92260f41ad693130387873b5511ba9 Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Thu, 23 Dec 2021 16:43:42 +0800 Subject: [PATCH 2/3] add test --- planner/core/physical_plan_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index 1b3d13c02cc03..613a10c76bac5 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -2016,3 +2016,26 @@ func (s *testPlanSuite) TestIssue28316(c *C) { tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...)) } } + +func (s *testPlanSuite) TestIssue30965(c *C) { + store, dom, err := newStoreWithBootstrap() + c.Assert(err, IsNil) + defer func() { + dom.Close() + store.Close() + }() + tk := testkit.NewTestKit(c, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t30965") + tk.MustExec("CREATE TABLE `t30965` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, `d` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL, KEY `ib` (`b`));") + tk.MustExec("insert into t30965 (a,b,c) value(3,4,5);") + tk.MustQuery("select count(*) from t30965 where d = 2 and b = 4 and a = 3 and c = 5;").Check(testkit.Rows("0")) + tk.MustQuery("explain select count(*) from t30965 where d = 2 and b = 4 and a = 3 and c = 5;").Check( + testkit.Rows( + "StreamAgg_10 1.00 root funcs:count(1)->Column#6", + "└─Selection_28 0.00 root eq(test.t30965.d, 2)", + " └─IndexLookUp_27 0.00 root ", + " ├─IndexRangeScan_24(Build) 10.00 cop[tikv] table:t30965, index:ib(b) range:[4,4], keep order:false, stats:pseudo", + " └─Selection_26(Probe) 0.00 cop[tikv] eq(test.t30965.a, 3), eq(test.t30965.c, 5)", + " └─TableRowIDScan_25 10.00 cop[tikv] table:t30965 keep order:false, stats:pseudo")) +} From 7eb3bcf7e14b4776d5b6ad10447a975916a1fbaa Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Thu, 23 Dec 2021 18:56:36 +0800 Subject: [PATCH 3/3] use brief explain --- planner/core/physical_plan_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index 613a10c76bac5..bc145e4a14ad7 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -2030,12 +2030,12 @@ func (s *testPlanSuite) TestIssue30965(c *C) { tk.MustExec("CREATE TABLE `t30965` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, `d` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL, KEY `ib` (`b`));") tk.MustExec("insert into t30965 (a,b,c) value(3,4,5);") tk.MustQuery("select count(*) from t30965 where d = 2 and b = 4 and a = 3 and c = 5;").Check(testkit.Rows("0")) - tk.MustQuery("explain select count(*) from t30965 where d = 2 and b = 4 and a = 3 and c = 5;").Check( + tk.MustQuery("explain format = 'brief' select count(*) from t30965 where d = 2 and b = 4 and a = 3 and c = 5;").Check( testkit.Rows( - "StreamAgg_10 1.00 root funcs:count(1)->Column#6", - "└─Selection_28 0.00 root eq(test.t30965.d, 2)", - " └─IndexLookUp_27 0.00 root ", - " ├─IndexRangeScan_24(Build) 10.00 cop[tikv] table:t30965, index:ib(b) range:[4,4], keep order:false, stats:pseudo", - " └─Selection_26(Probe) 0.00 cop[tikv] eq(test.t30965.a, 3), eq(test.t30965.c, 5)", - " └─TableRowIDScan_25 10.00 cop[tikv] table:t30965 keep order:false, stats:pseudo")) + "StreamAgg 1.00 root funcs:count(1)->Column#6", + "└─Selection 0.00 root eq(test.t30965.d, 2)", + " └─IndexLookUp 0.00 root ", + " ├─IndexRangeScan(Build) 10.00 cop[tikv] table:t30965, index:ib(b) range:[4,4], keep order:false, stats:pseudo", + " └─Selection(Probe) 0.00 cop[tikv] eq(test.t30965.a, 3), eq(test.t30965.c, 5)", + " └─TableRowIDScan 10.00 cop[tikv] table:t30965 keep order:false, stats:pseudo")) }