1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-30984 Online ALTER table is denied with non-informative error messages

Group all the checks in online_alter_check_supported().

There is now two groups of checks:
1. A technical availability of online, that is checked before open_tables,
and affects table_list->lock_type. It's supposed to be safe to make it
TL_READ even if COPY algorithm will fall back to not-online, since MDL is
SHARED_UPGRADEABLE anyway.
2. An 'online' availability for a COPY algorithm. It can be done as late as
just before the copy_data_between_tables call. The lock_type influence is
disclosed above, so the only other place it affects is
Alter_info::supports_lock, where `online` flag is only used to decide
whether to report the error at the inplace preparation stage. We'd want to
make that at the last resort, which is COPY preparation, if no algorithm is
chosen by the user. So it's event better now.

Some changes are required to the autoinc support detection, as the check
now happens after mysql_prepare_alter_table:
* alter_info->drop_list is empty
* instead, dropped columns are in tmp_set
* alter_info->create_list now has every field that's in the new table.
* the column definition's change.str will be nonnull whether the column
  remains in the new table (vs whether it was changed, as before).
  But it also has `field` field set.
* IF EXISTS doesn't have to be dealt anymore

This infers that the changes are now checked in more detail: a field's
definition shouldn't be changed, vs a field shouldn't be mentioned in
the CHANGE list, as it was before. This is reflected by the line 193 test.
This commit is contained in:
Nikita Malyavin
2023-05-15 19:39:21 +03:00
committed by Sergei Golubchik
parent b3f988d260
commit c382de72ea
5 changed files with 105 additions and 72 deletions

View File

@ -3,7 +3,7 @@
#
create table t (a int);
alter ignore table t add primary key (a), algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: ALTER IGNORE TABLE. Try LOCK=SHARED
drop table t;
#
# MDEV-28771 Assertion `table->in_use&&tdc->flushed' failed after ALTER
@ -91,13 +91,13 @@ references t1 (a)
on update cascade) engine=InnoDB;
insert into t2 values (1),(2),(3);
alter table t2 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: ON UPDATE CASCADE. Try LOCK=SHARED
alter table t2 add c int, algorithm=inplace, lock=none;
create or replace table t2 (b int, foreign key (b)
references t1 (a)
on delete set null) engine=InnoDB;
alter table t2 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: ON DELETE SET NULL. Try LOCK=SHARED
alter table t2 add c int, algorithm=inplace, lock=none;
create or replace table t2 (b int, foreign key (b)
references t1 (a)
@ -116,7 +116,7 @@ create table t2 (a int references t1 (a),
b int references t1 (b) on update cascade) engine=InnoDB;
insert into t2 values (1, 1),(2, 2);
alter table t2 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: ON UPDATE CASCADE. Try LOCK=SHARED
alter table t2 add c int, algorithm=copy;
alter table t2 add d int, algorithm=inplace;
drop table t2, t1;
@ -131,7 +131,7 @@ row_end bigint unsigned generated always as row end,
period for system_time (row_start, row_end))
engine=innodb with system versioning;
alter table t1 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: BIGINT GENERATED ALWAYS AS ROW_START. Try LOCK=SHARED
alter table t1 add c int, algorithm=inplace;
alter table t1 add d int, lock=none;
set system_versioning_alter_history= default;
@ -142,7 +142,7 @@ drop table t1;
#
create table t (a serial, b int) engine=innodb;
alter table t drop a, modify b serial, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: CHANGE COLUMN ... AUTO_INCREMENT. Try LOCK=SHARED
set statement sql_mode= NO_AUTO_VALUE_ON_ZERO for
alter table t drop a, modify b serial, algorithm=copy, lock=none;
create or replace table t (a serial, b int) engine=innodb;
@ -156,7 +156,7 @@ t CREATE TABLE `t` (
# a is unique in the old table, but is shrunk in the new one.
# Only unsafe approach is fine because of possible collisions.
alter table t modify a int, modify b serial, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: CHANGE COLUMN ... AUTO_INCREMENT. Try LOCK=SHARED
#
# Check that we treat autoinc columns correctly modify old autoinc is
# fine, adding new autoinc for existed column is unsafe.
@ -179,25 +179,27 @@ t CREATE TABLE `t` (
UNIQUE KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
alter table t drop b, change c c serial, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: CHANGE COLUMN ... AUTO_INCREMENT. Try LOCK=SHARED
# Check existed unique keys.
create or replace table t(a int, b int not null, c int not null, d int);
# No unique in the old table;
alter table t add unique(b, c), modify d int auto_increment, add key(d),
algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: CHANGE COLUMN ... AUTO_INCREMENT. Try LOCK=SHARED
alter table t add unique(a, b);
# Unique in the old table has nulls;
alter table t modify d int auto_increment, add key(d),
algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
ERROR 0A000: LOCK=NONE is not supported. Reason: CHANGE COLUMN ... AUTO_INCREMENT. Try LOCK=SHARED
alter table t add unique(b, c);
# Change unique'scolumn;
alter table t change b x int, modify d int auto_increment, add key(d),
# Change unique's column;
alter table t change b x bigint, modify d int auto_increment, add key(d),
algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
# Finally good.
alter table t modify d int auto_increment, add key(d),
ERROR 0A000: LOCK=NONE is not supported. Reason: CHANGE COLUMN ... AUTO_INCREMENT. Try LOCK=SHARED
# Finally good. Simple renames with a type unchanged will not affect
# the result. Also NOT NULL -> NULL transform is fine.
alter table t modify d int auto_increment, add key(d),
change b x int null,
algorithm=copy, lock=none;
drop table t;
# MDEV-31172 Server crash or ASAN errors in online_alter_check_autoinc