From 370a12ff9813207eb99d10a411ab0d2aecc3a0bc Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Thu, 9 Apr 2020 11:50:08 +0800 Subject: [PATCH] executor: fix unexpected error in union stmt. (#16073) (#16138) --- executor/executor.go | 6 ++++++ expression/integration_test.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/executor/executor.go b/executor/executor.go index 9e32321591408..71d443f9c02e1 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1563,6 +1563,12 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.NotFillCache = !opts.SQLCache } sc.CastStrToIntStrict = true + case *ast.UnionStmt: + sc.InSelectStmt = true + sc.OverflowAsWarning = true + sc.TruncateAsWarning = true + sc.IgnoreZeroInDate = true + sc.AllowInvalidDate = vars.SQLMode.HasAllowInvalidDatesMode() case *ast.ShowStmt: sc.IgnoreTruncate = true sc.IgnoreZeroInDate = true diff --git a/expression/integration_test.go b/expression/integration_test.go index 0f999d560103f..4e85839970331 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -4918,3 +4918,13 @@ func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { tk.MustQuery("select a=0 from testValuesBinary;").Check(testkit.Rows("1")) tk.MustExec("drop table testValuesBinary;") } + +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;") +}