Skip to content

Commit

Permalink
expression: limit valid decimal length (pingcap#28466) (pingcap#28647)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot committed Oct 12, 2021
1 parent 560b0da commit 90ae7cc
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 70 deletions.
3 changes: 3 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,9 @@ func WrapWithCastAsDecimal(ctx sessionctx.Context, expr Expression) Expression {
if expr.GetType().EvalType() == types.ETInt {
tp.Flen = mysql.MaxIntWidth
}
if tp.Flen == types.UnspecifiedLength || tp.Flen > mysql.MaxDecimalWidth {
tp.Flen = mysql.MaxDecimalWidth
}
types.SetBinChsClnFlag(tp)
tp.Flag |= expr.GetType().Flag & mysql.UnsignedFlag
return BuildCastFunction(ctx, expr, tp)
Expand Down
4 changes: 2 additions & 2 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3040,7 +3040,7 @@ func (s *testIntegrationSerialSuite) TestPushDownProjectionForTiFlash(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int, value decimal(6,3))")
tk.MustExec("create table t (id int, value decimal(6,3), name char(128))")
tk.MustExec("analyze table t")
tk.MustExec("set session tidb_allow_mpp=OFF")

Expand Down Expand Up @@ -3080,7 +3080,7 @@ func (s *testIntegrationSerialSuite) TestPushDownProjectionForMPP(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int, value decimal(6,3))")
tk.MustExec("create table t (id int, value decimal(6,3), name char(128))")
tk.MustExec("analyze table t")

// Create virtual tiflash replica info.
Expand Down
6 changes: 4 additions & 2 deletions planner/core/testdata/integration_serial_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@
"desc format = 'brief' select * from t right join (select id-2 as b from t) A on A.b=t.id",
"desc format = 'brief' select A.b, B.b from (select id-2 as b from t) B join (select id-2 as b from t) A on A.b=B.b",
"desc format = 'brief' select A.id from t as A where exists (select 1 from t where t.id=A.id)",
"desc format = 'brief' select A.id from t as A where not exists (select 1 from t where t.id=A.id)"
"desc format = 'brief' select A.id from t as A where not exists (select 1 from t where t.id=A.id)",
"desc format = 'brief' SELECT FROM_UNIXTIME(name,'%Y-%m-%d') FROM t;"
]
},
{
Expand All @@ -206,7 +207,8 @@
"desc format = 'brief' select A.b, B.b from (select id-2 as b from t) B join (select id-2 as b from t) A on A.b=B.b",
"desc format = 'brief' select id from t as A where exists (select 1 from t where t.id=A.id)",
"desc format = 'brief' select id from t as A where not exists (select 1 from t where t.id=A.id)",
"desc format = 'brief' select b*2, id from (select avg(value+2) as b, id from t group by id) C order by id"
"desc format = 'brief' select b*2, id from (select avg(value+2) as b, id from t group by id) C order by id",
"desc format = 'brief' SELECT FROM_UNIXTIME(name,'%Y-%m-%d') FROM t;"
]
},
{
Expand Down
Loading

0 comments on commit 90ae7cc

Please sign in to comment.