Commit 8ce5635a authored by Aleksey Midenkov's avatar Aleksey Midenkov

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.
parent d0b611a7
......@@ -2850,3 +2850,14 @@ insert into t1 values (8,'0');
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
unlock tables;
drop table t1;
#
# MDEV-22284 Aria table key read crash because wrong index used
#
create table t1 (
a int auto_increment,
b int, c int,
key(c, a), unique(b)
) engine aria
partition by hash (b);
replace into t1 values (1, 0, 0), (2, 0, 0), (0, 0, 0);
drop table t1;
......@@ -2093,3 +2093,16 @@ aria_page_checksum=$default_checksum,
aria_log_file_size=$default_log_file_size;
--enable_result_log
--enable_query_log
--echo #
--echo # MDEV-22284 Aria table key read crash because wrong index used
--echo #
create table t1 (
a int auto_increment,
b int, c int,
key(c, a), unique(b)
) engine aria
partition by hash (b);
replace into t1 values (1, 0, 0), (2, 0, 0), (0, 0, 0);
# cleanup
drop table t1;
......@@ -213,7 +213,13 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function,
info->last_key.data + share->base.max_key_length*2,
info->save_lastkey_data_length + info->save_lastkey_ref_length);
info->update= info->save_update | HA_STATE_WRITTEN;
info->lastinx= info->save_lastinx;
if (info->lastinx != info->save_lastinx) /* Index changed */
{
info->lastinx = info->save_lastinx;
info->last_key.keyinfo= info->s->keyinfo + info->lastinx;
info->last_key.flag= 0;
info->page_changed=1;
}
info->cur_row.lastpos= info->save_lastpos;
info->last_key.data_length= info->save_lastkey_data_length;
info->last_key.ref_length= info->save_lastkey_ref_length;
......
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