diff --git a/mysql-test/main/get_diagnostics.result b/mysql-test/main/get_diagnostics.result index 090642923ce..d394d96eaff 100644 --- a/mysql-test/main/get_diagnostics.result +++ b/mysql-test/main/get_diagnostics.result @@ -1734,3 +1734,16 @@ SELECT @row_num; @row_num 105 DROP PROCEDURE resignal_syntax; +# +# MDEV-26842: ROW_NUMBER is not set and differs from the message upon +# WARN_DATA_TRUNCATED produced by inplace ALTER +# +CREATE TABLE t1 (a VARCHAR(64)) ENGINE=InnoDB; +INSERT INTO t1 VALUES ('foo'),(null); +ALTER TABLE t1 ADD PRIMARY KEY(a), ALGORITHM=INPLACE; +ERROR 01000: Data truncated for column 'a' at row 2 +GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT; +SELECT @n, @m; +@n @m +2 Data truncated for column 'a' at row 2 +DROP TABLE t1; diff --git a/mysql-test/main/get_diagnostics.test b/mysql-test/main/get_diagnostics.test index 09a7b3bd0c3..f4495059f9c 100644 --- a/mysql-test/main/get_diagnostics.test +++ b/mysql-test/main/get_diagnostics.test @@ -1,3 +1,5 @@ +--source include/have_innodb.inc + SET NAMES utf8; --echo # @@ -1614,3 +1616,19 @@ GET DIAGNOSTICS CONDITION 1 @row_num= ROW_NUMBER; SELECT @row_num; DROP PROCEDURE resignal_syntax; + +--echo # +--echo # MDEV-26842: ROW_NUMBER is not set and differs from the message upon +--echo # WARN_DATA_TRUNCATED produced by inplace ALTER +--echo # + +CREATE TABLE t1 (a VARCHAR(64)) ENGINE=InnoDB; +INSERT INTO t1 VALUES ('foo'),(null); + +--error WARN_DATA_TRUNCATED +ALTER TABLE t1 ADD PRIMARY KEY(a), ALGORITHM=INPLACE; + +GET DIAGNOSTICS CONDITION 1 @n= ROW_NUMBER, @m= MESSAGE_TEXT; +SELECT @n, @m; + +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index 63d39c77d95..b72b0357c23 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11101,6 +11101,14 @@ Field::set_warning(Sql_condition::enum_warning_level level, uint code, will have table == NULL. */ THD *thd= get_thd(); + + /* + In INPLACE ALTER, server can't know which row has generated + the warning, so the value of current row is supplied by the engine. + */ + if (current_row) + thd->get_stmt_da()->reset_current_row_for_warning(current_row); + if (thd->count_cuted_fields > CHECK_FIELD_EXPRESSION) { thd->cuted_fields+= cut_increment;