mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
a7e352b54d
This was done in, among other things: - thd->db and thd->db_length - TABLE_LIST tablename, db, alias and schema_name - Audit plugin database name - lex->db - All db and table names in Alter_table_ctx - st_select_lex db Other things: - Changed a lot of functions to take const LEX_CSTRING* as argument for db, table_name and alias. See init_one_table() as an example. - Changed some function arguments from LEX_CSTRING to const LEX_CSTRING - Changed some lists from LEX_STRING to LEX_CSTRING - threads_mysql.result changed because process list_db wasn't always correctly updated - New append_identifier() function that takes LEX_CSTRING* as arguments - Added new element tmp_buff to Alter_table_ctx to separate temp name handling from temporary space - Ensure we store the length after my_casedn_str() of table/db names - Removed not used version of rename_table_in_stat_tables() - Changed Natural_join_column::table_name and db_name() to never return NULL (used for print) - thd->get_db() now returns db as a printable string (thd->db.str or "")
71 lines
2.5 KiB
C++
71 lines
2.5 KiB
C++
static ST_FIELD_INFO index_stats_fields[]=
|
|
{
|
|
{"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schema",SKIP_OPEN_TABLE},
|
|
{"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name",SKIP_OPEN_TABLE},
|
|
{"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Index_name",SKIP_OPEN_TABLE},
|
|
{"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read",SKIP_OPEN_TABLE},
|
|
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0,0}
|
|
};
|
|
|
|
static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond)
|
|
{
|
|
TABLE *table= tables->table;
|
|
|
|
mysql_mutex_lock(&LOCK_global_index_stats);
|
|
for (uint i= 0; i < global_index_stats.records; i++)
|
|
{
|
|
INDEX_STATS *index_stats =
|
|
(INDEX_STATS*) my_hash_element(&global_index_stats, i);
|
|
TABLE_LIST tmp_table;
|
|
const char *index_name;
|
|
size_t index_name_length;
|
|
|
|
bzero((char*) &tmp_table,sizeof(tmp_table));
|
|
tmp_table.db.str= index_stats->index;
|
|
tmp_table.db.length= strlen(index_stats->index);
|
|
tmp_table.table_name.str= index_stats->index + tmp_table.db.length + 1;
|
|
tmp_table.table_name.length= strlen(tmp_table.table_name.str);
|
|
tmp_table.grant.privilege= 0;
|
|
if (check_access(thd, SELECT_ACL, tmp_table.db.str,
|
|
&tmp_table.grant.privilege, NULL, 0, 1) ||
|
|
check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))
|
|
continue;
|
|
|
|
index_name= tmp_table.table_name.str + tmp_table.table_name.length + 1;
|
|
index_name_length= (index_stats->index_name_length - tmp_table.db.length -
|
|
tmp_table.table_name.length - 3);
|
|
|
|
table->field[0]->store(tmp_table.db.str, tmp_table.db.length, system_charset_info);
|
|
table->field[1]->store(tmp_table.table_name.str, tmp_table.table_name.length,
|
|
system_charset_info);
|
|
table->field[2]->store(index_name, (uint) index_name_length, system_charset_info);
|
|
table->field[3]->store((longlong)index_stats->rows_read, TRUE);
|
|
|
|
if (schema_table_store_record(thd, table))
|
|
{
|
|
mysql_mutex_unlock(&LOCK_global_index_stats);
|
|
return 1;
|
|
}
|
|
}
|
|
mysql_mutex_unlock(&LOCK_global_index_stats);
|
|
return 0;
|
|
}
|
|
|
|
static int index_stats_reset()
|
|
{
|
|
mysql_mutex_lock(&LOCK_global_index_stats);
|
|
free_global_index_stats();
|
|
init_global_index_stats();
|
|
mysql_mutex_unlock(&LOCK_global_index_stats);
|
|
return 0;
|
|
}
|
|
|
|
static int index_stats_init(void *p)
|
|
{
|
|
ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;
|
|
schema->fields_info= index_stats_fields;
|
|
schema->fill_table= index_stats_fill;
|
|
schema->reset_table= index_stats_reset;
|
|
return 0;
|
|
}
|
|
|