mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
This is based on the userstatv2 patch from Percona and OurDelta.
The original code comes, as far as I know, from Google (Mark Callaghan's team) with additional work from Percona, Ourdelta and Weldon Whipple. This code provides the same functionallity, but with a lot of changes to make it faster and better fit the MariaDB infrastucture. Added new status variables: - Com_show_client_statistics, Com_show_index_statistics, Com_show_table_statistics, Com_show_user_statistics - Access_denied_errors, Busy_time (clock time), Binlog_bytes_written, Cpu_time, Empty_queries, Rows_sent, Rows_read Added new variable / startup option 'userstat' to control if user statistics should be enabled or not Added my_getcputime(); Returns cpu time used by this thread. New FLUSH commands: - FLUSH SLOW QUERY LOG - FLUSH TABLE_STATISTICS - FLUSH INDEX_STATISTICS - FLUSH USER_STATISTICS - FLUSH CLIENT_STATISTICS New SHOW commands: - SHOW CLIENT_STATISTICS - SHOW USER_STATISTICS - SHOW TABLE_STATISTICS - SHOW INDEX_STATISTICS New Information schemas: - CLIENT_STATISTICS - USER_STATISTICS - INDEX_STATISTICS - TABLE_STATISTICS Added support for all new flush commands to mysqladmin Added handler::ha_... wrappers for all handler read calls to do statistics counting - Changed all code to use new ha_... calls - Count number of read rows, changed rows and rows read trough an index Added counting of number of bytes sent to binary log (status variable Binlog_bytes_written) Added counting of access denied errors (status variable Access_denied_erors) Bugs fixed: - Fixed bug in add_to_status() and add_diff_to_status() where longlong variables where threated as long - CLOCK_GETTIME was not propely working on Linuxm client/mysqladmin.cc: Added support for all new flush commmands and some common combinations: flush-slow-log flush-table-statistics flush-index-statistics flush-user-statistics flush-client-statistics flush-all-status flush-all-statistics configure.in: Added checking if clock_gettime needs the librt. (Fixes Bug #37639 clock_gettime is never used/enabled in Linux/Unix) include/my_sys.h: Added my_getcputime() include/mysql_com.h: Added LIST_PROCESS_HOST_LEN & new REFRESH target defines mysql-test/r/information_schema.result: New information schema tables added mysql-test/r/information_schema_all_engines.result: New information schema tables added mysql-test/r/information_schema_db.result: New information schema tables added mysql-test/r/log_slow.result: Added testing that flosh slow query logs is accepted mysql-test/r/status_user.result: Basic testing of user, client, table and index statistics mysql-test/t/log_slow.test: Added testing that flosh slow query logs is accepted mysql-test/t/status_user-master.opt: Ensure that we get a fresh restart before running status_user.test mysql-test/t/status_user.test: Basic testing of user, client, table and index statistics mysys/my_getsystime.c: Added my_getcputime() Returns cpu time used by this thread. sql/authors.h: Updated authors to have core and original MySQL developers first. sql/event_data_objects.cc: Updated call to mysql_reset_thd_for_next_command() sql/event_db_repository.cc: Changed to use new ha_... calls sql/filesort.cc: Changed to use new ha_... calls sql/ha_partition.cc: Changed to use new ha_... calls Fixed comment syntax sql/handler.cc: Changed to use new ha_... calls Reset table statistics Added code to update global table and index status Added counting of rows changed sql/handler.h: Added table and index statistics variables Added function reset_statistics() Added handler::ha_... wrappers for all handler read calls to do statistics counting Protected all normal read calls to ensure we use the new calls in the server. Made ha_partition a friend class so that partition code can call the old read functions sql/item_subselect.cc: Changed to use new ha_... calls sql/lex.h: Added keywords for new information schema tables and flush commands sql/log.cc: Added flush_slow_log() Added counting of number of bytes sent to binary log Removed not needed test of thd (It's used before, so it's safe to use) Added THD object to MYSQL_BIN_LOG::write_cache() to simplify statistics counting sql/log.h: Added new parameter to write_cache() Added flush_slow_log() functions. sql/log_event.cc: Updated call to mysql_reset_thd_for_next_command() Changed to use new ha_... calls sql/log_event_old.cc: Updated call to mysql_reset_thd_for_next_command() Changed to use new ha_... calls sql/mysql_priv.h: Updated call to mysql_reset_thd_for_next_command() Added new statistics functions and variables needed by these. sql/mysqld.cc: Added new statistics variables and structures to handle these Added new status variables: - Com_show_client_statistics, Com_show_index_statistics, Com_show_table_statistics, Com_show_user_statistics - Access_denied_errors, Busy_time (clock time), Binlog_bytes_written, Cpu_time, Empty_queries, Rows_set, Rows_read Added new option 'userstat' to control if user statistics should be enabled or not sql/opt_range.cc: Changed to use new ha_... calls sql/opt_range.h: Changed to use new ha_... calls sql/opt_sum.cc: Changed to use new ha_... calls sql/records.cc: Changed to use new ha_... calls sql/set_var.cc: Added variable 'userstat' sql/sp.cc: Changed to use new ha_... calls sql/sql_acl.cc: Changed to use new ha_... calls Added counting of access_denied_errors sql/sql_base.cc: Added call to statistics functions sql/sql_class.cc: Added usage of org_status_var, to store status variables at start of command Added functions THD::update_stats(), THD::update_all_stats() Fixed bug in add_to_status() and add_diff_to_status() where longlong variables where threated as long sql/sql_class.h: Added new status variables to status_var Moved variables that was not ulong in status_var last. Added variables to THD for storing temporary values during statistics counting sql/sql_connect.cc: Variables and functions to calculate user and client statistics Added counting of access_denied_errors and lost_connections sql/sql_cursor.cc: Changed to use new ha_... calls sql/sql_handler.cc: Changed to use new ha_... calls sql/sql_help.cc: Changed to use new ha_... calls sql/sql_insert.cc: Changed to use new ha_... calls sql/sql_lex.h: Added SQLCOM_SHOW_USER_STATS, SQLCOM_SHOW_TABLE_STATS, SQLCOM_SHOW_INDEX_STATS, SQLCOM_SHOW_CLIENT_STATS sql/sql_parse.cc: Added handling of: - SHOW CLIENT_STATISTICS - SHOW USER_STATISTICS - SHOW TABLE_STATISTICS - SHOW INDEX_STATISTICS Added handling of new FLUSH commands: - FLUSH SLOW QUERY LOGS - FLUSH TABLE_STATISTICS - FLUSH INDEX_STATISTICS - FLUSH USER_STATISTICS - FLUSH CLIENT_STATISTICS Added THD parameter to mysql_reset_thd_for_next_command() Added initialization and calls to user statistics functions Added increment of statistics variables empty_queries, rows_sent and access_denied_errors. Added counting of cpu time per query sql/sql_plugin.cc: Changed to use new ha_... calls sql/sql_prepare.cc: Updated call to mysql_reset_thd_for_next_command() sql/sql_select.cc: Changed to use new ha_... calls Indentation changes sql/sql_servers.cc: Changed to use new ha_... calls sql/sql_show.cc: Added counting of access denied errors Added function for new information schema tables: - CLIENT_STATISTICS - USER_STATISTICS - INDEX_STATISTICS - TABLE_STATISTICS Changed to use new ha_... calls sql/sql_table.cc: Changed to use new ha_... calls sql/sql_udf.cc: Changed to use new ha_... calls sql/sql_update.cc: Changed to use new ha_... calls sql/sql_yacc.yy: Add new show and flush commands sql/structs.h: Add name_length to KEY to avoid some strlen Added cache_name to KEY for fast storage of keyvalue in cache Added structs USER_STATS, TABLE_STATS, INDEX_STATS Added function prototypes for statistics functions sql/table.cc: Store db+table+index name into keyinfo->cache_name sql/table.h: Added new information schema tables sql/tztime.cc: Changed to use new ha_... calls
This commit is contained in:
@ -1834,9 +1834,9 @@ static bool update_user_table(THD *thd, TABLE *table,
|
||||
key_copy((uchar *) user_key, table->record[0], table->key_info,
|
||||
table->key_info->key_length);
|
||||
|
||||
if (table->file->index_read_idx_map(table->record[0], 0,
|
||||
(uchar *) user_key, HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_idx_map(table->record[0], 0,
|
||||
(uchar *) user_key, HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
{
|
||||
my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH),
|
||||
MYF(0)); /* purecov: deadcode */
|
||||
@ -1927,9 +1927,9 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
|
||||
key_copy(user_key, table->record[0], table->key_info,
|
||||
table->key_info->key_length);
|
||||
|
||||
if (table->file->index_read_idx_map(table->record[0], 0, user_key,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_idx_map(table->record[0], 0, user_key,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
{
|
||||
/* what == 'N' means revoke */
|
||||
if (what == 'N')
|
||||
@ -2151,9 +2151,9 @@ static int replace_db_table(TABLE *table, const char *db,
|
||||
key_copy(user_key, table->record[0], table->key_info,
|
||||
table->key_info->key_length);
|
||||
|
||||
if (table->file->index_read_idx_map(table->record[0],0, user_key,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_idx_map(table->record[0],0, user_key,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
{
|
||||
if (what == 'N')
|
||||
{ // no row, no revoke
|
||||
@ -2369,8 +2369,9 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs)
|
||||
col_privs->field[4]->store("",0, &my_charset_latin1);
|
||||
|
||||
col_privs->file->ha_index_init(0, 1);
|
||||
if (col_privs->file->index_read_map(col_privs->record[0], (uchar*) key,
|
||||
(key_part_map)15, HA_READ_KEY_EXACT))
|
||||
if (col_privs->file->ha_index_read_map(col_privs->record[0], (uchar*) key,
|
||||
(key_part_map)15,
|
||||
HA_READ_KEY_EXACT))
|
||||
{
|
||||
cols = 0; /* purecov: deadcode */
|
||||
col_privs->file->ha_index_end();
|
||||
@ -2391,7 +2392,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs)
|
||||
return; /* purecov: deadcode */
|
||||
}
|
||||
my_hash_insert(&hash_columns, (uchar *) mem_check);
|
||||
} while (!col_privs->file->index_next(col_privs->record[0]) &&
|
||||
} while (!col_privs->file->ha_index_next(col_privs->record[0]) &&
|
||||
!key_cmp_if_same(col_privs,key,0,key_prefix_len));
|
||||
col_privs->file->ha_index_end();
|
||||
}
|
||||
@ -2532,8 +2533,8 @@ static int replace_column_table(GRANT_TABLE *g_t,
|
||||
key_copy(user_key, table->record[0], table->key_info,
|
||||
table->key_info->key_length);
|
||||
|
||||
if (table->file->index_read_map(table->record[0], user_key, HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_map(table->record[0], user_key,
|
||||
HA_WHOLE_KEY, HA_READ_KEY_EXACT))
|
||||
{
|
||||
if (revoke_grant)
|
||||
{
|
||||
@ -2610,9 +2611,9 @@ static int replace_column_table(GRANT_TABLE *g_t,
|
||||
key_copy(user_key, table->record[0], table->key_info,
|
||||
key_prefix_length);
|
||||
|
||||
if (table->file->index_read_map(table->record[0], user_key,
|
||||
(key_part_map)15,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_map(table->record[0], user_key,
|
||||
(key_part_map)15,
|
||||
HA_READ_KEY_EXACT))
|
||||
goto end;
|
||||
|
||||
/* Scan through all rows with the same host,db,user and table */
|
||||
@ -2663,7 +2664,7 @@ static int replace_column_table(GRANT_TABLE *g_t,
|
||||
hash_delete(&g_t->hash_columns,(uchar*) grant_column);
|
||||
}
|
||||
}
|
||||
} while (!table->file->index_next(table->record[0]) &&
|
||||
} while (!table->file->ha_index_next(table->record[0]) &&
|
||||
!key_cmp_if_same(table, key, 0, key_prefix_length));
|
||||
}
|
||||
|
||||
@ -2713,9 +2714,9 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
|
||||
key_copy(user_key, table->record[0], table->key_info,
|
||||
table->key_info->key_length);
|
||||
|
||||
if (table->file->index_read_idx_map(table->record[0], 0, user_key,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_idx_map(table->record[0], 0, user_key,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
{
|
||||
/*
|
||||
The following should never happen as we first check the in memory
|
||||
@ -2840,10 +2841,10 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name,
|
||||
TRUE);
|
||||
store_record(table,record[1]); // store at pos 1
|
||||
|
||||
if (table->file->index_read_idx_map(table->record[0], 0,
|
||||
(uchar*) table->field[0]->ptr,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
if (table->file->ha_index_read_idx_map(table->record[0], 0,
|
||||
(uchar*) table->field[0]->ptr,
|
||||
HA_WHOLE_KEY,
|
||||
HA_READ_KEY_EXACT))
|
||||
{
|
||||
/*
|
||||
The following should never happen as we first check the in memory
|
||||
@ -3548,7 +3549,7 @@ static my_bool grant_load_procs_priv(TABLE *p_table)
|
||||
p_table->file->ha_index_init(0, 1);
|
||||
p_table->use_all_columns();
|
||||
|
||||
if (!p_table->file->index_first(p_table->record[0]))
|
||||
if (!p_table->file->ha_index_first(p_table->record[0]))
|
||||
{
|
||||
memex_ptr= &memex;
|
||||
my_pthread_setspecific_ptr(THR_MALLOC, &memex_ptr);
|
||||
@ -3600,7 +3601,7 @@ static my_bool grant_load_procs_priv(TABLE *p_table)
|
||||
goto end_unlock;
|
||||
}
|
||||
}
|
||||
while (!p_table->file->index_next(p_table->record[0]));
|
||||
while (!p_table->file->ha_index_next(p_table->record[0]));
|
||||
}
|
||||
/* Return ok */
|
||||
return_val= 0;
|
||||
@ -3650,7 +3651,7 @@ static my_bool grant_load(THD *thd, TABLE_LIST *tables)
|
||||
t_table->use_all_columns();
|
||||
c_table->use_all_columns();
|
||||
|
||||
if (!t_table->file->index_first(t_table->record[0]))
|
||||
if (!t_table->file->ha_index_first(t_table->record[0]))
|
||||
{
|
||||
memex_ptr= &memex;
|
||||
my_pthread_setspecific_ptr(THR_MALLOC, &memex_ptr);
|
||||
@ -3685,7 +3686,7 @@ static my_bool grant_load(THD *thd, TABLE_LIST *tables)
|
||||
goto end_unlock;
|
||||
}
|
||||
}
|
||||
while (!t_table->file->index_next(t_table->record[0]));
|
||||
while (!t_table->file->ha_index_next(t_table->record[0]));
|
||||
}
|
||||
|
||||
return_val=0; // Return ok
|
||||
@ -3957,6 +3958,8 @@ err:
|
||||
{
|
||||
char command[128];
|
||||
get_privilege_desc(command, sizeof(command), want_access);
|
||||
status_var_increment(thd->status_var.access_denied_errors);
|
||||
|
||||
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
|
||||
command,
|
||||
sctx->priv_user,
|
||||
@ -5203,9 +5206,9 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
|
||||
table->key_info->key_part[1].store_length);
|
||||
key_copy(user_key, table->record[0], table->key_info, key_prefix_length);
|
||||
|
||||
if ((error= table->file->index_read_idx_map(table->record[0], 0,
|
||||
user_key, (key_part_map)3,
|
||||
HA_READ_KEY_EXACT)))
|
||||
if ((error= table->file->ha_index_read_idx_map(table->record[0], 0,
|
||||
user_key, (key_part_map)3,
|
||||
HA_READ_KEY_EXACT)))
|
||||
{
|
||||
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
|
||||
{
|
||||
@ -5240,7 +5243,7 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
|
||||
DBUG_PRINT("info",("scan table: '%s' search: '%s'@'%s'",
|
||||
table->s->table_name.str, user_str, host_str));
|
||||
#endif
|
||||
while ((error= table->file->rnd_next(table->record[0])) !=
|
||||
while ((error= table->file->ha_rnd_next(table->record[0])) !=
|
||||
HA_ERR_END_OF_FILE)
|
||||
{
|
||||
if (error)
|
||||
|
Reference in New Issue
Block a user