planner: fix some select condition do not filter by tiflash (#14502)
This commit is contained in:
committed by
pingcap-github-bot
parent
6e648401e4
commit
cd9c65aad2
@ -1048,6 +1048,11 @@ func (ds *DataSource) convertToTableScan(prop *property.PhysicalProperty, candid
|
||||
|
||||
func (ts *PhysicalTableScan) addPushedDownSelection(copTask *copTask, stats *property.StatsInfo) {
|
||||
ts.filterCondition, copTask.rootTaskConds = splitSelCondsWithVirtualColumn(ts.filterCondition)
|
||||
if ts.StoreType == kv.TiFlash {
|
||||
var newRootConds []expression.Expression
|
||||
ts.filterCondition, newRootConds = expression.CheckExprPushFlash(ts.filterCondition)
|
||||
copTask.rootTaskConds = append(copTask.rootTaskConds, newRootConds...)
|
||||
}
|
||||
|
||||
// Add filter condition to table plan now.
|
||||
sessVars := ts.ctx.GetSessionVars()
|
||||
|
||||
@ -16,6 +16,7 @@ package core_test
|
||||
import (
|
||||
. "github.com/pingcap/check"
|
||||
"github.com/pingcap/errors"
|
||||
"github.com/pingcap/parser/model"
|
||||
"github.com/pingcap/parser/mysql"
|
||||
"github.com/pingcap/tidb/domain"
|
||||
"github.com/pingcap/tidb/kv"
|
||||
@ -265,6 +266,43 @@ func (s *testIntegrationSuite) TestNoneAccessPathsFoundByIsolationRead(c *C) {
|
||||
c.Assert(err.Error(), Equals, "[planner:1815]Internal : Can not find access path matching 'tidb_isolation_read_engines'(value: 'tiflash'). Available values are 'tikv'.")
|
||||
}
|
||||
|
||||
func (s *testIntegrationSuite) TestSelPushDownTiFlash(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 primary key, b varchar(20))")
|
||||
|
||||
// Create virtual tiflash replica info.
|
||||
dom := domain.GetDomain(tk.Se)
|
||||
is := dom.InfoSchema()
|
||||
db, exists := is.SchemaByName(model.NewCIStr("test"))
|
||||
c.Assert(exists, IsTrue)
|
||||
for _, tblInfo := range db.Tables {
|
||||
if tblInfo.Name.L == "t" {
|
||||
tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{
|
||||
Count: 1,
|
||||
Available: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tk.MustExec("set @@session.tidb_isolation_read_engines = 'tiflash'")
|
||||
|
||||
// All conditions should push tiflash.
|
||||
tk.MustQuery(`explain select * from t where t.a > 1 and t.b = "flash" or t.a + 3 * t.a = 5`).Check(testkit.Rows(
|
||||
"TableReader_7 8000.00 root data:Selection_6",
|
||||
"└─Selection_6 8000.00 cop[tiflash] or(and(gt(test.t.a, 1), eq(test.t.b, \"flash\")), eq(plus(test.t.a, mul(3, test.t.a)), 5))",
|
||||
" └─TableScan_5 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo",
|
||||
))
|
||||
|
||||
// Part of conditions should push tiflash.
|
||||
tk.MustQuery(`explain select * from t where cast(t.a as float) + 3 = 5.1`).Check(testkit.Rows(
|
||||
"Selection_7 10000.00 root eq(plus(cast(test.t.a), 3), 5.1)",
|
||||
"└─TableReader_6 10000.00 root data:TableScan_5",
|
||||
" └─TableScan_5 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo",
|
||||
))
|
||||
}
|
||||
|
||||
func (s *testIntegrationSuite) TestPartitionTableStats(c *C) {
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
|
||||
|
||||
@ -99,10 +99,6 @@ func (p *LogicalUnionScan) PredicatePushDown(predicates []expression.Expression)
|
||||
// PredicatePushDown implements LogicalPlan PredicatePushDown interface.
|
||||
func (ds *DataSource) PredicatePushDown(predicates []expression.Expression) ([]expression.Expression, LogicalPlan) {
|
||||
ds.allConds = predicates
|
||||
if ds.preferStoreType&preferTiFlash != 0 {
|
||||
ds.pushedDownConds, predicates = expression.CheckExprPushFlash(predicates)
|
||||
return predicates, ds
|
||||
}
|
||||
_, ds.pushedDownConds, predicates = expression.ExpressionsToPB(ds.ctx.GetSessionVars().StmtCtx, predicates, ds.ctx.GetClient())
|
||||
return predicates, ds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user