Skip to content

Commit

Permalink
executor: set OverflowAsWarning for insert statement in non-strict sq…
Browse files Browse the repository at this point in the history
…l mode (#49383)

close #49369
  • Loading branch information
tiancaiamao authored Dec 14, 2023
1 parent 918df0a commit 0110acb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/integrationtest/r/executor/issues.result
Original file line number Diff line number Diff line change
Expand Up @@ -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=<num>]
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;
14 changes: 14 additions & 0 deletions tests/integrationtest/t/executor/issues.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 0110acb

Please sign in to comment.