mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 21:55:03 +02:00

MDEV-33658 part 1’s refactoring ecaedbe299
introduced a new function init_key_info which (in part) aims to
calculate the total key length; however, it doesn’t account for the
key already having been initialized (as happens when called via
ALTER TABLE .. CONVERT PARTITION .. TO TABLE). This leads to crashes
when this key is later iterated over, because the iterator will try
to iterate over additional key parts which don’t exist because the
length reports as longer than the actual memory owned. The crash
reported by MDEV-36906 highlights this in function key_copy.
To explain how the keys already have been initialized, init_key_info
is called multiple times. That is, init_key_info is called from
mysql_prepare_create_table, which prepares a table and its key
structures for table creation, which is in turn called by
mysql_write_frm when using flags MFRM_WRITE_SHADOW and
MFRM_WRITE_CONVERTED_TO. The
ALTER TABLE .. CONVERT PARTITION .. TO TABLE use case (see function
fast_alter_partition_table), calls mysql_write_frm multiple times with
both of these flags set (first with MFRM_WRITE_CONVERTED_TO and then
with MFRM_WRITE_SHADOW).
Raising it up a level, mysql_prepare_create_table doesn't need to be
called again after it has already been invoked when just writing frms.
Init_key_info is the only place in that function which leads to side
effects, but the rest is redundant and can be skipped on the second
call (i.e. when writing the shadow).
The patch fixes this by skipping the call to mysql_prepare_create_table
in mysql_write_frm in the MFRM_WRITE_SHADOW block when it has already
been called previously. To track whether or not it has been previously
called, we add a new flag for the mysql_write_frm function,
MFRM_ALTER_INFO_PREPARED, which is hard-coded into the function call on
the later invocation.
Test case based on work by Elena Stepanova <elenst@mariadb.com>
Reviewed By:
============
Sergei Golubchik <serg@mariadb.org>
Nikita Malyavin <nikita.malyavin@mariadb.com>
117 lines
3.5 KiB
Text
117 lines
3.5 KiB
Text
#
|
|
# This test ensures that ALTER TABLE ... CONVERT PARTITION ... TO TABLE
|
|
# works with replication. I.e., the partitioning is done correctly, and
|
|
# after partitioning, both tables can be updated correctly.
|
|
#
|
|
# References:
|
|
# MDEV-36906: RBR crashes upon DML after CONVERT PARTITION
|
|
#
|
|
|
|
--source include/have_innodb.inc
|
|
--source include/have_partition.inc
|
|
--source include/master-slave.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure initial CREATE TABLE with partitioned data is replicated
|
|
--echo # correctly
|
|
--connection master
|
|
create table t (a int, b int, key(a)) engine=innodb partition by range (b) (partition p1 values less than (10), partition pn values less than (maxvalue));
|
|
insert into t values (1,5),(2,100);
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.t,slave:test.t
|
|
|
|
--source include/diff_tables.inc
|
|
|
|
--echo #
|
|
--echo # Ensure ALTER TABLE .. CONVERT PARTITION .. TO TABLE replicates
|
|
--echo # correctly
|
|
--connection master
|
|
alter table t convert partition p1 to table offspring;
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.t,slave:test.t
|
|
--source include/diff_tables.inc
|
|
--let $diff_tables=master:test.offspring,slave:test.offspring
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure data can be inserted into existing table after
|
|
--echo # ALTER TABLE .. CONVERT PARTITION .. TO TABLE
|
|
--connection master
|
|
insert into t values (3, 6);
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.t,slave:test.t
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure data can be inserted into offspring table after
|
|
--echo # ALTER TABLE .. CONVERT PARTITION .. TO TABLE
|
|
--connection master
|
|
insert into offspring values (4, 101);
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.offspring,slave:test.offspring
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure data can be updated in existing table after
|
|
--echo # ALTER TABLE .. CONVERT PARTITION .. TO TABLE
|
|
--connection master
|
|
update t set b=b+1 where a=3;
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.t,slave:test.t
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure data can be updated in offspring table after
|
|
--echo # ALTER TABLE .. CONVERT PARTITION .. TO TABLE
|
|
--connection master
|
|
update offspring set b=b+1 where a=4;
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.offspring,slave:test.offspring
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure data can be deleted in existing table after
|
|
--echo # ALTER TABLE .. CONVERT PARTITION .. TO TABLE
|
|
--connection master
|
|
delete from t;
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.t,slave:test.t
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--echo #
|
|
--echo # Ensure data can be deleted in offspring table after
|
|
--echo # ALTER TABLE .. CONVERT PARTITION .. TO TABLE
|
|
--connection master
|
|
delete from offspring;
|
|
--source include/save_master_gtid.inc
|
|
--connection slave
|
|
--source include/sync_with_master_gtid.inc
|
|
--let $diff_tables=master:test.offspring,slave:test.offspring
|
|
--source include/diff_tables.inc
|
|
|
|
|
|
--connection master
|
|
drop table t, offspring;
|
|
--source include/rpl_end.inc
|
|
--echo # End of rpl_alter_convert_partition
|