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..a72cdd4a6f24 --- /dev/null +++ b/mysql-test/suite/perfschema/r/create_drop_table.result @@ -0,0 +1,89 @@ +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 +TRUNCATE TABLE performance_schema.events_stages_history_long; +CREATE TEMPORARY 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/query end +stage/sql/closing tables +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/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..03d096d1ba8a --- /dev/null +++ b/mysql-test/suite/perfschema/t/create_drop_table.test @@ -0,0 +1,13 @@ +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; + +TRUNCATE TABLE performance_schema.events_stages_history_long; + +CREATE TEMPORARY 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 f0f91d3666fa..21f5fb5abe8d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -14780,6 +14780,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}; @@ -14797,6 +14798,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}; @@ -14885,6 +14887,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, @@ -14902,6 +14905,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 f618195df753..ea5a70ed4a79 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -579,6 +579,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; @@ -596,6 +597,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_base.cc b/sql/sql_base.cc index 29558bd43b32..9977cb2811e3 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2432,6 +2432,8 @@ void drop_temporary_table(THD *thd, Table_ref *table_list) { assert(!table->query_id || table->query_id == thd->query_id); + THD_STAGE_INFO(thd, stage_dropping_table); + /* If LOCK TABLES list is not empty and contains this table, unlock the table and remove the table from this list. @@ -2439,6 +2441,7 @@ void drop_temporary_table(THD *thd, Table_ref *table_list) { mysql_lock_remove(thd, thd->lock, table); close_temporary_table(thd, table, true, true); table_list->table = nullptr; + THD_STAGE_INFO(thd, stage_after_drop); } /* diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 85769243f7ce..1ebe05bc2208 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2882,6 +2882,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. */ @@ -3163,7 +3164,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; }