From 4d48d70186f3b352e05e09ac703d9ab79801efb3 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 15 Dec 2023 13:55:50 +0800 Subject: [PATCH] executor: set OverflowAsWarning for insert statement in non-strict sql mode (#49383) (#49459) close pingcap/tidb#49369 --- executor/executor.go | 2 ++ executor/issuetest/executor_issue_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/executor/executor.go b/executor/executor.go index b91e3ba16a478..946bf721eafea 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -2177,6 +2177,8 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { // but should not make DupKeyAsWarning. sc.DupKeyAsWarning = stmt.IgnoreErr sc.BadNullAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr + // see https://dev.mysql.com/doc/refman/8.0/en/out-of-range-and-overflow.html + sc.OverflowAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr sc.IgnoreNoPartition = stmt.IgnoreErr sc.ErrAutoincReadFailedAsWarning = stmt.IgnoreErr sc.TruncateAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr diff --git a/executor/issuetest/executor_issue_test.go b/executor/issuetest/executor_issue_test.go index 8d5c11ad627cf..91664bfcece4a 100644 --- a/executor/issuetest/executor_issue_test.go +++ b/executor/issuetest/executor_issue_test.go @@ -1461,3 +1461,19 @@ func TestIssue42662(t *testing.T) { require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/issue42662_1")) require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/util/servermemorylimit/issue42662_2")) } + +func TestIssue49369(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists issue49369;") + tk.MustExec("CREATE TABLE `issue49369` (\n" + + "`x` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") + err := tk.ExecToErr("insert into issue49369 select round(cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(18,12)) * cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(42,18)) );") + require.EqualError(t, err, "[types:1690]DECIMAL value is out of range in '(18, 12)'") + tk.MustExec("set @@sql_mode = ''") + tk.MustExec("insert into issue49369 select round(cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(18,12)) * cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(42,18)) );") + tk.MustQuery("select * from issue49369").Check(testkit.Rows("999999999999999999000000000000")) + tk.MustExec("set @@sql_mode = default") +}