diff options
-rw-r--r-- | mysql-test/main/alter_table_lock.result | 20 | ||||
-rw-r--r-- | mysql-test/main/alter_table_lock.test | 21 | ||||
-rw-r--r-- | sql/sql_table.cc | 19 |
3 files changed, 48 insertions, 12 deletions
diff --git a/mysql-test/main/alter_table_lock.result b/mysql-test/main/alter_table_lock.result index 3f6e0eba53f..5a787055478 100644 --- a/mysql-test/main/alter_table_lock.result +++ b/mysql-test/main/alter_table_lock.result @@ -22,6 +22,12 @@ DROP TABLE t1; # create table t1 (f int) engine=innodb; insert t1 values (1); +alter table t1 force, algorithm=copy, lock=none; +alter table t1 force, algorithm=inplace, lock=none; +alter table t1 force, algorithm=copy, lock=shared; +alter table t1 force, algorithm=inplace, lock=shared; +alter table t1 force, algorithm=copy, lock=exclusive; +alter table t1 force, algorithm=inplace, lock=exclusive; lock table t1 write; connect con1, localhost, root; select count(*) as 'must be 0' from t1; @@ -40,5 +46,17 @@ must be 0 connection default; drop table t1; # -# End of 10.10 tests +# MDEV-29056 Replica SQL thread stops with 1846 error on ALTER ONLINE after LOCK WRITE +# +create table t1 (c varchar(1), key (c)) engine=innodb; +insert into t1 (c) values ('g') ; +alter table t1 add fulltext key(c), algorithm=inplace; +alter online table t1 add column s blob not null, algorithm=inplace; +ERROR 0A000: LOCK=NONE is not supported. Reason: Fulltext index creation requires a lock. Try LOCK=SHARED +lock table t1 write; +alter online table t1 add column s blob not null, algorithm=inplace; +ERROR 0A000: LOCK=NONE is not supported. Reason: Fulltext index creation requires a lock. Try LOCK=SHARED +drop table t1; +# +# End of 10.11 tests # diff --git a/mysql-test/main/alter_table_lock.test b/mysql-test/main/alter_table_lock.test index b74f7d48ae6..6fe717f977e 100644 --- a/mysql-test/main/alter_table_lock.test +++ b/mysql-test/main/alter_table_lock.test @@ -39,6 +39,12 @@ DROP TABLE t1; # and that it is ignored, does not actually downgrade the lock create table t1 (f int) engine=innodb; insert t1 values (1); +alter table t1 force, algorithm=copy, lock=none; +alter table t1 force, algorithm=inplace, lock=none; +alter table t1 force, algorithm=copy, lock=shared; +alter table t1 force, algorithm=inplace, lock=shared; +alter table t1 force, algorithm=copy, lock=exclusive; +alter table t1 force, algorithm=inplace, lock=exclusive; lock table t1 write; connect con1, localhost, root; --send select count(*) as 'must be 0' from t1 @@ -57,5 +63,18 @@ unlock tables; drop table t1; --echo # ---echo # End of 10.10 tests +--echo # MDEV-29056 Replica SQL thread stops with 1846 error on ALTER ONLINE after LOCK WRITE +--echo # +create table t1 (c varchar(1), key (c)) engine=innodb; +insert into t1 (c) values ('g') ; +alter table t1 add fulltext key(c), algorithm=inplace; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +alter online table t1 add column s blob not null, algorithm=inplace; +lock table t1 write; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +alter online table t1 add column s blob not null, algorithm=inplace; +drop table t1; + +--echo # +--echo # End of 10.11 tests --echo # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 3fde2d1f2d3..91d1354a6b7 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9904,7 +9904,6 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, if (alter_info->requested_lock > Alter_info::ALTER_TABLE_LOCK_NONE || alter_info->flags & ALTER_DROP_SYSTEM_VERSIONING - || thd->locked_tables_mode == LTM_LOCK_TABLES || thd->lex->sql_command == SQLCOM_OPTIMIZE || ignore || alter_info->algorithm(thd) > Alter_info::ALTER_TABLE_ALGORITHM_COPY) @@ -10035,16 +10034,13 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, set of tables from the old table or to open a new TABLE object for an extended list and verify that they belong to locked tables. */ - if (thd->locked_tables_mode == LTM_LOCK_TABLES || - thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES) + if ((thd->locked_tables_mode == LTM_LOCK_TABLES || + thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES) && + (create_info->used_fields & HA_CREATE_USED_UNION) && + (table->s->tmp_table == NO_TMP_TABLE)) { - if ((create_info->used_fields & HA_CREATE_USED_UNION) && - (table->s->tmp_table == NO_TMP_TABLE)) - { - my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); - DBUG_RETURN(true); - } - alter_info->requested_lock= Alter_info::ALTER_TABLE_LOCK_DEFAULT; + my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0)); + DBUG_RETURN(true); } /* Check that we are not trying to rename to an existing table */ @@ -10767,6 +10763,9 @@ do_continue:; goto err_new_table_cleanup; } + if (thd->locked_tables_mode == LTM_LOCK_TABLES) + online= false; + // If EXCLUSIVE lock is requested, upgrade already. if (alter_info->requested_lock == Alter_info::ALTER_TABLE_LOCK_EXCLUSIVE && wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN)) |