28
28
*/
29
29
30
30
31
- /*
32
- * TODO: report query cache flags
33
- */
34
31
#ifndef MYSQL_SERVER
35
32
#define MYSQL_SERVER
36
33
#endif
40
37
#include < sql_acl.h> // PROCESS_ACL
41
38
#include < sql_class.h> // THD
42
39
#include < table.h> // ST_SCHEMA_TABLE
40
+ #include < set_var.h> // sql_mode_string_representation
41
+ #include < tztime.h>
43
42
#include < mysql/plugin.h>
44
43
45
44
class Accessible_Query_Cache : public Query_cache {
@@ -58,6 +57,25 @@ bool schema_table_store_record(THD *thd, TABLE *table);
58
57
#define COLUMN_RESULT_BLOCKS_COUNT 2
59
58
#define COLUMN_RESULT_BLOCKS_SIZE 3
60
59
#define COLUMN_RESULT_BLOCKS_SIZE_USED 4
60
+ #define COLUMN_LIMIT 5
61
+ #define COLUMN_MAX_SORT_LENGTH 6
62
+ #define COLUMN_GROUP_CONCAT_MAX_LENGTH 7
63
+ #define COLUMN_CHARACTER_SET_CLIENT 8
64
+ #define COLUMN_CHARACTER_SET_RESULT 9
65
+ #define COLUMN_COLLATION 10
66
+ #define COLUMN_TIMEZONE 11
67
+ #define COLUMN_DEFAULT_WEEK_FORMAT 12
68
+ #define COLUMN_DIV_PRECISION_INCREMENT 13
69
+ #define COLUMN_SQL_MODE 14
70
+ #define COLUMN_LC_TIME_NAMES 15
71
+
72
+ #define COLUMN_CLIENT_LONG_FLAG 16
73
+ #define COLUMN_CLIENT_PROTOCOL_41 17
74
+ #define COLUMN_PROTOCOL_TYPE 18
75
+ #define COLUMN_MORE_RESULTS_EXISTS 19
76
+ #define COLUMN_IN_TRANS 20
77
+ #define COLUMN_AUTOCOMMIT 21
78
+ #define COLUMN_PKT_NR 22
61
79
62
80
/* ST_FIELD_INFO is defined in table.h */
63
81
static ST_FIELD_INFO qc_info_fields[]=
@@ -67,6 +85,24 @@ static ST_FIELD_INFO qc_info_fields[]=
67
85
{" RESULT_BLOCKS_COUNT" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0 , 0 , 0 , 0 },
68
86
{" RESULT_BLOCKS_SIZE" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0 , 0 , 0 , 0 },
69
87
{" RESULT_BLOCKS_SIZE_USED" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0 , 0 , 0 , 0 },
88
+ {" LIMIT" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0 , 0 , 0 , 0 },
89
+ {" MAX_SORT_LENGTH" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0 , 0 , 0 , 0 },
90
+ {" GROUP_CONCAT_MAX_LENGTH" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0 , 0 , 0 , 0 },
91
+ {" CHARACTER_SET_CLIENT" , MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 },
92
+ {" CHARACTER_SET_RESULT" , MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 },
93
+ {" COLLATION" , MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 },
94
+ {" TIMEZONE" , 50 , MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 },
95
+ {" DEFAULT_WEEK_FORMAT" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0 , 0 , 0 , 0 },
96
+ {" DIV_PRECISION_INCREMENT" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0 , 0 , 0 , 0 },
97
+ {" SQL_MODE" , 250 , MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 },
98
+ {" LC_TIME_NAMES" , 100 , MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 },
99
+ {" CLIENT_LONG_FLAG" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
100
+ {" CLIENT_PROTOCOL_41" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
101
+ {" PROTOCOL_TYPE" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
102
+ {" MORE_RESULTS_EXISTS" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
103
+ {" IN_TRANS" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
104
+ {" AUTOCOMMIT" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
105
+ {" PACKET_NUMBER" , MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0 , 0 , 0 , 0 },
70
106
{0 , 0 , MYSQL_TYPE_STRING, 0 , 0 , 0 , 0 }
71
107
};
72
108
@@ -91,15 +127,22 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables,
91
127
const uchar *query_cache_block_raw;
92
128
Query_cache_block* query_cache_block;
93
129
Query_cache_query* query_cache_query;
130
+ Query_cache_query_flags flags;
94
131
uint result_blocks_count;
95
132
ulonglong result_blocks_size;
96
133
ulonglong result_blocks_size_used;
97
134
Query_cache_block *first_result_block;
98
135
Query_cache_block *result_block;
99
136
const char *statement_text;
100
137
size_t statement_text_length;
138
+ size_t flags_length;
101
139
const char *key, *db;
102
140
size_t key_length, db_length;
141
+ LEX_STRING sql_mode_str;
142
+ const String *tz;
143
+ CHARSET_INFO *cs_client;
144
+ CHARSET_INFO *cs_result;
145
+ CHARSET_INFO *collation;
103
146
104
147
query_cache_block_raw = my_hash_element (queries, i);
105
148
query_cache_block = (Query_cache_block*)query_cache_block_raw;
@@ -118,6 +161,38 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables,
118
161
/* get the entire key that identifies this query cache query */
119
162
key = (const char *)query_cache_query_get_key (query_cache_block_raw,
120
163
&key_length, 0 );
164
+ /* get and store the flags */
165
+ flags_length= key_length - QUERY_CACHE_FLAGS_SIZE;
166
+ memcpy (&flags, key+flags_length, QUERY_CACHE_FLAGS_SIZE);
167
+ table->field [COLUMN_LIMIT]->store (flags.limit , 0 );
168
+ table->field [COLUMN_MAX_SORT_LENGTH]->store (flags.max_sort_length , 0 );
169
+ table->field [COLUMN_GROUP_CONCAT_MAX_LENGTH]->store (flags.group_concat_max_len , 0 );
170
+
171
+ cs_client= get_charset (flags.character_set_client_num , MYF (MY_WME));
172
+ table->field [COLUMN_CHARACTER_SET_CLIENT]->store (cs_client->csname , strlen (cs_client->csname ), scs);
173
+ cs_result= get_charset (flags.character_set_results_num , MYF (MY_WME));
174
+ table->field [COLUMN_CHARACTER_SET_RESULT]->store (cs_result->csname , strlen (cs_result->csname ), scs);
175
+ collation= get_charset (flags.collation_connection_num , MYF (MY_WME));
176
+ table->field [COLUMN_COLLATION]->store (collation->name , strlen (collation->name ), scs);
177
+
178
+ tz= flags.time_zone ->get_name ();
179
+ table->field [COLUMN_TIMEZONE]->store (tz->ptr (), tz->length (), scs);
180
+ table->field [COLUMN_DEFAULT_WEEK_FORMAT]->store (flags.default_week_format , 0 );
181
+ table->field [COLUMN_DIV_PRECISION_INCREMENT]->store (flags.div_precision_increment , 0 );
182
+
183
+ sql_mode_string_representation (thd, flags.sql_mode , &sql_mode_str);
184
+ table->field [COLUMN_SQL_MODE]->store (sql_mode_str.str , sql_mode_str.length , scs);
185
+
186
+ table->field [COLUMN_LC_TIME_NAMES]->store (flags.lc_time_names ->name ,strlen (flags.lc_time_names ->name ), scs);
187
+
188
+ table->field [COLUMN_CLIENT_LONG_FLAG]->store (flags.client_long_flag , 0 );
189
+ table->field [COLUMN_CLIENT_PROTOCOL_41]->store (flags.client_protocol_41 , 0 );
190
+ table->field [COLUMN_PROTOCOL_TYPE]->store (flags.protocol_type , 0 );
191
+ table->field [COLUMN_MORE_RESULTS_EXISTS]->store (flags.more_results_exists , 0 );
192
+ table->field [COLUMN_IN_TRANS]->store (flags.in_trans , 0 );
193
+ table->field [COLUMN_AUTOCOMMIT]->store (flags.autocommit , 0 );
194
+ table->field [COLUMN_PKT_NR]->store (flags.pkt_nr , 0 );
195
+
121
196
/* The database against which the statement is executed is part of the
122
197
query cache query key
123
198
*/
@@ -198,15 +273,15 @@ maria_declare_plugin(query_cache_info)
198
273
MYSQL_INFORMATION_SCHEMA_PLUGIN,
199
274
&qc_info_plugin,
200
275
" QUERY_CACHE_INFO" ,
201
- " Roland Bouman" ,
276
+ " Roland Bouman, Daniel Black " ,
202
277
" Lists all queries in the query cache." ,
203
278
PLUGIN_LICENSE_BSD,
204
279
qc_info_plugin_init, /* Plugin Init */
205
280
0 , /* Plugin Deinit */
206
- 0x0100 , /* version, hex */
281
+ 0x0101 , /* version, hex */
207
282
NULL , /* status variables */
208
283
NULL , /* system variables */
209
- " 1.0 " , /* version as a string */
284
+ " 1.1 " , /* version as a string */
210
285
MariaDB_PLUGIN_MATURITY_GAMMA
211
286
}
212
287
maria_declare_plugin_end;
0 commit comments