Skip to content

Commit dbd7017

Browse files
MDEV-36997 Assertion failed in ha_tina::delete_row on multi delete
Multi-delete code invokes ha_rnd_end after applying deferred deletes, following the pattern as in multi-update. The CSV engine batches deletes made via calls to delete_row, then applies them all at once during ha_rnd_end. For each row batched, the CSV engine decrements an internal counter of the total rows in the table. The multi-delete code was not calling ha_rnd_end, so this internal counter was not consistent with the total number of rows in the table, triggering the assertion. In the CSV engine, explicitly delete the destination file before renaming the source file over it. This avoids a file rename problem on Windows. This change would have been necessary before the latest multi-delete changes, had this test case existed at that point in time, because the end_read_record call in do_table_deletes swallowed the rename failure on Windows.
1 parent c095283 commit dbd7017

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

mysql-test/main/delete_multi_order_by.result

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,37 @@ id v
391391
select * from t3;
392392
id v
393393
drop table t1, t2, t3;
394+
#
395+
# Begin 11.8 tests
396+
#
397+
#
398+
# MDEV-36997 Assertion failed in ha_tina::delete_row on multi delete
399+
#
400+
SET sql_mode='';
401+
CREATE TABLE t1 (v INT (1) NOT NULL) ENGINE=CSV;
402+
INSERT INTO t1 SELECT 1 away;
403+
SELECT COUNT(*) from t1;
404+
COUNT(*)
405+
1
406+
DELETE FROM a3,a1 USING t1 AS a1 JOIN t1 AS a2 JOIN t1 AS a3;
407+
SELECT COUNT(*) from t1;
408+
COUNT(*)
409+
0
410+
DROP TABLE t1;
411+
SET sql_mode='';
412+
CREATE TABLE t1 (v VECTOR (1) NOT NULL) ENGINE=CSV;
413+
INSERT INTO t1 SELECT 1 away;
414+
Warnings:
415+
Warning 4078 Cannot cast 'int' as 'vector' in assignment of `test`.`t1`.`v`
416+
Warning 1292 Incorrect vector value: '1' for column `test`.`t1`.`v` at row 1
417+
SELECT COUNT(*) from t1;
418+
COUNT(*)
419+
1
420+
DELETE FROM a3,a1 USING t1 AS a1 JOIN t1 AS a2 JOIN t1 AS a3;
421+
SELECT COUNT(*) from t1;
422+
COUNT(*)
423+
0
424+
DROP TABLE t1;
425+
#
426+
# End 11.8 tests
427+
#

mysql-test/main/delete_multi_order_by.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
--source include/have_innodb.inc
6+
--source include/have_csv.inc
67

78
create table t1 (id int primary key, v int);
89
create table t2 (id int primary key, v int);
@@ -203,3 +204,30 @@ select * from t2;
203204
select * from t3;
204205

205206
drop table t1, t2, t3;
207+
208+
--echo #
209+
--echo # Begin 11.8 tests
210+
--echo #
211+
212+
--echo #
213+
--echo # MDEV-36997 Assertion failed in ha_tina::delete_row on multi delete
214+
--echo #
215+
SET sql_mode='';
216+
CREATE TABLE t1 (v INT (1) NOT NULL) ENGINE=CSV;
217+
INSERT INTO t1 SELECT 1 away;
218+
SELECT COUNT(*) from t1;
219+
DELETE FROM a3,a1 USING t1 AS a1 JOIN t1 AS a2 JOIN t1 AS a3;
220+
SELECT COUNT(*) from t1;
221+
DROP TABLE t1;
222+
223+
SET sql_mode='';
224+
CREATE TABLE t1 (v VECTOR (1) NOT NULL) ENGINE=CSV;
225+
INSERT INTO t1 SELECT 1 away;
226+
SELECT COUNT(*) from t1;
227+
DELETE FROM a3,a1 USING t1 AS a1 JOIN t1 AS a2 JOIN t1 AS a3;
228+
SELECT COUNT(*) from t1;
229+
DROP TABLE t1;
230+
231+
--echo #
232+
--echo # End 11.8 tests
233+
--echo #

sql/sql_delete.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,10 @@ int multi_delete::rowid_table_deletes(TABLE *table, bool ignore)
16471647
err:
16481648
if (err_table)
16491649
err_table->file->print_error(local_error,MYF(ME_FATAL));
1650+
if (tmp_table->file->inited == handler::init_stat::RND)
1651+
tmp_table->file->ha_rnd_end();
1652+
if (table->file->inited == handler::init_stat::RND)
1653+
table->file->ha_rnd_end();
16501654
DBUG_RETURN(local_error);
16511655
}
16521656

storage/csv/ha_tina.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ int ha_tina::rnd_end()
14631463
of the old datafile.
14641464
*/
14651465
if (mysql_file_close(data_file, MYF(0)) ||
1466+
mysql_file_delete(csv_key_file_data, share->data_file_name, MYF(0)) ||
14661467
mysql_file_rename(csv_key_file_data,
14671468
fn_format(updated_fname, share->table_name,
14681469
"", CSN_EXT,

0 commit comments

Comments
 (0)