From 0110acbdfea1b3ee2c14dd61124f6e074824c41a Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 14 Dec 2023 12:28:50 +0800 Subject: [PATCH] executor: set OverflowAsWarning for insert statement in non-strict sql mode (#49383) close pingcap/tidb#49369 --- pkg/executor/executor.go | 2 ++ .../integrationtest/r/executor/issues.result | 19 +++++++++++++++++++ tests/integrationtest/t/executor/issues.test | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 3d0178a815fc0..3c685ee286166 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -2116,6 +2116,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.DividedByZeroAsWarning = !vars.StrictSQLMode || stmt.IgnoreErr diff --git a/tests/integrationtest/r/executor/issues.result b/tests/integrationtest/r/executor/issues.result index 952378b5effb7..7a564b0b06692 100644 --- a/tests/integrationtest/r/executor/issues.result +++ b/tests/integrationtest/r/executor/issues.result @@ -831,3 +831,22 @@ explain select ps_partkey, sum(ps_supplycost * ps_availqty) as value from partsu Error 8175 (HY000): Your query has been cancelled due to exceeding the allowed memory limit for a single SQL query. Please try narrowing your query scope or increase the tidb_mem_quota_query limit and try again.[conn=] SET GLOBAL tidb_mem_oom_action = DEFAULT; set @@tidb_mem_quota_query=default; +drop table if exists issue49369; +CREATE TABLE `issue49369` ( +`x` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +insert into t select round(cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(18,12)) * cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(42,18)) ); +Error 1690 (22003): DECIMAL value is out of range in '(18, 12)' +set @@sql_mode = ''; +insert into t select round(cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(18,12)) * cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(42,18)) ); +show warnings; +Level Code Message +Warning 1690 DECIMAL value is out of range in '(18, 12)' +Warning 1690 DECIMAL value is out of range in '(42, 18)' +Warning 1690 %s value is out of range in '%s' +select * from t; +c +1 +2 +2147483647 +set @@sql_mode = default; diff --git a/tests/integrationtest/t/executor/issues.test b/tests/integrationtest/t/executor/issues.test index 93964c9f98d9c..52f2a7e279d2c 100644 --- a/tests/integrationtest/t/executor/issues.test +++ b/tests/integrationtest/t/executor/issues.test @@ -633,3 +633,17 @@ set @@tidb_mem_quota_query=128; explain select ps_partkey, sum(ps_supplycost * ps_availqty) as value from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'MOZAMBIQUE' group by ps_partkey having sum(ps_supplycost * ps_availqty) > ( select sum(ps_supplycost * ps_availqty) * 0.0001000000 from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = 'MOZAMBIQUE' ) order by value desc; SET GLOBAL tidb_mem_oom_action = DEFAULT; set @@tidb_mem_quota_query=default; + + +# TestIssue49369 +drop table if exists issue49369; +CREATE TABLE `issue49369` ( + `x` varchar(32) COLLATE utf8mb4_bin DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +--error 1690 +insert into t select round(cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(18,12)) * cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(42,18)) ); +set @@sql_mode = ''; +insert into t select round(cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(18,12)) * cast('88888899999999999888888888888888888888888888888888888.11111111111111111111' as decimal(42,18)) ); +show warnings; +select * from t; +set @@sql_mode = default; \ No newline at end of file