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) (#49484)

close #49369
  • Loading branch information
tiancaiamao authored Dec 15, 2023
1 parent ac248c1 commit b57f662
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,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
16 changes: 16 additions & 0 deletions executor/issuetest/executor_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit b57f662

Please sign in to comment.