Skip to content

Commit

Permalink
cherry pick pingcap#28466 to release-5.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
fzhedu authored and ti-srebot committed Oct 8, 2021
1 parent dc07933 commit 98ec00a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 66 deletions.
6 changes: 6 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,12 @@ func WrapWithCastAsDecimal(ctx sessionctx.Context, expr Expression) Expression {
if expr.GetType().EvalType() == types.ETInt {
tp.Flen = mysql.MaxIntWidth
}
<<<<<<< HEAD
=======
if tp.Flen == types.UnspecifiedLength || tp.Flen > mysql.MaxDecimalWidth {
tp.Flen = mysql.MaxDecimalWidth
}
>>>>>>> a18e05d2f... expression: limit valid decimal length (#28466)
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 @@ -3199,7 +3199,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 @@ -3239,7 +3239,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 @@ -217,7 +217,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 @@ -236,7 +237,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 98ec00a

Please sign in to comment.