MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / update_stats

Method update_stats

sql/sql_class.cc:927–981  ·  view source on GitHub ↗

Updates 'diff' stats of a THD.

Source from the content-addressed store, hash-verified

925
926// Updates 'diff' stats of a THD.
927void THD::update_stats(bool ran_command)
928{
929 diff_total_busy_time+= busy_time;
930 diff_total_cpu_time+= cpu_time;
931 diff_total_bytes_received+= bytes_received;
932 diff_total_bytes_sent+= bytes_sent;
933 diff_total_binlog_bytes_written+= binlog_bytes_written;
934 diff_total_sent_rows+= sent_row_count_2;
935 diff_total_updated_rows+= updated_row_count;
936 // diff_total_read_rows is updated in handler.cc.
937
938 if (ran_command)
939 {
940 // The replication thread has the COM_CONNECT command.
941 DBUG_ASSERT(get_command() != COM_SLEEP);
942 if ((get_command() == COM_QUERY || get_command() == COM_CONNECT) &&
943 (lex->sql_command >= 0 && lex->sql_command < SQLCOM_END)) {
944 // A SQL query.
945 if (lex->sql_command == SQLCOM_SELECT)
946 {
947 diff_select_commands++;
948 if (!sent_row_count_2)
949 diff_empty_queries++;
950 }
951 else if (!sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)
952 {
953 // 'SHOW ' commands become SQLCOM_SELECT.
954 diff_other_commands++;
955 // 'SHOW ' commands shouldn't inflate total sent row count.
956 diff_total_sent_rows-= sent_row_count_2;
957 } else if (is_update_query(lex->sql_command)) {
958 diff_update_commands++;
959 } else {
960 diff_other_commands++;
961 }
962 }
963 }
964 // diff_commit_trans is updated in handler.cc.
965 // diff_rollback_trans is updated in handler.cc.
966 // diff_denied_connections is updated in sql_parse.cc.
967 // diff_lost_connections is updated in sql_parse.cc.
968 // diff_access_denied_errors is updated in sql_parse.cc.
969
970 /* reset counters to zero to avoid double-counting since values
971 are already store in diff_total_*.
972 */
973
974 busy_time= 0;
975 cpu_time= 0;
976 bytes_received= 0;
977 bytes_sent= 0;
978 binlog_bytes_written= 0;
979 updated_row_count= 0;
980 sent_row_count_2= 0;
981}
982
983/*
984 Do what's needed when one invokes change user.

Callers

nothing calls this directly

Calls 1

is_update_queryFunction · 0.85

Tested by

no test coverage detected