Skip to content

Commit

Permalink
cherry pick pingcap#30966 to release-5.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
time-and-fate authored and ti-srebot committed Dec 23, 2021
1 parent 181b4c2 commit 76fd589
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
12 changes: 6 additions & 6 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,15 +1233,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 {
Expand Down
85 changes: 85 additions & 0 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1745,3 +1745,88 @@ func (s *testPlanSuite) TestPossibleProperties(c *C) {
"1 58.0000",
))
}
<<<<<<< HEAD
=======

func (s *testPlanSuite) TestSelectionPartialPushDown(c *C) {
var (
input []string
output []struct {
SQL string
Plan []string
}
)
s.testData.GetTestCases(c, &input, &output)
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 t1, t2")
tk.MustExec("create table t1(a int, b int as (a+1) virtual)")
tk.MustExec("create table t2(a int, b int as (a+1) virtual, c int, key idx_a(a))")

for i, ts := range input {
s.testData.OnRecord(func() {
output[i].SQL = ts
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows())
})
tk.MustQuery("explain format='brief' " + ts).Check(testkit.Rows(output[i].Plan...))
}
}

func (s *testPlanSuite) TestIssue28316(c *C) {
var (
input []string
output []struct {
SQL string
Plan []string
}
)
s.testData.GetTestCases(c, &input, &output)
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 t")
tk.MustExec("create table t(a int)")

for i, ts := range input {
s.testData.OnRecord(func() {
output[i].SQL = ts
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery("explain format='brief'" + ts).Rows())
})
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 format = 'brief' select count(*) from t30965 where d = 2 and b = 4 and a = 3 and c = 5;").Check(
testkit.Rows(
"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"))
}
>>>>>>> e24493f41... planner: fix `AccessPath.TableFilters` got modified unexpectedly (#30966)

0 comments on commit 76fd589

Please sign in to comment.