Skip to content

Commit e0abc22

Browse files
BUG#13406 - incorrect amount of "records deleted" in CSV.
Fallback to row-wise delete if number or rows in the table is unknown
1 parent a42b373 commit e0abc22

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

mysql-test/r/csv.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4976,3 +4976,27 @@ c1
49764976
4
49774977
5
49784978
DROP TABLE bug14672;
4979+
create table t1 (a int) engine=csv;
4980+
insert t1 values (1);
4981+
delete from t1;
4982+
affected rows: 1
4983+
delete from t1;
4984+
affected rows: 0
4985+
insert t1 values (1),(2);
4986+
delete from t1;
4987+
affected rows: 2
4988+
insert t1 values (1),(2),(3);
4989+
flush tables;
4990+
delete from t1;
4991+
affected rows: 3
4992+
insert t1 values (1),(2),(3),(4);
4993+
flush tables;
4994+
select count(*) from t1;
4995+
count(*)
4996+
4
4997+
delete from t1;
4998+
affected rows: 4
4999+
insert t1 values (1),(2),(3),(4),(5);
5000+
truncate table t1;
5001+
affected rows: 0
5002+
drop table t1;

mysql-test/t/csv.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,3 +1352,35 @@ SELECT * FROM bug14672;
13521352
DROP TABLE bug14672;
13531353

13541354
# End of 4.1 tests
1355+
1356+
#
1357+
# BUG#13406 - incorrect amount of "records deleted"
1358+
#
1359+
1360+
create table t1 (a int) engine=csv;
1361+
insert t1 values (1);
1362+
--enable_info
1363+
delete from t1; -- delete_row
1364+
delete from t1; -- delete_all_rows
1365+
--disable_info
1366+
insert t1 values (1),(2);
1367+
--enable_info
1368+
delete from t1; -- delete_all_rows
1369+
--disable_info
1370+
insert t1 values (1),(2),(3);
1371+
flush tables;
1372+
--enable_info
1373+
delete from t1; -- delete_row
1374+
--disable_info
1375+
insert t1 values (1),(2),(3),(4);
1376+
flush tables;
1377+
select count(*) from t1;
1378+
--enable_info
1379+
delete from t1; -- delete_all_rows
1380+
--disable_info
1381+
insert t1 values (1),(2),(3),(4),(5);
1382+
--enable_info
1383+
truncate table t1; -- truncate
1384+
--disable_info
1385+
drop table t1;
1386+

sql/examples/ha_tina.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ ha_tina::ha_tina(TABLE *table_arg)
274274
These definitions are found in hanler.h
275275
These are not probably completely right.
276276
*/
277-
current_position(0), next_position(0), chain_alloced(0), chain_size(DEFAULT_CHAIN_LENGTH)
277+
current_position(0), next_position(0), chain_alloced(0),
278+
chain_size(DEFAULT_CHAIN_LENGTH), records_is_known(0)
278279
{
279280
/* Set our original buffers from pre-allocated memory */
280281
buffer.set(byte_buffer, IO_SIZE, system_charset_info);
@@ -504,6 +505,7 @@ int ha_tina::write_row(byte * buf)
504505
*/
505506
if (get_mmap(share, 0) > 0)
506507
DBUG_RETURN(-1);
508+
records++;
507509
DBUG_RETURN(0);
508510
}
509511

@@ -668,6 +670,7 @@ int ha_tina::rnd_init(bool scan)
668670

669671
current_position= next_position= 0;
670672
records= 0;
673+
records_is_known= 0;
671674
chain_ptr= chain;
672675
#ifdef HAVE_MADVISE
673676
if (scan)
@@ -745,7 +748,7 @@ void ha_tina::info(uint flag)
745748
{
746749
DBUG_ENTER("ha_tina::info");
747750
/* This is a lie, but you don't want the optimizer to see zero or 1 */
748-
if (records < 2)
751+
if (!records_is_known && records < 2)
749752
records= 2;
750753
DBUG_VOID_RETURN;
751754
}
@@ -780,6 +783,8 @@ int ha_tina::rnd_end()
780783
{
781784
DBUG_ENTER("ha_tina::rnd_end");
782785

786+
records_is_known= 1;
787+
783788
/* First position will be truncate position, second will be increment */
784789
if ((chain_ptr - chain) > 0)
785790
{
@@ -824,17 +829,21 @@ int ha_tina::rnd_end()
824829
}
825830

826831
/*
827-
Truncate table and others of its ilk call this.
832+
DELETE without WHERE calls it
828833
*/
829834
int ha_tina::delete_all_rows()
830835
{
831836
DBUG_ENTER("ha_tina::delete_all_rows");
832837

838+
if (!records_is_known)
839+
return (my_errno=HA_ERR_WRONG_COMMAND);
840+
833841
int rc= my_chsize(share->data_file, 0, 0, MYF(MY_WME));
834842

835843
if (get_mmap(share, 0) > 0)
836844
DBUG_RETURN(-1);
837845

846+
records=0;
838847
DBUG_RETURN(rc);
839848
}
840849

sql/examples/ha_tina.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ha_tina: public handler
4848
tina_set *chain_ptr;
4949
byte chain_alloced;
5050
uint32 chain_size;
51+
bool records_is_known;
5152

5253
public:
5354
ha_tina(TABLE *table_arg);

0 commit comments

Comments
 (0)