1static ST_FIELD_INFO index_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 {"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Index_name",SKIP_OPEN_TABLE},
6 {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read",SKIP_OPEN_TABLE},
7 {0, 0, MYSQL_TYPE_STRING, 0, 0, 0,0}
8};
9
10static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond)
11{
12 TABLE *table= tables->table;
13
14 mysql_mutex_lock(&LOCK_global_index_stats);
15 for (uint i= 0; i < global_index_stats.records; i++)
16 {
17 INDEX_STATS *index_stats =
18 (INDEX_STATS*) my_hash_element(&global_index_stats, i);
19 TABLE_LIST tmp_table;
20 const char *index_name;
21 size_t index_name_length;
22
23 bzero((char*) &tmp_table,sizeof(tmp_table));
24 tmp_table.db.str= index_stats->index;
25 tmp_table.db.length= strlen(index_stats->index);
26 tmp_table.table_name.str= index_stats->index + tmp_table.db.length + 1;
27 tmp_table.table_name.length= strlen(tmp_table.table_name.str);
28 tmp_table.grant.privilege= 0;
29 if (check_access(thd, SELECT_ACL, tmp_table.db.str,
30 &tmp_table.grant.privilege, NULL, 0, 1) ||
31 check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))
32 continue;
33
34 index_name= tmp_table.table_name.str + tmp_table.table_name.length + 1;
35 index_name_length= (index_stats->index_name_length - tmp_table.db.length -
36 tmp_table.table_name.length - 3);
37
38 table->field[0]->store(tmp_table.db.str, tmp_table.db.length, system_charset_info);
39 table->field[1]->store(tmp_table.table_name.str, tmp_table.table_name.length,
40 system_charset_info);
41 table->field[2]->store(index_name, (uint) index_name_length, system_charset_info);
42 table->field[3]->store((longlong)index_stats->rows_read, TRUE);
43
44 if (schema_table_store_record(thd, table))
45 {
46 mysql_mutex_unlock(&LOCK_global_index_stats);
47 return 1;
48 }
49 }
50 mysql_mutex_unlock(&LOCK_global_index_stats);
51 return 0;
52}
53
54static int index_stats_reset()
55{
56 mysql_mutex_lock(&LOCK_global_index_stats);
57 free_global_index_stats();
58 init_global_index_stats();
59 mysql_mutex_unlock(&LOCK_global_index_stats);
60 return 0;
61}
62
63static int index_stats_init(void *p)
64{
65 ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;
66 schema->fields_info= index_stats_fields;
67 schema->fill_table= index_stats_fill;
68 schema->reset_table= index_stats_reset;
69 return 0;
70}
71
72