From d82cf4c971932c2e034992e867f0dd650520da81 Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Thu, 9 Apr 2020 12:37:09 +0800 Subject: [PATCH] executor: fix unexpected error in union stmt. (#16073) (#16137) --- 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 9198a1d559c1a..34d9fd852f60e 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1542,6 +1542,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 1ab4c22d2c792..27173fe636c4a 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -4920,6 +4920,16 @@ func (s *testIntegrationSuite) TestValuesForBinaryLiteral(c *C) { 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;") +} + func (s *testIntegrationSuite) TestCacheRefineArgs(c *C) { tk := testkit.NewTestKit(c, s.store) orgEnable := plannercore.PreparedPlanCacheEnabled()