From 237590f9eb8fe894d29a142a531f4475d76f178f Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 3 Apr 2020 23:47:43 +0800 Subject: [PATCH 1/2] add union stmt flag --- executor/executor.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/executor/executor.go b/executor/executor.go index a2853f3cec2e2..f804d23362029 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1610,6 +1610,11 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.Priority = opts.Priority sc.NotFillCache = !opts.SQLCache } + case *ast.UnionStmt: + sc.OverflowAsWarning = true + sc.IgnoreTruncate = true + sc.IgnoreZeroInDate = true + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() case *ast.ShowStmt: sc.IgnoreTruncate = true sc.IgnoreZeroInDate = true From 0198c3c1aaa4a1ecd2d44d88c847d6d02b52918f Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Sat, 4 Apr 2020 00:01:00 +0800 Subject: [PATCH 2/2] add some test --- executor/executor.go | 3 ++- expression/integration_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/executor/executor.go b/executor/executor.go index f804d23362029..baee88e78d760 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1611,8 +1611,9 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.NotFillCache = !opts.SQLCache } case *ast.UnionStmt: + sc.InSelectStmt = true sc.OverflowAsWarning = true - sc.IgnoreTruncate = true + sc.TruncateAsWarning = true sc.IgnoreZeroInDate = true sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() case *ast.ShowStmt: diff --git a/expression/integration_test.go b/expression/integration_test.go index ba065b81c1d65..5470ab9839889 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5971,3 +5971,13 @@ func (s *testIntegrationSuite) TestNegativeZeroForHashJoin(c *C) { tk.MustExec("drop TABLE t0;") tk.MustExec("drop table t1;") } + +func (s *testIntegrationSuite) TestIssue15790(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test;") + tk.MustExec("CREATE TABLE t0(c0 INT);") + tk.MustExec("INSERT INTO t0(c0) VALUES (0);") + tk.MustQuery("SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION SELECT * FROM t0;").Check(testkit.Rows("0")) + tk.MustQuery("SELECT * FROM t0 WHERE -10000000000000000000 | t0.c0 UNION all SELECT * FROM t0;").Check(testkit.Rows("0", "0")) + tk.MustExec("drop table t0;") +}