Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: Add missing pbcode for functions InetAton/InetNtoa/Inet6Aton/Inet6Ntoa/IsIPv4/IsIPv4Compat/IsIPv4Mapped/IsIPv6. #26939

Merged
merged 12 commits into from
Aug 6, 2021
52 changes: 52 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,58 @@ func (s *testEvaluatorSuite) TestExprOnlyPushDownToFlash(c *C) {
c.Assert(len(remained), Equals, len(exprs))
}

func (s *testEvaluatorSuite) TestExprPushDownToTiKV(c *C) {
sc := new(stmtctx.StatementContext)
client := new(mock.Client)
dg := new(dataGen4Expr2PbTest)
exprs := make([]Expression, 0)

//jsonColumn := dg.genColumn(mysql.TypeJSON, 1)
//intColumn := dg.genColumn(mysql.TypeLonglong, 2)
//realColumn := dg.genColumn(mysql.TypeDouble, 3)
//decimalColumn := dg.genColumn(mysql.TypeNewDecimal, 4)
Comment on lines +1017 to +1020
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later will use

stringColumn := dg.genColumn(mysql.TypeString, 5)
//datetimeColumn := dg.genColumn(mysql.TypeDatetime, 6)
binaryStringColumn := dg.genColumn(mysql.TypeString, 7)
binaryStringColumn.RetType.Collate = charset.CollationBin

function, err := NewFunction(mock.NewContext(), ast.InetAton, types.NewFieldType(mysql.TypeString), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.InetNtoa, types.NewFieldType(mysql.TypeLonglong), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.Inet6Aton, types.NewFieldType(mysql.TypeString), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.Inet6Ntoa, types.NewFieldType(mysql.TypeLonglong), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.IsIPv4, types.NewFieldType(mysql.TypeString), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.IsIPv6, types.NewFieldType(mysql.TypeString), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.IsIPv4Compat, types.NewFieldType(mysql.TypeString), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

function, err = NewFunction(mock.NewContext(), ast.IsIPv4Mapped, types.NewFieldType(mysql.TypeString), stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

pushed, remained := PushDownExprs(sc, exprs, client, kv.TiKV)
c.Assert(len(pushed), Equals, 0)
c.Assert(len(remained), Equals, len(exprs))
}

func (s *testEvaluatorSuite) TestExprOnlyPushDownToTiKV(c *C) {
sc := new(stmtctx.StatementContext)
client := new(mock.Client)
Expand Down
13 changes: 6 additions & 7 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,15 +1161,14 @@ func init() {

func canScalarFuncPushDown(scalarFunc *ScalarFunction, pc PbConverter, storeType kv.StoreType) bool {
pbCode := scalarFunc.Function.PbCode()
if pbCode <= tipb.ScalarFuncSig_Unspecified {
failpoint.Inject("PanicIfPbCodeUnspecified", func() {
panic(errors.Errorf("unspecified PbCode: %T", scalarFunc.Function))
})
return false
}

// Check whether this function can be pushed.
if !canFuncBePushed(scalarFunc, storeType) {
if unspecified := pbCode <= tipb.ScalarFuncSig_Unspecified; unspecified || !canFuncBePushed(scalarFunc, storeType) {
if unspecified {
failpoint.Inject("PanicIfPbCodeUnspecified", func() {
panic(errors.Errorf("unspecified PbCode: %T", scalarFunc.Function))
})
}
if pc.sc.InExplainStmt {
storageName := storeType.Name()
if storeType == kv.UnSpecified {
Expand Down
1 change: 0 additions & 1 deletion planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,6 @@ func CheckAggCanPushCop(sctx sessionctx.Context, aggFuncs []*aggregation.AggFunc
}

if !ret && sc.InExplainStmt {
sctx.GetSessionVars().RaiseWarningWhenMPPEnforced("MPP mode may be blocked because " + reason)
storageName := storeType.Name()
if storeType == kv.UnSpecified {
storageName = "storage layer"
Expand Down
3 changes: 2 additions & 1 deletion planner/core/testdata/enforce_mpp_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"EXPLAIN SELECT count(*) from t group by b; -- 8. group by virtual column",
"EXPLAIN SELECT group_concat(a) from t; -- 9. agg func not supported",
"EXPLAIN SELECT count(a) from t group by md5(a); -- 10. scalar func not supported",
"EXPLAIN SELECT count(a) from t where c=1; -- 11. type not supported"
"EXPLAIN SELECT count(a) from t where c=1; -- 11. type not supported",
"EXPLAIN SELECT count(a) from t group by is_ipv4(a); -- 12. scalar func not supported (without pbcode)"
]
},
{
Expand Down
32 changes: 17 additions & 15 deletions planner/core/testdata/enforce_mpp_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,10 @@
" └─TableRowIDScan_41(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo"
],
"Warn": [
"MPP mode may be blocked because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"MPP mode may be blocked because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"MPP mode may be blocked because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"Aggregation can not be pushed to tikv because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"MPP mode may be blocked because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"MPP mode may be blocked because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now",
"Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now"
]
},
Expand All @@ -316,11 +311,8 @@
" └─TableFullScan_10 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
],
"Warn": [
"MPP mode may be blocked because groupByItems contain virtual columns, which is not supported now",
"Aggregation can not be pushed to tiflash because groupByItems contain virtual columns, which is not supported now",
"MPP mode may be blocked because groupByItems contain virtual columns, which is not supported now",
"Aggregation can not be pushed to tiflash because groupByItems contain virtual columns, which is not supported now",
"MPP mode may be blocked because groupByItems contain virtual columns, which is not supported now",
"Aggregation can not be pushed to tiflash because groupByItems contain virtual columns, which is not supported now"
]
},
Expand All @@ -333,13 +325,9 @@
" └─TableFullScan_12 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
],
"Warn": [
"MPP mode may be blocked because AggFunc `group_concat` is not supported now",
"Aggregation can not be pushed to tiflash because AggFunc `group_concat` is not supported now",
"MPP mode may be blocked because AggFunc `group_concat` is not supported now",
"Aggregation can not be pushed to tiflash because AggFunc `group_concat` is not supported now",
"MPP mode may be blocked because AggFunc `group_concat` is not supported now",
"Aggregation can not be pushed to tiflash because AggFunc `group_concat` is not supported now",
"MPP mode may be blocked because AggFunc `group_concat` is not supported now",
"Aggregation can not be pushed to tiflash because AggFunc `group_concat` is not supported now"
]
},
Expand All @@ -353,13 +341,10 @@
],
"Warn": [
"Scalar function 'md5'(signature: MD5) can not be pushed to tiflash",
"MPP mode may be blocked because groupByItems contain unsupported exprs",
"Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs",
"Scalar function 'md5'(signature: MD5) can not be pushed to tiflash",
"MPP mode may be blocked because groupByItems contain unsupported exprs",
"Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs",
"Scalar function 'md5'(signature: MD5) can not be pushed to tiflash",
"MPP mode may be blocked because groupByItems contain unsupported exprs",
"Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs"
]
},
Expand All @@ -378,6 +363,23 @@
"Expr 'test.t.c' can not be pushed to TiFlash because it contains Duration type",
"Expr 'test.t.c' can not be pushed to TiFlash because it contains Duration type"
]
},
{
"SQL": "EXPLAIN SELECT count(a) from t group by is_ipv4(a); -- 12. scalar func not supported (without pbcode)",
"Plan": [
"HashAgg_6 8000.00 root group by:Column#7, funcs:count(Column#6)->Column#5",
"└─Projection_19 10000.00 root test.t.a, is_ipv4(cast(test.t.a, var_string(20)))->Column#7",
" └─TableReader_12 10000.00 root data:TableFullScan_10",
" └─TableFullScan_10 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
],
"Warn": [
"Scalar function 'is_ipv4'(signature: Unspecified) can not be pushed to tiflash",
"Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs",
"Scalar function 'is_ipv4'(signature: Unspecified) can not be pushed to tiflash",
"Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs",
"Scalar function 'is_ipv4'(signature: Unspecified) can not be pushed to tiflash",
"Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs"
]
}
]
},
Expand Down