From fa4d8a1baaa09e9de8494595ddbab320a831503a Mon Sep 17 00:00:00 2001 From: Michal Jankowski Date: Mon, 29 Jun 2026 16:07:32 +0200 Subject: [PATCH] PS-10452 [8.4] Thread status for DROP TABLE Added 2 stages, analogically to CREATE TABLE: - stage/sql/dropping table - stage/sql/after drop --- mysql-test/r/profiling.result | 25 ++++++++++ .../perfschema/r/create_drop_table.result | 47 +++++++++++++++++++ .../perfschema/t/create_drop_table-master.opt | 1 + .../suite/perfschema/t/create_drop_table.test | 6 +++ mysql-test/t/profiling.test | 1 + sql/mysqld.cc | 4 ++ sql/mysqld.h | 2 + sql/sql_table.cc | 3 +- 8 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/perfschema/r/create_drop_table.result create mode 100644 mysql-test/suite/perfschema/t/create_drop_table-master.opt create mode 100644 mysql-test/suite/perfschema/t/create_drop_table.test diff --git a/mysql-test/r/profiling.result b/mysql-test/r/profiling.result index d702126d99c7..4eb60e3f7eb1 100644 --- a/mysql-test/r/profiling.result +++ b/mysql-test/r/profiling.result @@ -413,6 +413,31 @@ select @@profiling; @@profiling 1 drop table if exists t2, t1, t3; +select QUERY_ID, SEQ, STATE from INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = (select max(QUERY_ID) from INFORMATION_SCHEMA.PROFILING) order by SEQ; +QUERY_ID SEQ STATE +105 2 starting +105 3 Executing hook on transaction +105 4 starting +105 5 waiting for handler commit +105 6 checking permissions +105 7 checking permissions +105 8 checking permissions +105 9 dropping table +105 10 after drop +105 11 dropping table +105 12 after drop +105 13 dropping table +105 14 after drop +105 15 waiting for handler commit +105 16 waiting for handler commit +105 17 query end +105 18 closing tables +105 19 waiting for handler commit +105 20 freeing items +105 21 cleaning up +Warnings: +Warning 1287 'INFORMATION_SCHEMA.PROFILING' is deprecated and will be removed in a future release. Please use Performance Schema instead +Warning 1287 'INFORMATION_SCHEMA.PROFILING' is deprecated and will be removed in a future release. Please use Performance Schema instead drop view if exists v1; Warnings: Note 1051 Unknown table 'test.v1' diff --git a/mysql-test/suite/perfschema/r/create_drop_table.result b/mysql-test/suite/perfschema/r/create_drop_table.result new file mode 100644 index 000000000000..062733780b86 --- /dev/null +++ b/mysql-test/suite/perfschema/r/create_drop_table.result @@ -0,0 +1,47 @@ +TRUNCATE TABLE performance_schema.events_stages_history_long; +CREATE TABLE test.t1(a int); +DROP TABLE test.t1; +SELECT EVENT_NAME FROM performance_schema.events_stages_history_long ORDER BY EVENT_ID; +EVENT_NAME +stage/sql/System lock +stage/sql/waiting for handler commit +stage/sql/query end +stage/sql/closing tables +stage/sql/waiting for handler commit +stage/sql/freeing items +stage/sql/cleaning up +stage/sql/starting +stage/sql/Executing hook on transaction begin. +stage/sql/starting +stage/sql/checking permissions +stage/sql/Opening tables +stage/sql/creating table +stage/sql/After create +stage/sql/waiting for handler commit +stage/sql/waiting for handler commit +stage/sql/query end +stage/sql/closing tables +stage/sql/waiting for handler commit +stage/sql/freeing items +stage/sql/cleaning up +stage/sql/starting +stage/sql/Executing hook on transaction begin. +stage/sql/starting +stage/sql/checking permissions +stage/sql/dropping table +stage/sql/after drop +stage/sql/waiting for handler commit +stage/sql/waiting for handler commit +stage/sql/query end +stage/sql/closing tables +stage/sql/waiting for handler commit +stage/sql/freeing items +stage/sql/cleaning up +stage/sql/starting +stage/sql/checking permissions +stage/sql/Opening tables +stage/sql/init +stage/sql/System lock +stage/sql/optimizing +stage/sql/statistics +stage/sql/preparing diff --git a/mysql-test/suite/perfschema/t/create_drop_table-master.opt b/mysql-test/suite/perfschema/t/create_drop_table-master.opt new file mode 100644 index 000000000000..0f5979cbd072 --- /dev/null +++ b/mysql-test/suite/perfschema/t/create_drop_table-master.opt @@ -0,0 +1 @@ +--loose-performance-schema-instrument='stage/sql/%=COUNTED' \ No newline at end of file diff --git a/mysql-test/suite/perfschema/t/create_drop_table.test b/mysql-test/suite/perfschema/t/create_drop_table.test new file mode 100644 index 000000000000..d16cd3bf9017 --- /dev/null +++ b/mysql-test/suite/perfschema/t/create_drop_table.test @@ -0,0 +1,6 @@ +TRUNCATE TABLE performance_schema.events_stages_history_long; + +CREATE TABLE test.t1(a int); +DROP TABLE test.t1; + +SELECT EVENT_NAME FROM performance_schema.events_stages_history_long ORDER BY EVENT_ID; \ No newline at end of file diff --git a/mysql-test/t/profiling.test b/mysql-test/t/profiling.test index bd8ef012c8a9..2229d8bafd57 100644 --- a/mysql-test/t/profiling.test +++ b/mysql-test/t/profiling.test @@ -298,6 +298,7 @@ select @@profiling; --enable_warnings drop table if exists t2, t1, t3; +select QUERY_ID, SEQ, STATE from INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID = (select max(QUERY_ID) from INFORMATION_SCHEMA.PROFILING) order by SEQ; drop view if exists v1; drop function if exists f1; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5ca85725e42d..0ed429bbfe1e 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -15119,6 +15119,7 @@ static PSI_file_info all_server_files[]= /* clang-format off */ PSI_stage_info stage_after_create= { 0, "After create", 0, PSI_DOCUMENT_ME}; +PSI_stage_info stage_after_drop= { 0, "after drop", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_alter_inplace_prepare= { 0, "preparing for alter table", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_alter_inplace= { 0, "altering table", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_alter_inplace_commit= { 0, "committing alter table to storage engine", 0, PSI_DOCUMENT_ME}; @@ -15136,6 +15137,7 @@ PSI_stage_info stage_creating_tmp_table= { 0, "Creating tmp table", 0, PSI_DOCUM PSI_stage_info stage_deleting_from_main_table= { 0, "deleting from main table", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_deleting_from_reference_tables= { 0, "deleting from reference tables", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_discard_or_import_tablespace= { 0, "discard_or_import_tablespace", 0, PSI_DOCUMENT_ME}; +PSI_stage_info stage_dropping_table= { 0, "dropping table", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_end= { 0, "end", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_executing= { 0, "executing", 0, PSI_DOCUMENT_ME}; PSI_stage_info stage_execution_of_init_command= { 0, "Execution of init_command", 0, PSI_DOCUMENT_ME}; @@ -15224,6 +15226,7 @@ extern PSI_stage_info stage_waiting_for_disk_space; PSI_stage_info *all_server_stages[] = { &stage_after_create, + &stage_after_drop, &stage_alter_inplace_prepare, &stage_alter_inplace, &stage_alter_inplace_commit, @@ -15241,6 +15244,7 @@ PSI_stage_info *all_server_stages[] = { &stage_deleting_from_main_table, &stage_deleting_from_reference_tables, &stage_discard_or_import_tablespace, + &stage_dropping_table, &stage_end, &stage_executing, &stage_execution_of_init_command, diff --git a/sql/mysqld.h b/sql/mysqld.h index b6aba36d4a40..0781746df9fc 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -585,6 +585,7 @@ extern PSI_socket_key key_socket_client_connection; Hint: grep PSI_stage_info | sort -u */ extern PSI_stage_info stage_after_create; +extern PSI_stage_info stage_after_drop; extern PSI_stage_info stage_alter_inplace_prepare; extern PSI_stage_info stage_alter_inplace; extern PSI_stage_info stage_alter_inplace_commit; @@ -602,6 +603,7 @@ extern PSI_stage_info stage_creating_tmp_table; extern PSI_stage_info stage_deleting_from_main_table; extern PSI_stage_info stage_deleting_from_reference_tables; extern PSI_stage_info stage_discard_or_import_tablespace; +extern PSI_stage_info stage_dropping_table; extern PSI_stage_info stage_end; extern PSI_stage_info stage_executing; extern PSI_stage_info stage_execution_of_init_command; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index faaf57304faf..b9a82fbd0b59 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2972,6 +2972,7 @@ static bool drop_base_table(THD *thd, const Drop_tables_ctx &drop_ctx, Foreign_key_parents_invalidator *fk_invalidator, std::vector *safe_to_release_mdl, MEM_ROOT *foreach_table_root) { + THD_STAGE_INFO(thd, stage_dropping_table); char path[FN_REFLEN + 1]; /* Check that we have an exclusive lock on the table to be dropped. */ @@ -3253,7 +3254,7 @@ static bool drop_base_table(THD *thd, const Drop_tables_ctx &drop_ctx, result |= mark_referencing_views_invalid(thd, table, (drop_ctx.drop_database && atomic), !atomic, foreach_table_root); - + THD_STAGE_INFO(thd, stage_after_drop); return result; }