diff --git a/sql/log_event.cc b/sql/log_event.cc index 6610c436302..b68d6c1fbc3 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -41,6 +41,7 @@ #include "transaction.h" #include #include "sql_show.h" // append_identifier +#include #include #include "compat56.h" @@ -4272,6 +4273,13 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, Parser_state parser_state; if (!parser_state.init(thd, thd->query(), thd->query_length())) { + thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state, + stmt_info_rpl.m_key, + thd->db, thd->db_length, + thd->charset()); + THD_STAGE_INFO(thd, stage_init); + MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(), thd->query_length()); + mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); /* Finalize server status flags after executing a statement. */ thd->update_server_status(); @@ -4455,6 +4463,11 @@ end: thd->set_db(NULL, 0); /* will free the current database */ thd->reset_query(); DBUG_PRINT("info", ("end: query= 0")); + + /* Mark the statement completed. */ + MYSQL_END_STATEMENT(thd->m_statement_psi, thd->get_stmt_da()); + thd->m_statement_psi= NULL; + /* As a disk space optimization, future masters will not log an event for LAST_INSERT_ID() if that function returned 0 (and thus they will be able diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 438c56659b0..a9ee5890fdf 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -338,6 +338,13 @@ static PSI_rwlock_key key_rwlock_openssl; volatile sig_atomic_t ld_assume_kernel_is_set= 0; #endif +/** + Statement instrumentation key for replication. +*/ +#ifdef HAVE_PSI_STATEMENT_INTERFACE +PSI_statement_info stmt_info_rpl; +#endif + /* the default log output is log tables */ static bool lower_case_table_names_used= 0; static bool max_long_data_size_used= false; @@ -3791,7 +3798,7 @@ void init_com_statement_info() com_statement_info[index].m_flags= 0; } - /* "statement/com/query" can mutate into "statement/sql/..." */ + /* "statement/abstract/query" can mutate into "statement/sql/..." */ com_statement_info[(uint) COM_QUERY].m_flags= PSI_FLAG_MUTABLE; } #endif @@ -9617,23 +9624,49 @@ void init_server_psi_keys(void) category= "com"; init_com_statement_info(); - count= array_elements(com_statement_info); + + /* + Register [0 .. COM_QUERY - 1] as "statement/com/..." + */ + count= (int) COM_QUERY; mysql_statement_register(category, com_statement_info, count); + /* + Register [COM_QUERY + 1 .. COM_END] as "statement/com/..." + */ + count= (int) COM_END - (int) COM_QUERY; + mysql_statement_register(category, & com_statement_info[(int) COM_QUERY + 1], count); + + category= "abstract"; + /* + Register [COM_QUERY] as "statement/abstract/com_query" + */ + mysql_statement_register(category, & com_statement_info[(int) COM_QUERY], 1); + /* When a new packet is received, - it is instrumented as "statement/com/". + it is instrumented as "statement/abstract/new_packet". Based on the packet type found, it later mutates to the proper narrow type, for example - "statement/com/query" or "statement/com/ping". - In cases of "statement/com/query", SQL queries are given to + "statement/abstract/query" or "statement/com/ping". + In cases of "statement/abstract/query", SQL queries are given to the parser, which mutates the statement type to an even more narrow classification, for example "statement/sql/select". */ stmt_info_new_packet.m_key= 0; - stmt_info_new_packet.m_name= ""; + stmt_info_new_packet.m_name= "new_packet"; stmt_info_new_packet.m_flags= PSI_FLAG_MUTABLE; - mysql_statement_register(category, & stmt_info_new_packet, 1); + mysql_statement_register(category, &stmt_info_new_packet, 1); + + /* + Statements processed from the relay log are initially instrumented as + "statement/abstract/relay_log". The parser will mutate the statement type to + a more specific classification, for example "statement/sql/insert". + */ + stmt_info_rpl.m_key= 0; + stmt_info_rpl.m_name= "relay_log"; + stmt_info_rpl.m_flags= PSI_FLAG_MUTABLE; + mysql_statement_register(category, &stmt_info_rpl, 1); #endif } diff --git a/sql/mysqld.h b/sql/mysqld.h index 0e3af959122..09f886bff01 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -461,6 +461,11 @@ extern PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1]; */ extern PSI_statement_info com_statement_info[(uint) COM_END + 1]; +/** + Statement instrumentation key for replication. +*/ +extern PSI_statement_info stmt_info_rpl; + void init_sql_statement_info(); void init_com_statement_info(); #endif /* HAVE_PSI_STATEMENT_INTERFACE */ diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 44f47646e38..b772c82ef52 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -287,14 +287,15 @@ static Sys_var_long Sys_pfs_events_stages_history_size( - 1 for "statement/com/new_packet", for unknown enum_server_command - 1 for "statement/com/Error", for invalid enum_server_command - SQLCOM_END for all regular "statement/sql/...", - - 1 for "statement/sql/error", for invalid enum_sql_command. + - 1 for "statement/sql/error", for invalid enum_sql_command + - 1 for "statement/rpl/relay_log", for replicated statements. */ static Sys_var_ulong Sys_pfs_max_statement_classes( "performance_schema_max_statement_classes", "Maximum number of statement instruments.", PARSED_EARLY READ_ONLY GLOBAL_VAR(pfs_param.m_statement_class_sizing), CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256), - DEFAULT((ulong) SQLCOM_END + (ulong) COM_END + 3), + DEFAULT((ulong) SQLCOM_END + (ulong) COM_END + 4), BLOCK_SIZE(1)); static Sys_var_long Sys_pfs_events_statements_history_long_size(