From 25edc0f22f3502b28be8c2c3019ac3641a83ddfb Mon Sep 17 00:00:00 2001 From: dongjunduo Date: Sat, 3 Sep 2022 23:51:46 +0800 Subject: [PATCH] expression: push down bin function to tiflash --- expression/expr_to_pb_test.go | 5 +++++ expression/expression.go | 2 +- planner/core/integration_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go index 03d80a14d018f..6e686c560ce14 100644 --- a/expression/expr_to_pb_test.go +++ b/expression/expr_to_pb_test.go @@ -1173,6 +1173,11 @@ func TestExprPushDownToFlash(t *testing.T) { require.NoError(t, err) exprs = append(exprs, function) + // Bin + function, err = NewFunction(mock.NewContext(), ast.Bin, types.NewFieldType(mysql.TypeString), intColumn) + require.NoError(t, err) + exprs = append(exprs, function) + // Elt function, err = NewFunction(mock.NewContext(), ast.Elt, types.NewFieldType(mysql.TypeString), intColumn, stringColumn) require.NoError(t, err) diff --git a/expression/expression.go b/expression/expression.go index 05a5b0a09d294..a69c842a594a0 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -1161,7 +1161,7 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool { } case ast.IsTruthWithNull, ast.IsTruthWithoutNull, ast.IsFalsity: return true - case ast.Hex: + case ast.Hex, ast.Bin: return true case ast.GetFormat: return true diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 075972aa23a01..17b8c7b25f4db 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -7060,6 +7060,31 @@ func TestHexIntOrStrPushDownToTiFlash(t *testing.T) { tk.MustQuery("explain select hex(b) from t;").CheckAt([]int{0, 2, 4}, rows) } +func TestBinPushDownToTiFlash(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + tk := testkit.NewTestKit(t, store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int);") + tk.MustExec("insert into t values(1);") + tk.MustExec("set @@tidb_allow_mpp=1; set @@tidb_enforce_mpp=1;") + tk.MustExec("set @@tidb_isolation_read_engines = 'tiflash'") + + tbl, err := dom.InfoSchema().TableByName(model.CIStr{O: "test", L: "test"}, model.CIStr{O: "t", L: "t"}) + require.NoError(t, err) + // Set the hacked TiFlash replica for explain tests. + tbl.Meta().TiFlashReplica = &model.TiFlashReplicaInfo{Count: 1, Available: true} + + rows := [][]interface{}{ + {"TableReader_9", "root", "data:ExchangeSender_8"}, + {"└─ExchangeSender_8", "mpp[tiflash]", "ExchangeType: PassThrough"}, + {" └─Projection_4", "mpp[tiflash]", "bin(test.t.a)->Column#3"}, + {" └─TableFullScan_7", "mpp[tiflash]", "keep order:false, stats:pseudo"}, + } + tk.MustQuery("explain select bin(a) from t;").CheckAt([]int{0, 2, 4}, rows) +} + func TestEltPushDownToTiFlash(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t) tk := testkit.NewTestKit(t, store)