Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: set OverflowAsWarning for insert statement in non-strict sql mode (#49383) #49455

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,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
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 @@ -746,6 +746,25 @@ insert into F values (1, 8);
select table1.`col_int` as field1, table1.`col_int` as field2 from V as table1 left join F as table2 on table1.`col_int` = table2.`col_int` order by field1, field2 desc limit 2;
field1 field2
8 8
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;
set @@tidb_max_chunk_size = 32;
drop table if exists t, s;
CREATE TABLE `t` (`c` char(1)) COLLATE=utf8_general_ci ;
Expand Down
15 changes: 14 additions & 1 deletion tests/integrationtest/t/executor/issues.test
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,19 @@ create table F (id int primary key, col_int int);
insert into F values (1, 8);
select table1.`col_int` as field1, table1.`col_int` as field2 from V as table1 left join F as table2 on table1.`col_int` = table2.`col_int` order by field1, field2 desc limit 2;

# 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;

# TestIssue49902
set @@tidb_max_chunk_size = 32;
drop table if exists t, s;
Expand All @@ -568,4 +581,4 @@ insert into s values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),
insert into s values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1);
SELECT /*+ stream_agg()*/ count(`t`.`c`) FROM (`s`) JOIN `t` GROUP BY `t`.`c`;
SELECT count(`t`.`c`) FROM (`s`) JOIN `t` GROUP BY `t`.`c`;
set @@tidb_max_chunk_size = default;
set @@tidb_max_chunk_size = default;