| 1 | static ST_FIELD_INFO table_stats_fields[]= |
| 2 | { |
| 3 | {"TABLE_SCHEMA" , NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schema" ,SKIP_OPEN_TABLE}, |
| 4 | {"TABLE_NAME" , NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name" ,SKIP_OPEN_TABLE}, |
| 5 | {"ROWS_READ" , MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read" ,SKIP_OPEN_TABLE}, |
| 6 | {"ROWS_CHANGED" , MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_changed" ,SKIP_OPEN_TABLE}, |
| 7 | {"ROWS_CHANGED_X_INDEXES" , MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_changed_x_#indexes" ,SKIP_OPEN_TABLE}, |
| 8 | {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} |
| 9 | }; |
| 10 | |
| 11 | static int table_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) |
| 12 | { |
| 13 | TABLE *table= tables->table; |
| 14 | |
| 15 | mysql_mutex_lock(&LOCK_global_table_stats); |
| 16 | for (uint i= 0; i < global_table_stats.records; i++) |
| 17 | { |
| 18 | char *end_of_schema; |
| 19 | TABLE_STATS *table_stats= |
| 20 | (TABLE_STATS*)my_hash_element(&global_table_stats, i); |
| 21 | TABLE_LIST tmp_table; |
| 22 | size_t schema_length, table_name_length; |
| 23 | |
| 24 | end_of_schema= strend(table_stats->table); |
| 25 | schema_length= (size_t) (end_of_schema - table_stats->table); |
| 26 | table_name_length= strlen(table_stats->table + schema_length + 1); |
| 27 | |
| 28 | bzero((char*) &tmp_table,sizeof(tmp_table)); |
| 29 | tmp_table.db.str= table_stats->table; |
| 30 | tmp_table.db.length= schema_length; |
| 31 | tmp_table.table_name.str= end_of_schema+1; |
| 32 | tmp_table.table_name.length= table_name_length; |
| 33 | tmp_table.grant.privilege= 0; |
| 34 | if (check_access(thd, SELECT_ACL, tmp_table.db.str, |
| 35 | &tmp_table.grant.privilege, NULL, 0, 1) || |
| 36 | check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, |
| 37 | 1)) |
| 38 | continue; |
| 39 | |
| 40 | table->field[0]->store(table_stats->table, schema_length, |
| 41 | system_charset_info); |
| 42 | table->field[1]->store(table_stats->table + schema_length+1, |
| 43 | table_name_length, system_charset_info); |
| 44 | table->field[2]->store((longlong)table_stats->rows_read, TRUE); |
| 45 | table->field[3]->store((longlong)table_stats->rows_changed, TRUE); |
| 46 | table->field[4]->store((longlong)table_stats->rows_changed_x_indexes, |
| 47 | TRUE); |
| 48 | if (schema_table_store_record(thd, table)) |
| 49 | { |
| 50 | mysql_mutex_unlock(&LOCK_global_table_stats); |
| 51 | return 1; |
| 52 | } |
| 53 | } |
| 54 | mysql_mutex_unlock(&LOCK_global_table_stats); |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static int table_stats_reset() |
| 59 | { |
| 60 | mysql_mutex_lock(&LOCK_global_table_stats); |
| 61 | free_global_table_stats(); |
| 62 | init_global_table_stats(); |
| 63 | mysql_mutex_unlock(&LOCK_global_table_stats); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int table_stats_init(void *p) |
| 68 | { |
| 69 | ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; |
| 70 | schema->fields_info= table_stats_fields; |
| 71 | schema->fill_table= table_stats_fill; |
| 72 | schema->reset_table= table_stats_reset; |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | |