diff --git a/mysql-test/main/alter_table_online.result b/mysql-test/main/alter_table_online.result index 7928222a428..c8c0c782115 100644 --- a/mysql-test/main/alter_table_online.result +++ b/mysql-test/main/alter_table_online.result @@ -238,3 +238,33 @@ ERROR 0A000: LOCK=NONE is not supported. Reason: Function or expression 'NEXTVAL drop table t2; drop table t1; drop sequence s; +# +# MDEV-33348 ALTER TABLE lock waiting stages are indistinguishable +# +connect con2, localhost, root,,; +create or replace table t1 (a int); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +insert t1 values (5); +connection con2; +begin; +select * from t1; +a +5 +connection default; +alter table t1 add b int NULL, algorithm= copy, lock= none; +connection con2; +select stage, state, info from information_schema.processlist where id = @con; +stage 4 +state Waiting for table metadata lock +info alter table t1 add b int NULL, algorithm= copy, lock= none +rollback; +connection default; +drop table t1; +disconnect con2; +# +# End of 11.2 tests +# diff --git a/mysql-test/main/alter_table_online.test b/mysql-test/main/alter_table_online.test index 35e01054890..f0d70b05884 100644 --- a/mysql-test/main/alter_table_online.test +++ b/mysql-test/main/alter_table_online.test @@ -246,3 +246,45 @@ alter table t2 modify b int not null default (nextval(s)), lock=none; drop table t2; drop table t1; drop sequence s; + +--echo # +--echo # MDEV-33348 ALTER TABLE lock waiting stages are indistinguishable +--echo # +--connect (con2, localhost, root,,) + +create or replace table t1 (a int); +show create table t1; +insert t1 values (5); + +--connection con2 +begin; +select * from t1; +--connection default +--let $con= `select connection_id()` +send alter table t1 add b int NULL, algorithm= copy, lock= none; + + +--connection con2 +disable_query_log; +eval set @con= $con; +enable_query_log; + + +let $wait_condition= select stage = 4 and progress = 100 + and state= "Waiting for table metadata lock" + from information_schema.processlist where id = @con; +--source include/wait_condition.inc + +query_vertical select stage, state, info from information_schema.processlist where id = @con; + +rollback; + +--connection default +reap; + +drop table t1; +--disconnect con2 + +--echo # +--echo # End of 11.2 tests +--echo # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 788f6e19679..2c0f01a5a57 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -11364,6 +11364,15 @@ do_continue:; new_table->mark_columns_needed_for_insert(); mysql_bin_log.write_table_map(thd, new_table, 1); } + + /* + if ORDER BY: sorting + always: copying, building indexes. + if online: reading up the binlog (second binlog is being written) + reading up the second binlog under exclusive lock + */ + thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online)); + if (copy_data_between_tables(thd, table, new_table, ignore, order_num, order, &copied, &deleted, @@ -11532,6 +11541,8 @@ do_continue:; NULL); table_list->table= table= NULL; /* Safety */ + thd_progress_end(thd); + DBUG_PRINT("info", ("is_table_renamed: %d engine_changed: %d", alter_ctx.is_table_renamed(), engine_changed)); @@ -11761,6 +11772,8 @@ err_new_table_cleanup: DBUG_PRINT("error", ("err_new_table_cleanup")); thd->variables.option_bits&= ~OPTION_BIN_COMMIT_OFF; + thd_progress_end(thd); + /* No default value was provided for a DATE/DATETIME field, the current sql_mode doesn't allow the '0000-00-00' value and @@ -11890,7 +11903,7 @@ static int online_alter_read_from_binlog(THD *thd, rpl_group_info *rgi, IO_CACHE *log_file= log->flip(); - thd_progress_report(thd, 0, my_b_write_tell(log_file)); + thd_progress_report(thd, 1, MY_MAX(1, my_b_write_tell(log_file))); Has_default_error_handler hdeh; thd->push_internal_handler(&hdeh); @@ -11957,14 +11970,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, MYSQL_TIME query_start; DBUG_ENTER("copy_data_between_tables"); - /* - if ORDER BY: sorting - always: copying, building indexes. - if online: reading up the binlog (second binlog is being written) - reading up the second binlog under exclusive lock - */ - thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online)); - if (!(copy= new (thd->mem_root) Copy_field[to->s->fields])) DBUG_RETURN(-1); @@ -12431,7 +12436,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, if (error < 0 && !from->s->tmp_table && to->file->extra(HA_EXTRA_PREPARE_FOR_RENAME)) error= 1; - thd_progress_end(thd); DBUG_RETURN(error > 0 ? -1 : 0); }