Skip to content

Commit

Permalink
expr: add switch to control pushing bit column down (#32795)
Browse files Browse the repository at this point in the history
* add switch

Signed-off-by: yisaer <disxiaofei@163.com>

* address the comment

Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer authored Mar 4, 2022
1 parent 493eb45 commit 5464eec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions expression/expr_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/mysql"
ast "github.com/pingcap/tidb/parser/types"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
Expand Down Expand Up @@ -182,6 +183,10 @@ func (pc PbConverter) columnToPBExpr(column *Column) *tipb.Expr {
return nil
}
switch column.GetType().Tp {
case mysql.TypeBit:
if !IsPushDownEnabled(ast.TypeStr(column.GetType().Tp), kv.TiKV) {
return nil
}
case mysql.TypeSet, mysql.TypeGeometry, mysql.TypeUnspecified:
return nil
case mysql.TypeEnum:
Expand Down
22 changes: 22 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,28 @@ func TestBitColumnPushDown(t *testing.T) {
sql = "select a from t1 where cast(a as char)='A'"
tk.MustQuery(sql).Check(testkit.Rows("A"))
tk.MustQuery(fmt.Sprintf("explain analyze %s", sql)).CheckAt([]int{0, 3, 6}, rows)

tk.MustExec("insert into mysql.expr_pushdown_blacklist values('bit', 'tikv','');")
tk.MustExec("admin reload expr_pushdown_blacklist;")
rows = [][]interface{}{
{"Selection_5", "root", `eq(cast(test.t1.a, var_string(1)), "A")`},
{"└─TableReader_7", "root", "data:TableFullScan_6"},
{" └─TableFullScan_6", "cop[tikv]", "keep order:false, stats:pseudo"},
}
sql = "select a from t1 where cast(a as char)='A'"
tk.MustQuery(sql).Check(testkit.Rows("A"))
tk.MustQuery(fmt.Sprintf("explain analyze %s", sql)).CheckAt([]int{0, 3, 6}, rows)

tk.MustExec("delete from mysql.expr_pushdown_blacklist where name='bit'")
tk.MustExec("admin reload expr_pushdown_blacklist;")
sql = "select a from t1 where ascii(a)=65"
tk.MustQuery(sql).Check(testkit.Rows("A"))
rows = [][]interface{}{
{"TableReader_7", "root", "data:Selection_6"},
{"└─Selection_6", "cop[tikv]", "eq(ascii(cast(test.t1.a, var_string(1))), 65)"},
{" └─TableFullScan_5", "cop[tikv]", "keep order:false, stats:pseudo"},
}
tk.MustQuery(fmt.Sprintf("explain analyze %s", sql)).CheckAt([]int{0, 3, 6}, rows)
}

func TestScalarFunctionPushDown(t *testing.T) {
Expand Down

0 comments on commit 5464eec

Please sign in to comment.