mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to I_S and processlist
MDEV-32441 SENT_ROWS shows random wrong values when stored function is selected. MDEV-32281 EXAMINED_ROWS is not populated in information_schema.processlist upon SELECT. Added ROWS_SENT to information_schema.processlist This is to have the same information as Percona server (SENT_ROWS) To ensure that information_schema.processlist has correct values for sent_rows and examined_rows I introduced two new variables to hold the total counts so far. This was needed as stored functions and stored procedures will reset the normal counters to be able to count rows for each statement individually for slow query log. Other things: - Selects with functions shows in processlist the total examined_rows and sent_rows by the main statement and all functions. - Stored procedures shows in processlist examined_rows and sent_rows per stored procedure statement. - Fixed some double accounting for sent_rows and examined_rows. - HANDLER operations now also supports send_rows and examined_rows. - Display sizes for MEMORY_USED, MAX_MEMORY_USED, EXAMINED_ROWS and QUERY_ID in information_schema.processlist changed to 10 characters. - EXAMINED_ROWS and SENT_ROWS changed to bigint. - INSERT RETURNING and DELETE RETURNING now updates SENT_ROWS. - As thd is always up to date with examined_rows, we do not need to handle examined row counting for unions or filesort. - I renamed SORT_INFO::examined_rows to m_examined_rows to ensure that we don't get bugs in merges that tries to use examined_rows. - Removed calls of type "thd->set_examined_row_count(0)" as they are not needed anymore. - Removed JOIN::join_examined_rows - Removed not used functions: THD::set_examined_row_count() - Made inline some functions that where called for each row.
This commit is contained in:
@@ -641,7 +641,10 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
|
||||
current_stmt_binlog_format(BINLOG_FORMAT_MIXED),
|
||||
bulk_param(0),
|
||||
table_map_for_update(0),
|
||||
m_sent_row_count(0),
|
||||
sent_row_count_for_statement(0),
|
||||
m_examined_row_count(0),
|
||||
examined_row_count_for_statement(0),
|
||||
accessed_rows_and_keys(0),
|
||||
m_digest(NULL),
|
||||
m_statement_psi(NULL),
|
||||
@@ -777,7 +780,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
|
||||
my_hash_clear(&ull_hash);
|
||||
tmp_table=0;
|
||||
cuted_fields= 0L;
|
||||
m_sent_row_count= 0L;
|
||||
limit_found_rows= 0;
|
||||
m_row_count_func= -1;
|
||||
statement_id_counter= 0UL;
|
||||
@@ -5823,7 +5825,7 @@ void THD::reset_sub_statement_state(Sub_statement_state *backup,
|
||||
cuted_fields= 0;
|
||||
transaction->savepoints= 0;
|
||||
first_successful_insert_id_in_cur_stmt= 0;
|
||||
reset_slow_query_state();
|
||||
reset_slow_query_state(backup);
|
||||
}
|
||||
|
||||
void THD::restore_sub_statement_state(Sub_statement_state *backup)
|
||||
@@ -5865,11 +5867,14 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup)
|
||||
first_successful_insert_id_in_cur_stmt=
|
||||
backup->first_successful_insert_id_in_cur_stmt;
|
||||
limit_found_rows= backup->limit_found_rows;
|
||||
set_sent_row_count(backup->sent_row_count);
|
||||
client_capabilities= backup->client_capabilities;
|
||||
|
||||
/* Restore statistic needed for slow log */
|
||||
add_slow_query_state(backup);
|
||||
if (backup->sent_row_count)
|
||||
MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, m_sent_row_count);
|
||||
if (backup->examined_row_count)
|
||||
MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
|
||||
|
||||
/*
|
||||
If we've left sub-statement mode, reset the fatal error flag.
|
||||
@@ -5903,18 +5908,20 @@ void THD::store_slow_query_state(Sub_statement_state *backup)
|
||||
backup->affected_rows= affected_rows;
|
||||
backup->bytes_sent_old= bytes_sent_old;
|
||||
backup->examined_row_count= m_examined_row_count;
|
||||
backup->examined_row_count_for_statement= examined_row_count_for_statement;
|
||||
backup->query_plan_flags= query_plan_flags;
|
||||
backup->query_plan_fsort_passes= query_plan_fsort_passes;
|
||||
backup->sent_row_count= m_sent_row_count;
|
||||
backup->sent_row_count_for_statement= sent_row_count_for_statement;
|
||||
backup->tmp_tables_disk_used= tmp_tables_disk_used;
|
||||
backup->tmp_tables_size= tmp_tables_size;
|
||||
backup->tmp_tables_used= tmp_tables_used;
|
||||
backup->handler_stats= handler_stats;
|
||||
backup->handler_stats= handler_stats;
|
||||
}
|
||||
|
||||
/* Reset variables related to slow query log */
|
||||
|
||||
void THD::reset_slow_query_state()
|
||||
void THD::reset_slow_query_state(Sub_statement_state *backup)
|
||||
{
|
||||
affected_rows= 0;
|
||||
bytes_sent_old= status_var.bytes_sent;
|
||||
@@ -5925,6 +5932,17 @@ void THD::reset_slow_query_state()
|
||||
tmp_tables_disk_used= 0;
|
||||
tmp_tables_size= 0;
|
||||
tmp_tables_used= 0;
|
||||
if (backup && (backup->in_stored_procedure= in_stored_procedure()))
|
||||
{
|
||||
/*
|
||||
For stored procedures, we want to see stats in show processlist
|
||||
for the current statement, not for the call to stored procedure.
|
||||
This is because 'show processlist' shows the stored procedure
|
||||
query string, not the CALL query.
|
||||
*/
|
||||
examined_row_count_for_statement= 0;
|
||||
sent_row_count_for_statement= 0;
|
||||
}
|
||||
if ((variables.log_slow_verbosity & LOG_SLOW_VERBOSITY_ENGINE))
|
||||
handler_stats.reset();
|
||||
}
|
||||
@@ -5945,6 +5963,17 @@ void THD::add_slow_query_state(Sub_statement_state *backup)
|
||||
tmp_tables_disk_used+= backup->tmp_tables_disk_used;
|
||||
tmp_tables_size+= backup->tmp_tables_size;
|
||||
tmp_tables_used+= backup->tmp_tables_used;
|
||||
if (backup->in_stored_procedure)
|
||||
{
|
||||
/*
|
||||
For stored procedures, we want to see stats in show processlist
|
||||
for the current statement, not for the call to stored procedure.
|
||||
This is because 'show processlist' shows the stored procedure
|
||||
query string, not the CALL query.
|
||||
*/
|
||||
examined_row_count_for_statement+= backup->examined_row_count_for_statement;
|
||||
sent_row_count_for_statement+= backup->sent_row_count_for_statement;
|
||||
}
|
||||
if ((variables.log_slow_verbosity & LOG_SLOW_VERBOSITY_ENGINE))
|
||||
handler_stats.add(&backup->handler_stats);
|
||||
}
|
||||
@@ -5957,30 +5986,21 @@ void THD::set_statement(Statement *stmt)
|
||||
mysql_mutex_unlock(&LOCK_thd_data);
|
||||
}
|
||||
|
||||
/*
|
||||
This functions is only called when we send the result from the query
|
||||
cache or in case of select_export().
|
||||
*/
|
||||
void THD::set_sent_row_count(ha_rows count)
|
||||
{
|
||||
m_sent_row_count= count;
|
||||
sent_row_count_for_statement+= count;
|
||||
MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, m_sent_row_count);
|
||||
}
|
||||
|
||||
void THD::set_examined_row_count(ha_rows count)
|
||||
void THD::ps_report_examined_row_count()
|
||||
{
|
||||
m_examined_row_count= count;
|
||||
MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
|
||||
}
|
||||
|
||||
void THD::inc_sent_row_count(ha_rows count)
|
||||
{
|
||||
m_sent_row_count+= count;
|
||||
DBUG_EXECUTE_IF("debug_huge_number_of_examined_rows",
|
||||
m_examined_row_count= (ULONGLONG_MAX - 1000000););
|
||||
MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, m_sent_row_count);
|
||||
}
|
||||
|
||||
void THD::inc_examined_row_count(ha_rows count)
|
||||
{
|
||||
m_examined_row_count+= count;
|
||||
MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
|
||||
if (m_examined_row_count)
|
||||
MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
|
||||
}
|
||||
|
||||
void THD::inc_status_created_tmp_disk_tables()
|
||||
|
Reference in New Issue
Block a user