Skip to content

Commit

Permalink
executor: fix big_unsigned_int union decimal sign bug (#7202)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored Jul 31, 2018
1 parent 26b7a5e commit 8739d80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2946,4 +2946,16 @@ func (s *testSuite) TestUnionAutoSignedCast(c *C) {
Check(testkit.Rows("1 -1", "2 1"))
tk.MustQuery("select id, v from t4 union select id, v from t3 order by id").
Check(testkit.Rows("1 0", "2 1"))

tk.MustExec("drop table if exists t5,t6,t7")
tk.MustExec("create table t5 (id int, v bigint unsigned)")
tk.MustExec("create table t6 (id int, v decimal)")
tk.MustExec("create table t7 (id int, v bigint)")
tk.MustExec("insert into t5 values (1, 1)")
tk.MustExec("insert into t6 values (2, -1)")
tk.MustExec("insert into t7 values (3, -1)")
tk.MustQuery("select id, v from t5 union select id, v from t6 order by id").
Check(testkit.Rows("1 1", "2 -1"))
tk.MustQuery("select id, v from t5 union select id, v from t7 union select id, v from t6 order by id").
Check(testkit.Rows("1 1", "2 -1", "3 -1"))
}
4 changes: 2 additions & 2 deletions plan/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ func (b *planBuilder) buildDistinct(child LogicalPlan, length int) LogicalPlan {
func unionJoinFieldType(a, b *types.FieldType) *types.FieldType {
resultTp := types.NewFieldType(types.MergeFieldType(a.Tp, b.Tp))
// This logic will be intelligible when it is associated with the buildProjection4Union logic.
if a.Tp == mysql.TypeNewDecimal {
// The decimal type will be unsigned only when all the decimals to be united are unsigned.
if resultTp.Tp == mysql.TypeNewDecimal {
// The decimal result type will be unsigned only when all the decimals to be united are unsigned.
resultTp.Flag &= b.Flag & mysql.UnsignedFlag
} else {
// Non-decimal results will be unsigned when the first SQL statement result in the union is unsigned.
Expand Down

0 comments on commit 8739d80

Please sign in to comment.