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: open CAST string as real push down switcher #14323

Merged
merged 7 commits into from Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/explaintest/r/explain_easy.result
Expand Up @@ -465,9 +465,9 @@ begin;
insert tb values ('1');
explain select * from ta where a = 1;
id count task operator info
Selection_5 8000.00 root eq(cast(test.ta.a), 1)
└─TableReader_7 10000.00 root data:TableScan_6
└─TableScan_6 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
TableReader_7 8000.00 root data:Selection_6
└─Selection_6 8000.00 cop[tikv] eq(cast(test.ta.a), 1)
└─TableScan_5 10000.00 cop[tikv] table:ta, range:[-inf,+inf], keep order:false, stats:pseudo
rollback;
drop table if exists t1, t2;
create table t1(a int, b int, c int, primary key(a, b));
Expand Down
15 changes: 9 additions & 6 deletions expression/builtin_arithmetic.go
Expand Up @@ -273,13 +273,16 @@ func (s *builtinArithmeticPlusRealSig) Clone() builtinFunc {
}

func (s *builtinArithmeticPlusRealSig) evalReal(row chunk.Row) (float64, bool, error) {
a, isNull, err := s.args[0].EvalReal(s.ctx, row)
if isNull || err != nil {
return 0, isNull, err
a, isLHSNull, err := s.args[0].EvalReal(s.ctx, row)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the expressions which have two arguments in TiDB have this pattern, they have inconsistent behavior with MySQL.

create table t (a varchar(10));
insert into t values ('2007');
select * from t where NULL + pow(7020, a);

The above statement should report an error.

return 0, isLHSNull, err
}
b, isNull, err := s.args[1].EvalReal(s.ctx, row)
if isNull || err != nil {
return 0, isNull, err
b, isRHSNull, err := s.args[1].EvalReal(s.ctx, row)
if err != nil {
return 0, isRHSNull, err
}
if isLHSNull || isRHSNull {
return 0, true, nil
}
if (a > 0 && b > math.MaxFloat64-a) || (a < 0 && b < -math.MaxFloat64-a) {
return 0, true, types.ErrOverflow.GenWithStackByArgs("DOUBLE", fmt.Sprintf("(%s + %s)", s.args[0].String(), s.args[1].String()))
Expand Down
1 change: 0 additions & 1 deletion expression/expr_to_pb.go
Expand Up @@ -468,7 +468,6 @@ func (pc PbConverter) canFuncBePushed(sf *ScalarFunction) bool {
case ast.Cast:
switch sf.Function.PbCode() {
case tipb.ScalarFuncSig_CastStringAsInt,
tipb.ScalarFuncSig_CastStringAsReal,
tipb.ScalarFuncSig_CastStringAsTime,
tipb.ScalarFuncSig_CastTimeAsInt:
return false
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -54,7 +54,7 @@ require (
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
github.com/struCoder/pidusage v0.1.2
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/uber-go/atomic v1.3.2 // indirect
github.com/uber-go/atomic v1.3.2
github.com/uber/jaeger-client-go v2.15.0+incompatible
github.com/uber/jaeger-lib v1.5.0 // indirect
github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d // indirect
Expand Down
2 changes: 1 addition & 1 deletion planner/core/testdata/plan_suite_out.json
Expand Up @@ -1045,7 +1045,7 @@
},
{
"SQL": "select a from t where c = 'hanfei'",
"Best": "IndexReader(Index(t.c_d_e)[[NULL,+inf]])->Sel([eq(cast(test.t.c), cast(hanfei))])->Projection"
"Best": "IndexReader(Index(t.c_d_e)[[NULL,+inf]]->Sel([eq(cast(test.t.c), cast(hanfei))]))->Projection"
}
]
},
Expand Down