Skip to content

Commit 92f7d00

Browse files
mariadb-RuchaDeodharvuvova
authored andcommitted
MDEV-26844: DELETE returns ROW_NUMBER=1 for every row upon
ER_TRUNCATED_WRONG_VALUE Part 1: Fix for DELETE without ORDER BY Analysis: m_current_row_for_warning doesn't increment and assumes default value which is then used by ROW_NUMBER. Fix: Increment m_current_row_for_warning for each processed row.
1 parent e13dc7d commit 92f7d00

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

mysql-test/main/get_diagnostics.result

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,3 +1783,31 @@ SELECT @n;
17831783
@n
17841784
4
17851785
DROP TABLE t1;
1786+
#
1787+
# MDEV-26844: DELETE returns ROW_NUMBER=1 for every row upon
1788+
# ER_TRUNCATED_WRONG_VALUE
1789+
#
1790+
# without ORDER BY
1791+
CREATE TABLE t (a VARCHAR(8));
1792+
INSERT INTO t VALUES ('val1'),('val2'),('100'),('val4');
1793+
SELECT * FROM t;
1794+
a
1795+
val1
1796+
val2
1797+
100
1798+
val4
1799+
DELETE FROM t WHERE a = 100;
1800+
Warnings:
1801+
Warning 1292 Truncated incorrect DOUBLE value: 'val1'
1802+
Warning 1292 Truncated incorrect DOUBLE value: 'val2'
1803+
Warning 1292 Truncated incorrect DOUBLE value: 'val4'
1804+
SHOW WARNINGS;
1805+
Level Code Message
1806+
Warning 1292 Truncated incorrect DOUBLE value: 'val1'
1807+
Warning 1292 Truncated incorrect DOUBLE value: 'val2'
1808+
Warning 1292 Truncated incorrect DOUBLE value: 'val4'
1809+
GET DIAGNOSTICS CONDITION 3 @n = ROW_NUMBER;
1810+
SELECT @n;
1811+
@n
1812+
4
1813+
DROP TABLE t;

mysql-test/main/get_diagnostics.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,3 +1667,23 @@ GET DIAGNOSTICS CONDITION 2 @n= ROW_NUMBER;
16671667
SELECT @n;
16681668

16691669
DROP TABLE t1;
1670+
1671+
--echo #
1672+
--echo # MDEV-26844: DELETE returns ROW_NUMBER=1 for every row upon
1673+
--echo # ER_TRUNCATED_WRONG_VALUE
1674+
--echo #
1675+
1676+
--echo # without ORDER BY
1677+
1678+
CREATE TABLE t (a VARCHAR(8));
1679+
1680+
INSERT INTO t VALUES ('val1'),('val2'),('100'),('val4');
1681+
SELECT * FROM t;
1682+
1683+
DELETE FROM t WHERE a = 100;
1684+
SHOW WARNINGS;
1685+
1686+
GET DIAGNOSTICS CONDITION 3 @n = ROW_NUMBER;
1687+
SELECT @n;
1688+
1689+
DROP TABLE t;

sql/sql_delete.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
795795
THD_STAGE_INFO(thd, stage_updating);
796796
fix_rownum_pointers(thd, thd->lex->current_select, &deleted);
797797

798+
thd->get_stmt_da()->reset_current_row_for_warning(0);
798799
while (likely(!(error=info.read_record())) && likely(!thd->killed) &&
799800
likely(!thd->is_error()))
800801
{
802+
thd->get_stmt_da()->inc_current_row_for_warning();
801803
if (delete_while_scanning)
802804
delete_record= record_should_be_deleted(thd, table, select, explain,
803805
delete_history);
@@ -873,6 +875,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
873875
else
874876
break;
875877
}
878+
thd->get_stmt_da()->reset_current_row_for_warning(1);
876879

877880
terminate_delete:
878881
killed_status= thd->killed;

0 commit comments

Comments
 (0)