From b77bb5f30a315835c6d5ae00c44fb996422adf58 Mon Sep 17 00:00:00 2001 From: zyguan Date: Fri, 5 Aug 2022 17:00:06 +0800 Subject: [PATCH 1/2] cherry pick #36304 to release-6.2 Signed-off-by: ti-srebot --- executor/insert.go | 18 ++++++++++++--- executor/insert_common.go | 39 +++++++++++++++++++++++++++----- executor/insert_test.go | 9 ++++---- executor/showtest/show_test.go | 4 ++-- executor/write_test.go | 17 +++++++------- expression/integration_test.go | 41 +++++++++++++++++++++++++--------- expression/scalar_function.go | 5 +---- 7 files changed, 96 insertions(+), 37 deletions(-) diff --git a/executor/insert.go b/executor/insert.go index abb3aa5efc7b5..a391d6412aae8 100644 --- a/executor/insert.go +++ b/executor/insert.go @@ -199,7 +199,7 @@ func (e *InsertExec) updateDupRow(ctx context.Context, idxInBatch int, txn kv.Tr extraCols = e.ctx.GetSessionVars().CurrInsertBatchExtraCols[idxInBatch] } - err = e.doDupRowUpdate(ctx, handle, oldRow, row.row, extraCols, e.OnDuplicate) + err = e.doDupRowUpdate(ctx, handle, oldRow, row.row, extraCols, e.OnDuplicate, idxInBatch) if e.ctx.GetSessionVars().StmtCtx.DupKeyAsWarning && kv.ErrKeyExists.Equal(err) { e.ctx.GetSessionVars().StmtCtx.AppendWarning(err) return nil @@ -374,7 +374,7 @@ func (e *InsertExec) initEvalBuffer4Dup() { // doDupRowUpdate updates the duplicate row. func (e *InsertExec) doDupRowUpdate(ctx context.Context, handle kv.Handle, oldRow []types.Datum, newRow []types.Datum, - extraCols []types.Datum, cols []*expression.Assignment) error { + extraCols []types.Datum, cols []*expression.Assignment, idxInBatch int) error { assignFlag := make([]bool, len(e.Table.WritableCols())) // See http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_values e.curInsertVals.SetDatums(newRow...) @@ -390,6 +390,8 @@ func (e *InsertExec) doDupRowUpdate(ctx context.Context, handle kv.Handle, oldRo // Update old row when the key is duplicated. e.evalBuffer4Dup.SetDatums(e.row4Update...) + sc := e.ctx.GetSessionVars().StmtCtx + warnCnt := int(sc.WarningCount()) for _, col := range cols { if col.LazyErr != nil { return col.LazyErr @@ -398,10 +400,20 @@ func (e *InsertExec) doDupRowUpdate(ctx context.Context, handle kv.Handle, oldRo if err1 != nil { return err1 } - e.row4Update[col.Col.Index], err1 = table.CastValue(e.ctx, val, col.Col.ToInfo(), false, false) + c := col.Col.ToInfo() + c.Name = col.ColName + e.row4Update[col.Col.Index], err1 = table.CastValue(e.ctx, val, c, false, false) if err1 != nil { return err1 } + if newWarnings := sc.TruncateWarnings(warnCnt); len(newWarnings) > 0 { + for k := range newWarnings { + // Use `idxInBatch` here for simplicity, since the offset of the batch is unknown under the current context. + newWarnings[k].Err = completeInsertErr(c, &val, idxInBatch, newWarnings[k].Err) + } + sc.AppendWarnings(newWarnings) + warnCnt += len(newWarnings) + } e.evalBuffer4Dup.SetDatum(col.Col.Index, e.row4Update[col.Col.Index]) assignFlag[col.Col.Index] = true } diff --git a/executor/insert_common.go b/executor/insert_common.go index dee087b13ae91..78e97c5693f1d 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -288,12 +288,7 @@ func insertRows(ctx context.Context, base insertCommon) (err error) { return nil } -func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int, err error) error { - if err == nil { - return nil - } - - // Convert the error with full messages. +func completeInsertErr(col *model.ColumnInfo, val *types.Datum, rowIdx int, err error) error { var ( colTp byte colName string @@ -324,6 +319,20 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int } else if types.ErrWarnDataOutOfRange.Equal(err) { err = types.ErrWarnDataOutOfRange.GenWithStackByArgs(colName, rowIdx+1) } + return err +} + +func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int, err error) error { + if err == nil { + return nil + } + + // Convert the error with full messages. + var c *model.ColumnInfo + if col != nil { + c = col.ColumnInfo + } + err = completeInsertErr(c, val, rowIdx, err) if !e.ctx.GetSessionVars().StmtCtx.DupKeyAsWarning { return err @@ -351,6 +360,8 @@ func (e *InsertValues) evalRow(ctx context.Context, list []expression.Expression } e.evalBuffer.SetDatums(row...) + sc := e.ctx.GetSessionVars().StmtCtx + warnCnt := int(sc.WarningCount()) for i, expr := range list { val, err := expr.Eval(e.evalBuffer.ToRow()) if err != nil { @@ -360,6 +371,13 @@ func (e *InsertValues) evalRow(ctx context.Context, list []expression.Expression if err = e.handleErr(e.insertColumns[i], &val, rowIdx, err); err != nil { return nil, err } + if newWarnings := sc.TruncateWarnings(warnCnt); len(newWarnings) > 0 { + for k := range newWarnings { + newWarnings[k].Err = completeInsertErr(e.insertColumns[i].ColumnInfo, &val, rowIdx, newWarnings[k].Err) + } + sc.AppendWarnings(newWarnings) + warnCnt += len(newWarnings) + } offset := e.insertColumns[i].Offset val1.Copy(&row[offset]) @@ -379,6 +397,8 @@ func (e *InsertValues) fastEvalRow(ctx context.Context, list []expression.Expres } row := make([]types.Datum, rowLen) hasValue := make([]bool, rowLen) + sc := e.ctx.GetSessionVars().StmtCtx + warnCnt := int(sc.WarningCount()) for i, expr := range list { con := expr.(*expression.Constant) val, err := con.Eval(emptyRow) @@ -389,6 +409,13 @@ func (e *InsertValues) fastEvalRow(ctx context.Context, list []expression.Expres if err = e.handleErr(e.insertColumns[i], &val, rowIdx, err); err != nil { return nil, err } + if newWarnings := sc.TruncateWarnings(warnCnt); len(newWarnings) > 0 { + for k := range newWarnings { + newWarnings[k].Err = completeInsertErr(e.insertColumns[i].ColumnInfo, &val, rowIdx, newWarnings[k].Err) + } + sc.AppendWarnings(newWarnings) + warnCnt += len(newWarnings) + } offset := e.insertColumns[i].Offset row[offset], hasValue[offset] = val1, true } diff --git a/executor/insert_test.go b/executor/insert_test.go index 4540ff711915f..5696f201f7a49 100644 --- a/executor/insert_test.go +++ b/executor/insert_test.go @@ -393,7 +393,7 @@ func TestInsertWrongValueForField(t *testing.T) { tk.MustExec(`CREATE TABLE ts (id int DEFAULT NULL, time1 TIMESTAMP NULL DEFAULT NULL)`) tk.MustExec(`SET @@sql_mode=''`) tk.MustExec(`INSERT INTO ts (id, time1) VALUES (1, TIMESTAMP '1018-12-23 00:00:00')`) - tk.MustQuery(`SHOW WARNINGS`).Check(testkit.Rows(`Warning 1292 Incorrect timestamp value: '1018-12-23 00:00:00'`)) + tk.MustQuery(`SHOW WARNINGS`).Check(testkit.Rows(`Warning 1292 Incorrect timestamp value: '1018-12-23 00:00:00' for column 'time1' at row 1`)) tk.MustQuery(`SELECT * FROM ts ORDER BY id`).Check(testkit.Rows(`1 0000-00-00 00:00:00`)) tk.MustExec(`SET @@sql_mode='STRICT_TRANS_TABLES'`) @@ -1691,7 +1691,7 @@ func TestIssue10402(t *testing.T) { tk.MustExec("insert into vctt values ('ab\\n\\n\\n', 'ab\\n\\n\\n'), ('ab\\t\\t\\t', 'ab\\t\\t\\t'), ('ab ', 'ab '), ('ab\\r\\r\\r', 'ab\\r\\r\\r')") require.Equal(t, uint16(4), tk.Session().GetSessionVars().StmtCtx.WarningCount()) warns := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - require.Equal(t, "[{Warning [types:1265]Data truncated, field len 4, data len 5} {Warning [types:1265]Data truncated, field len 4, data len 5} {Warning [types:1265]Data truncated, field len 4, data len 6} {Warning [types:1265]Data truncated, field len 4, data len 5}]", + require.Equal(t, "[{Warning [types:1265]Data truncated for column 'v' at row 1} {Warning [types:1265]Data truncated for column 'v' at row 2} {Warning [types:1265]Data truncated for column 'v' at row 3} {Warning [types:1265]Data truncated for column 'v' at row 4}]", fmt.Sprintf("%v", warns)) tk.MustQuery("select * from vctt").Check(testkit.Rows("ab\n\n ab\n\n", "ab\t\t ab\t\t", "ab ab", "ab\r\r ab\r\r")) tk.MustQuery("select length(v), length(c) from vctt").Check(testkit.Rows("4 4", "4 4", "4 2", "4 4")) @@ -1909,7 +1909,8 @@ func TestStringtoDecimal(t *testing.T) { tk.MustGetErrCode("insert into t values('1.2.')", errno.ErrTruncatedWrongValueForField) tk.MustGetErrCode("insert into t values('1,999.00')", errno.ErrTruncatedWrongValueForField) tk.MustExec("insert into t values('12e-3')") - tk.MustQuery("show warnings;").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect DECIMAL value: '0.012'")) + // TODO: MySQL8.0 reports Note 1265 Data truncated for column 'id' at row 1 + tk.MustQuery("show warnings;").Check(testkit.RowsWithSep("|", "Warning|1366|Incorrect decimal value: '12e-3' for column 'id' at row 1")) tk.MustQuery("select id from t").Check(testkit.Rows("0")) tk.MustExec("drop table if exists t") } @@ -1924,7 +1925,7 @@ func TestIssue17745(t *testing.T) { tk.MustGetErrCode("insert into tt1 values(89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)", errno.ErrWarnDataOutOfRange) tk.MustGetErrCode("insert into tt1 values(89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000)", errno.ErrWarnDataOutOfRange) tk.MustExec("insert ignore into tt1 values(89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000)") - tk.MustQuery("show warnings;").Check(testkit.Rows(`Warning 1690 DECIMAL value is out of range in '(64, 0)'`, `Warning 1292 Truncated incorrect DECIMAL value: '789012345678901234567890123456789012345678901234567890123456789012345678900000000'`)) + tk.MustQuery("show warnings;").Check(testkit.Rows(`Warning 1264 Out of range value for column 'c1' at row 1`, `Warning 1292 Truncated incorrect DECIMAL value: '789012345678901234567890123456789012345678901234567890123456789012345678900000000'`)) tk.MustQuery("select c1 from tt1").Check(testkit.Rows("9999999999999999999999999999999999999999999999999999999999999999")) tk.MustGetErrCode("update tt1 set c1 = 89123456789012345678901234567890123456789012345678901234567890123456789012345678900000000", errno.ErrWarnDataOutOfRange) tk.MustExec("drop table if exists tt1") diff --git a/executor/showtest/show_test.go b/executor/showtest/show_test.go index e983bc3a2746e..60c5944fbea89 100644 --- a/executor/showtest/show_test.go +++ b/executor/showtest/show_test.go @@ -700,9 +700,9 @@ func TestShowWarnings(t *testing.T) { tk.MustExec("set @@sql_mode=''") tk.MustExec("insert show_warnings values ('a')") require.Equal(t, uint16(1), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect DOUBLE value: 'a'")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1366|Incorrect int value: 'a' for column 'a' at row 1")) require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect DOUBLE value: 'a'")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1366|Incorrect int value: 'a' for column 'a' at row 1")) require.Equal(t, uint16(0), tk.Session().GetSessionVars().StmtCtx.WarningCount()) // Test Warning level 'Error' diff --git a/executor/write_test.go b/executor/write_test.go index aa2b77b4122b7..2a57842af4a09 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -213,7 +213,8 @@ func TestInsert(t *testing.T) { tk.MustExec("CREATE TABLE t(a DECIMAL(4,2));") tk.MustExec("INSERT INTO t VALUES (1.000001);") r = tk.MustQuery("SHOW WARNINGS;") - r.Check(testkit.Rows("Warning 1292 Truncated incorrect DECIMAL value: '1.000001'")) + // TODO: MySQL8.0 reports Note 1265 Data truncated for column 'a' at row 1 + r.Check(testkit.Rows("Warning 1366 Incorrect decimal value: '1.000001' for column 'a' at row 1")) tk.MustExec("INSERT INTO t VALUES (1.000000);") r = tk.MustQuery("SHOW WARNINGS;") r.Check(testkit.Rows()) @@ -250,15 +251,14 @@ func TestInsert(t *testing.T) { require.True(t, types.ErrWarnDataOutOfRange.Equal(err)) tk.MustExec("set @@sql_mode = '';") tk.MustExec("insert into t value (-1);") - // TODO: the following warning messages are not consistent with MySQL, fix them in the future PRs - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1690 constant -1 overflows bigint")) + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'a' at row 1")) tk.MustExec("insert into t select -1;") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1690 constant -1 overflows bigint")) tk.MustExec("insert into t select cast(-1 as unsigned);") tk.MustExec("insert into t value (-1.111);") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1690 constant -1.111 overflows bigint")) + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'a' at row 1")) tk.MustExec("insert into t value ('-1.111');") - tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1690 BIGINT UNSIGNED value is out of range in '-1'")) + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'a' at row 1")) tk.MustExec("update t set a = -1 limit 1;") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1690 constant -1 overflows bigint")) r = tk.MustQuery("select * from t;") @@ -281,8 +281,8 @@ func TestInsert(t *testing.T) { tk.MustExec("create table t(a float unsigned, b double unsigned)") tk.MustExec("insert into t value(-1.1, -1.1), (-2.1, -2.1), (0, 0), (1.1, 1.1)") tk.MustQuery("show warnings"). - Check(testkit.Rows("Warning 1690 constant -1.1 overflows float", "Warning 1690 constant -1.1 overflows double", - "Warning 1690 constant -2.1 overflows float", "Warning 1690 constant -2.1 overflows double")) + Check(testkit.Rows("Warning 1264 Out of range value for column 'a' at row 1", "Warning 1264 Out of range value for column 'b' at row 1", + "Warning 1264 Out of range value for column 'a' at row 2", "Warning 1264 Out of range value for column 'b' at row 2")) tk.MustQuery("select * from t").Check(testkit.Rows("0 0", "0 0", "0 0", "1.1 1.1")) // issue 7061 @@ -531,7 +531,8 @@ func TestInsertIgnore(t *testing.T) { require.NoError(t, err) require.Empty(t, tk.Session().LastMessage()) r = tk.MustQuery("SHOW WARNINGS") - r.Check(testkit.Rows("Warning 1292 Truncated incorrect DOUBLE value: '1a'")) + // TODO: MySQL8.0 reports Warning 1265 Data truncated for column 'a' at row 1 + r.Check(testkit.Rows("Warning 1366 Incorrect bigint value: '1a' for column 'a' at row 1")) // for duplicates with warning testSQL = `drop table if exists t; diff --git a/expression/integration_test.go b/expression/integration_test.go index cf1ab5efa08e5..eedb0243cc13a 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -502,8 +502,8 @@ func TestConvertToBit(t *testing.T) { tk.MustExec("create table t(a tinyint, b bit(63));") tk.MustExec("insert ignore into t values(599999999, -1);") tk.MustQuery("show warnings;").Check(testkit.Rows( - "Warning 1690 constant 599999999 overflows tinyint", - "Warning 1406 Data Too Long, field len 63")) + "Warning 1264 Out of range value for column 'a' at row 1", + "Warning 1406 Data too long for column 'b' at row 1")) tk.MustQuery("select * from t;").Check(testkit.Rows("127 \u007f\xff\xff\xff\xff\xff\xff\xff")) // For issue 24900 @@ -511,8 +511,8 @@ func TestConvertToBit(t *testing.T) { tk.MustExec("create table t(b bit(16));") tk.MustExec("insert ignore into t values(0x3635313836),(0x333830);") tk.MustQuery("show warnings;").Check(testkit.Rows( - "Warning 1406 Data Too Long, field len 16", - "Warning 1406 Data Too Long, field len 16")) + "Warning 1406 Data too long for column 'b' at row 1", + "Warning 1406 Data too long for column 'b' at row 2")) tk.MustQuery("select * from t;").Check(testkit.Rows("\xff\xff", "\xff\xff")) } @@ -5399,7 +5399,7 @@ func TestIssue19892(t *testing.T) { tk.MustExec("TRUNCATE TABLE dd") tk.MustExec("INSERT INTO dd(c) values('0000-00-00 20:00:00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00' for column 'c' at row 1")) tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) tk.MustExec("TRUNCATE TABLE dd") @@ -5413,7 +5413,7 @@ func TestIssue19892(t *testing.T) { { tk.MustExec("TRUNCATE TABLE dd") tk.MustExec("INSERT INTO dd(b) values('0000-0-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '0000-0-00'")) + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '0000-0-00' for column 'b' at row 1")) tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) tk.MustExec("TRUNCATE TABLE dd") @@ -5434,7 +5434,7 @@ func TestIssue19892(t *testing.T) { tk.MustExec("TRUNCATE TABLE dd") tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('0000-00-00 20:00:00')", "[table:1292]Incorrect timestamp value: '0000-00-00 20:00:00' for column 'c' at row 1") tk.MustExec("INSERT IGNORE INTO dd(c) VALUES ('0000-00-00 20:00:00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00' for column 'c' at row 1")) tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) tk.MustExec("TRUNCATE TABLE dd") @@ -5485,7 +5485,7 @@ func TestIssue19892(t *testing.T) { { tk.MustExec("TRUNCATE TABLE dd") tk.MustExec("INSERT INTO dd(a) values('2000-01-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '2000-01-00'")) + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '2000-01-00' for column 'a' at row 1")) tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) tk.MustExec("TRUNCATE TABLE dd") @@ -5513,7 +5513,7 @@ func TestIssue19892(t *testing.T) { tk.MustExec("TRUNCATE TABLE dd") tk.MustGetErrMsg("INSERT INTO dd(b) VALUES ('2000-01-00')", "[table:1292]Incorrect datetime value: '2000-01-00' for column 'b' at row 1") tk.MustExec("INSERT IGNORE INTO dd(b) VALUES ('2000-00-01')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01'")) + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01' for column 'b' at row 1")) tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) tk.MustExec("TRUNCATE TABLE dd") @@ -5566,7 +5566,7 @@ func TestIssue19892(t *testing.T) { tk.MustExec("TRUNCATE TABLE dd") tk.MustGetErrMsg("INSERT INTO dd(b) VALUES ('2000-01-00')", "[table:1292]Incorrect datetime value: '2000-01-00' for column 'b' at row 1") tk.MustExec("INSERT IGNORE INTO dd(b) VALUES ('2000-00-01')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01'")) + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01' for column 'b' at row 1")) tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) tk.MustExec("TRUNCATE TABLE dd") @@ -7506,6 +7506,27 @@ func TestIssue31600(t *testing.T) { tk.MustExec("drop table t") } +func TestIssue31569(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (c int primary key, c2 enum('a', 'b'))") + tk.MustExec("set session sql_mode = ''") + tk.MustExec("insert into t values(4, 'a')") + tk.MustExec("insert into t values(4, 0) on duplicate key update c=values(c), c2=values(c2)") + // tidb produces two warnings here (when eval (4, 0) & values(c2)), which is slightly incompatible with mysql + tk.MustQuery("show warnings").Check([][]interface{}{ + {"Warning", "1265", "Data truncated for column 'c2' at row 1"}, + {"Warning", "1265", "Data truncated for column 'c2' at row 1"}, + }) + tk.MustExec("insert into t values(4, 'a') on duplicate key update c=values(c), c2=values(c2)") + tk.MustQuery("show warnings").Check([][]interface{}{}) + tk.MustExec("drop table t") +} + func TestDateAddForNonExistingTimestamp(t *testing.T) { store, clean := testkit.CreateMockStore(t) defer clean() diff --git a/expression/scalar_function.go b/expression/scalar_function.go index d58ed6e5792a7..4d489d43c1656 100644 --- a/expression/scalar_function.go +++ b/expression/scalar_function.go @@ -375,10 +375,7 @@ func (sf *ScalarFunction) Eval(row chunk.Row) (d types.Datum, err error) { res, err = types.ParseEnum(tp.GetElems(), str, tp.GetCollate()) if ctx := sf.GetCtx(); ctx != nil { if sc := ctx.GetSessionVars().StmtCtx; sc != nil { - if sc.TruncateAsWarning { - ctx.GetSessionVars().StmtCtx.AppendWarning(err) - err = nil - } + err = sc.HandleTruncate(err) } } } else { From b1f9baf333948bd6f7570915c7f86f7e1daa75aa Mon Sep 17 00:00:00 2001 From: zyguan Date: Tue, 9 Aug 2022 03:47:02 +0000 Subject: [PATCH 2/2] fixup Signed-off-by: zyguan --- expression/integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index eedb0243cc13a..01e5a1e74d8a2 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7507,7 +7507,8 @@ func TestIssue31600(t *testing.T) { } func TestIssue31569(t *testing.T) { - store := testkit.CreateMockStore(t) + store, clean := testkit.CreateMockStore(t) + defer clean() tk := testkit.NewTestKit(t, store)