Skip to content

Commit

Permalink
MDEV-15380 Index for versioned table gets corrupt after partitioning …
Browse files Browse the repository at this point in the history
…and DELETE

In a test case Update occurs between Search and Delete/Update. This corrupts rowid
which Search saves for Delete/Update. Patch prevents this by using of
HA_EXTRA_REMEMBER_POS and HA_EXTRA_RESTORE_POS in a partition code.

This situation possibly occurs only with system versioning table and partition.
MyISAM and Aria engines are affected.

fix by midenok
Closes #705
  • Loading branch information
kevgs authored and vuvova committed May 22, 2018
1 parent 4ec8598 commit aa5683d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
18 changes: 18 additions & 0 deletions mysql-test/suite/versioning/r/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,24 @@ delete from t1 where a is not null;
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current);
select * from t1 partition (p0) for system_time all;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
# MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
create or replace table t1 (pk int primary key)
engine=myisam
with system versioning
partition by key() partitions 3;
set timestamp=1523466002.799571;
insert into t1 values (11),(12);
set timestamp=1523466004.169435;
delete from t1 where pk in (11, 12);
Same test but for Aria storage engine
create or replace table t1 (pk int primary key)
engine=aria
with system versioning
partition by key() partitions 3;
set timestamp=1523466002.799571;
insert into t1 values (11),(12);
set timestamp=1523466004.169435;
delete from t1 where pk in (11, 12);
# Test cleanup
drop database test;
create database test;
19 changes: 19 additions & 0 deletions mysql-test/suite/versioning/t/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,25 @@ create or replace table t1 (i int) with system versioning partition by system_ti
--error ER_VERS_QUERY_IN_PARTITION
select * from t1 partition (p0) for system_time all;

--echo # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
create or replace table t1 (pk int primary key)
engine=myisam
with system versioning
partition by key() partitions 3;
set timestamp=1523466002.799571;
insert into t1 values (11),(12);
set timestamp=1523466004.169435;
delete from t1 where pk in (11, 12);
--echo Same test but for Aria storage engine
create or replace table t1 (pk int primary key)
engine=aria
with system versioning
partition by key() partitions 3;
set timestamp=1523466002.799571;
insert into t1 values (11),(12);
set timestamp=1523466004.169435;
delete from t1 where pk in (11, 12);

--echo # Test cleanup
drop database test;
create database test;
14 changes: 12 additions & 2 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8687,6 +8687,16 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names)
HA_EXTRA_NO_READCHECK=5 No readcheck on update
HA_EXTRA_READCHECK=6 Use readcheck (def)
HA_EXTRA_REMEMBER_POS:
HA_EXTRA_RESTORE_POS:
System versioning needs this for MyISAM and Aria tables.
On DELETE using PRIMARY KEY:
1) handler::ha_index_read_map() saves rowid used for row delete/update
2) handler::ha_update_row() can rewrite saved rowid
3) handler::ha_delete_row()/handler::ha_update_row() expects saved but got
different rowid and operation fails
Using those flags prevents harmful side effect of 2)
4) Operations only used by temporary tables for query processing
----------------------------------------------------------------
HA_EXTRA_RESET_STATE:
Expand Down Expand Up @@ -8746,8 +8756,6 @@ int ha_partition::change_partitions_to_open(List<String> *partition_names)
Only used MyISAM, only used internally in MyISAM handler, never called
from server level.
HA_EXTRA_KEYREAD_CHANGE_POS:
HA_EXTRA_REMEMBER_POS:
HA_EXTRA_RESTORE_POS:
HA_EXTRA_PRELOAD_BUFFER_SIZE:
HA_EXTRA_CHANGE_KEY_TO_DUP:
HA_EXTRA_CHANGE_KEY_TO_UNIQUE:
Expand Down Expand Up @@ -8830,6 +8838,8 @@ int ha_partition::extra(enum ha_extra_function operation)
case HA_EXTRA_PREPARE_FOR_DROP:
case HA_EXTRA_FLUSH_CACHE:
case HA_EXTRA_PREPARE_FOR_ALTER_TABLE:
case HA_EXTRA_REMEMBER_POS:
case HA_EXTRA_RESTORE_POS:
{
DBUG_RETURN(loop_extra(operation));
}
Expand Down
7 changes: 6 additions & 1 deletion sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ int TABLE::delete_row()

store_record(this, record[1]);
vers_update_end();
return file->ha_update_row(record[1], record[0]);
int res;
if ((res= file->extra(HA_EXTRA_REMEMBER_POS)))
return res;
if ((res= file->ha_update_row(record[1], record[0])))
return res;
return file->extra(HA_EXTRA_RESTORE_POS);
}


Expand Down

0 comments on commit aa5683d

Please sign in to comment.