Skip to content
Permalink
Browse files

planner, executor: fix tp.Flen size when union with castIntAsString (#…

  • Loading branch information...
AndrewDi authored and zz-jason committed Nov 28, 2018
1 parent b2620ce commit 8461a95e7563fca221693ddfe1fc5e2192eadbdf
Showing with 9 additions and 0 deletions.
  1. +6 −0 executor/executor_test.go
  2. +3 −0 plan/logical_plan_builder.go
@@ -1062,6 +1062,12 @@ func (s *testSuite) TestUnion(c *C) {
tk.MustExec("CREATE TABLE t2 (a int not null, b char (10) not null)")
tk.MustExec("insert into t2 values(1,'a'),(2,'b'),(3,'c'),(3,'c')")
tk.MustQuery("select a from t1 union select a from t1 order by (select a+1);").Check(testkit.Rows("1", "2", "3"))

// #issue 8231
tk.MustExec("drop table if exists t1")
tk.MustExec("CREATE TABLE t1 (uid int(1))")
tk.MustExec("INSERT INTO t1 SELECT 150")
tk.MustQuery("SELECT 'a' UNION SELECT uid FROM t1 order by 1 desc;").Check(testkit.Rows("a", "150"))
}

func (s *testSuite) TestNeighbouringProj(c *C) {
@@ -630,6 +630,9 @@ func joinFieldType(a, b *types.FieldType) *types.FieldType {
resultTp.Decimal = mathutil.Max(a.Decimal, b.Decimal)
// `Flen - Decimal` is the fraction before '.'
resultTp.Flen = mathutil.Max(a.Flen-a.Decimal, b.Flen-b.Decimal) + resultTp.Decimal
if resultTp.EvalType() != types.ETInt && (a.EvalType() == types.ETInt || b.EvalType() == types.ETInt) && resultTp.Flen < mysql.MaxIntWidth {
resultTp.Flen = mysql.MaxIntWidth
}
resultTp.Charset = a.Charset
resultTp.Collate = a.Collate
expression.SetBinFlagOrBinStr(b, resultTp)

0 comments on commit 8461a95

Please sign in to comment.
You can’t perform that action at this time.