Skip to content

Commit 8ce5635

Browse files
committed
MDEV-22284 Aria table key read crash because wrong index used
When restoring lastinx last_key.keyinfo must be updated as well. The good example is in _ma_check_index(). The point of failure is extra(HA_EXTRA_NO_KEYREAD) in ha_maria::get_auto_increment(): 1. extra(HA_EXTRA_KEYREAD) saves lastinx; 2. maria_rkey() changes index, so the lastinx and last_key.keyinfo; 3. extra(HA_EXTRA_NO_KEYREAD) restores lastinx but not last_key.keyinfo. So we have discrepancy between lastinx and last_key.keyinfo after 3.
1 parent d0b611a commit 8ce5635

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

mysql-test/suite/maria/maria.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,3 +2850,14 @@ insert into t1 values (8,'0');
28502850
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
28512851
unlock tables;
28522852
drop table t1;
2853+
#
2854+
# MDEV-22284 Aria table key read crash because wrong index used
2855+
#
2856+
create table t1 (
2857+
a int auto_increment,
2858+
b int, c int,
2859+
key(c, a), unique(b)
2860+
) engine aria
2861+
partition by hash (b);
2862+
replace into t1 values (1, 0, 0), (2, 0, 0), (0, 0, 0);
2863+
drop table t1;

mysql-test/suite/maria/maria.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,3 +2093,16 @@ aria_page_checksum=$default_checksum,
20932093
aria_log_file_size=$default_log_file_size;
20942094
--enable_result_log
20952095
--enable_query_log
2096+
2097+
--echo #
2098+
--echo # MDEV-22284 Aria table key read crash because wrong index used
2099+
--echo #
2100+
create table t1 (
2101+
a int auto_increment,
2102+
b int, c int,
2103+
key(c, a), unique(b)
2104+
) engine aria
2105+
partition by hash (b);
2106+
replace into t1 values (1, 0, 0), (2, 0, 0), (0, 0, 0);
2107+
# cleanup
2108+
drop table t1;

storage/maria/ma_extra.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function,
213213
info->last_key.data + share->base.max_key_length*2,
214214
info->save_lastkey_data_length + info->save_lastkey_ref_length);
215215
info->update= info->save_update | HA_STATE_WRITTEN;
216-
info->lastinx= info->save_lastinx;
216+
if (info->lastinx != info->save_lastinx) /* Index changed */
217+
{
218+
info->lastinx = info->save_lastinx;
219+
info->last_key.keyinfo= info->s->keyinfo + info->lastinx;
220+
info->last_key.flag= 0;
221+
info->page_changed=1;
222+
}
217223
info->cur_row.lastpos= info->save_lastpos;
218224
info->last_key.data_length= info->save_lastkey_data_length;
219225
info->last_key.ref_length= info->save_lastkey_ref_length;

0 commit comments

Comments
 (0)