-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery_cache_tables.cc
More file actions
105 lines (86 loc) · 3.76 KB
/
Copy pathquery_cache_tables.cc
File metadata and controls
105 lines (86 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Copyright (c) 2012, PaynetEasy. All rights reserved.
Author: Mikhail Goryachkin
Licence: GPL
Description: mysql query cache view plugin.
*/
#include "mysql_query_cache.h"
#include <mysql/plugin.h>
bool schema_table_store_record(THD *thd,TABLE *table);
#define MAX_SCHEMA_NAME_LENGTH 127
#define MAX_TABLE_NAME_LENGTH 127
#define COLUMN_SCHEMA_NAME 0
#define COLUMN_TABLE_NAME 1
ST_FIELD_INFO query_cache_table_fields[]=
{
{"SCHEMA_NAME", MAX_SCHEMA_NAME_LENGTH, MYSQL_TYPE_STRING, 0, 0, "Schema Name"},
{"TABLE_NAME", MAX_TABLE_NAME_LENGTH, MYSQL_TYPE_STRING, 0, 0, "Table Name"},
{0,0, MYSQL_TYPE_STRING, 0, 0, 0}
};
static int query_cache_table_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
{
// character set information to store varchar values
CHARSET_INFO *cs = system_charset_info;
TABLE *is_query_cache_tables = (TABLE *)tables->table;
// query_cache defined in sql_cache.h is MySQL Query Cache implementation;
MySQL_IS_Query_Cache *qc = (MySQL_IS_Query_Cache *)&query_cache;
HASH *h_tables;
const uchar *query_cache_block_hash;
Query_cache_block* query_cache_block_current;
query_cache.lock();
h_tables = qc->get_tables_hash();
for(uint i = 0; i < h_tables->records; i++)
{
query_cache_block_hash = my_hash_element(h_tables, i);
query_cache_block_current = (Query_cache_block*)query_cache_block_hash;
Query_cache_table* query_cache_table = query_cache_block_current->table();
// get tables data
const char *schema_name = (const char*)query_cache_table->db();
size_t schema_name_length = strlen(schema_name)>MAX_SCHEMA_NAME_LENGTH?MAX_SCHEMA_NAME_LENGTH:strlen(schema_name);
is_query_cache_tables->field[COLUMN_SCHEMA_NAME]->store((char*)schema_name, schema_name_length, cs);
const char *table_name = (const char*)query_cache_table->table();
size_t table_name_length = strlen(table_name)>MAX_TABLE_NAME_LENGTH?MAX_TABLE_NAME_LENGTH:strlen(table_name);
is_query_cache_tables->field[COLUMN_TABLE_NAME]->store((char*)table_name, table_name_length, cs);
if (schema_table_store_record(thd, is_query_cache_tables)) {
query_cache.unlock();
return 1;
}
}
query_cache.unlock();
return 0;
}
static int query_cache_table_plugin_init(void *p)
{
ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *)p;
schema->fields_info = query_cache_table_fields;
schema->fill_table = query_cache_table_fill_table;
return 0;
}
static int query_cache_table_plugin_deinit(void *p)
{
return 0;
}
struct st_mysql_information_schema query_cache_table_plugin =
{
MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION /* interface version */
};
/*
Plugin library descriptor
*/
mysql_declare_plugin(mysql_is_query_cache_table)
{
MYSQL_INFORMATION_SCHEMA_PLUGIN, /* type */
&query_cache_table_plugin, /* descriptor */
"QUERY_CACHE_TABLES", /* name */
"Mikhail Goryachkin", /* author */
"Lists all tables in the query cache", /* description */
PLUGIN_LICENSE_GPL,
query_cache_table_plugin_init, /* init function (when loaded) */
query_cache_table_plugin_deinit, /* deinit function (when unloaded) */
0x0010, /* version */
NULL, /* status variables */
NULL, /* system variables */
NULL, /* config options */
0, /* flags */
}
mysql_declare_plugin_end;