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
8 changes: 8 additions & 0 deletions expression/builtin_miscellaneous.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ func (c *inetAtonFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
bf.tp.Flen = 21
bf.tp.Flag |= mysql.UnsignedFlag
sig := &builtinInetAtonSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_InetAton)
return sig, nil
}

Expand Down Expand Up @@ -476,6 +477,7 @@ func (c *inetNtoaFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
bf.tp.Flen = 93
bf.tp.Decimal = 0
sig := &builtinInetNtoaSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_InetNtoa)
return sig, nil
}

Expand Down Expand Up @@ -528,6 +530,7 @@ func (c *inet6AtonFunctionClass) getFunction(ctx sessionctx.Context, args []Expr
types.SetBinChsClnFlag(bf.tp)
bf.tp.Decimal = 0
sig := &builtinInet6AtonSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Inet6Aton)
return sig, nil
}

Expand Down Expand Up @@ -600,6 +603,7 @@ func (c *inet6NtoaFunctionClass) getFunction(ctx sessionctx.Context, args []Expr
bf.tp.Flen = 117
bf.tp.Decimal = 0
sig := &builtinInet6NtoaSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Inet6Ntoa)
return sig, nil
}

Expand Down Expand Up @@ -654,6 +658,7 @@ func (c *isIPv4FunctionClass) getFunction(ctx sessionctx.Context, args []Express
}
bf.tp.Flen = 1
sig := &builtinIsIPv4Sig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IsIPv4)
return sig, nil
}

Expand Down Expand Up @@ -721,6 +726,7 @@ func (c *isIPv4CompatFunctionClass) getFunction(ctx sessionctx.Context, args []E
}
bf.tp.Flen = 1
sig := &builtinIsIPv4CompatSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IsIPv4Compat)
return sig, nil
}

Expand Down Expand Up @@ -769,6 +775,7 @@ func (c *isIPv4MappedFunctionClass) getFunction(ctx sessionctx.Context, args []E
}
bf.tp.Flen = 1
sig := &builtinIsIPv4MappedSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IsIPv4Mapped)
return sig, nil
}

Expand Down Expand Up @@ -817,6 +824,7 @@ func (c *isIPv6FunctionClass) getFunction(ctx sessionctx.Context, args []Express
}
bf.tp.Flen = 1
sig := &builtinIsIPv6Sig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IsIPv6)
return sig, nil
}

Expand Down
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
17 changes: 9 additions & 8 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,9 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
ast.Cast,

// misc functions.
ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton, ast.IsIPv4, ast.IsIPv4Compat, ast.IsIPv4Mapped, ast.IsIPv6, ast.UUID:
// TODO(#26942): enable functions below after them are fully tested in TiKV.
/*ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton, ast.IsIPv4, ast.IsIPv4Compat, ast.IsIPv4Mapped, ast.IsIPv6,*/
ast.UUID:

return true

Expand Down Expand Up @@ -1161,15 +1163,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
15 changes: 0 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 Down