Commit 10738fa6 authored by unknown's avatar unknown

Fix for bug #29411: deleting from a csv table leads to the table corruption

Problem: we don't adjust share->rows_recorded and local_saved_data_file_length
deleting rows from a CSV table, so following table check may fail.

Fix: properly adjust those values.


mysql-test/r/csv.result:
  Fix for bug #29411: deleting from a csv table leads to the table corruption
    - test result.
mysql-test/t/csv.test:
  Fix for bug #29411: deleting from a csv table leads to the table corruption
    - test case.
storage/csv/ha_tina.cc:
  Fix for bug #29411: deleting from a csv table leads to the table corruption
    - decrement share->rows_recorded in the ha_tina::delete_row().
    - set share->rows_recorded and local_saved_data_file_length to 0 in the 
      ha_tina::delete_all_rows().
    - adjust local_saved_data_file_length after cleaning up in the 
      ha_tina::rnd_end().
parent 0b437391
......@@ -4945,8 +4945,6 @@ SELECT * FROM bug13894;
val
6
6
5
11
DROP TABLE bug13894;
DROP TABLE IF EXISTS bug14672;
CREATE TABLE bug14672 (c1 integer) engine = CSV;
......@@ -5291,4 +5289,20 @@ check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
create table t1(a int) engine=csv;
insert into t1 values (0), (1), (2);
delete from t1 limit 2;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1;
a
2
delete from t1;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1;
a
drop table t1;
End of 5.1 tests
......@@ -1698,4 +1698,17 @@ select * from t1;
check table t1;
drop table t1;
#
# Bug #29411: deleting from a csv table leads to the table corruption
#
create table t1(a int) engine=csv;
insert into t1 values (0), (1), (2);
delete from t1 limit 2;
check table t1;
select * from t1;
delete from t1;
check table t1;
select * from t1;
drop table t1;
--echo End of 5.1 tests
......@@ -960,6 +960,11 @@ int ha_tina::delete_row(const uchar * buf)
DBUG_RETURN(-1);
stats.records--;
/* Update shared info */
DBUG_ASSERT(share->rows_recorded);
pthread_mutex_lock(&share->mutex);
share->rows_recorded--;
pthread_mutex_unlock(&share->mutex);
/* DELETE should never happen on the log table */
DBUG_ASSERT(!share->is_log_table);
......@@ -1146,6 +1151,7 @@ int ha_tina::rnd_end()
if ((chain_ptr - chain) > 0)
{
off_t temp_file_length= 0;
tina_set *ptr= chain;
/*
......@@ -1171,15 +1177,18 @@ int ha_tina::rnd_end()
while ((file_buffer_start != -1)) // while not end of file
{
bool in_hole= get_write_pos(&write_end, ptr);
off_t write_length= write_end - write_begin;
/* if there is something to write, write it */
if ((write_end - write_begin) &&
(my_write(update_temp_file,
(uchar*)(file_buff->ptr() +
(write_begin - file_buff->start())),
write_end - write_begin, MYF_RW)))
goto error;
if (write_length)
{
if (my_write(update_temp_file,
(uchar*) (file_buff->ptr() +
(write_begin - file_buff->start())),
write_length, MYF_RW))
goto error;
temp_file_length+= write_length;
}
if (in_hole)
{
/* skip hole */
......@@ -1232,6 +1241,8 @@ int ha_tina::rnd_end()
Here we record this fact to the meta-file.
*/
(void)write_meta_file(share->meta_file, share->rows_recorded, FALSE);
local_saved_data_file_length= temp_file_length;
}
DBUG_RETURN(0);
......@@ -1390,6 +1401,11 @@ int ha_tina::delete_all_rows()
rc= my_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME));
stats.records=0;
/* Update shared info */
pthread_mutex_lock(&share->mutex);
share->rows_recorded= 0;
pthread_mutex_unlock(&share->mutex);
local_saved_data_file_length= 0;
DBUG_RETURN(rc);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment