Skip to content

Commit d455793

Browse files
grooverdanvuvova
authored andcommitted
plugin - qc_info - add Query Cache flags
1 parent 3abfe76 commit d455793

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed
2.17 KB
Binary file not shown.
1.9 KB
Binary file not shown.

mysql-test/suite/plugins/t/qc_info_init.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,20 @@ insert into t1 values (1),(2),(3);
1212
select * from t1;
1313
select statement_schema, statement_text, result_blocks_count, result_blocks_size from information_schema.query_cache_info;
1414

15+
select @@time_zone into @time_zone;
16+
select @@default_week_format into @default_week_format;
17+
select @@character_set_client into @character_set_client;
18+
select @@character_set_results into @character_set_results;
19+
select @@sql_mode into @sql_mode;
20+
select @@div_precision_increment into @div_precision_increment;
21+
select @@lc_time_names into @lc_time_names;
22+
select @@max_sort_length into @max_sort_length;
23+
select @@autocommit into @autocommit;
24+
select @@group_concat_max_len into @group_concat_max_len;
25+
select Name into @new_time_zone from mysql.time_zone_name limit 1;
26+
set time_zone=@new_time_zone,default_week_format=4,character_set_client='binary',character_set_results='utf32',collation_connection='utf32_bin',sql_mode='STRICT_ALL_TABLES',div_precision_increment=7,lc_time_names='ar_SD',autocommit=0, group_concat_max_len=513, max_sort_length=1011;
27+
select * from t1;
28+
set time_zone= @time_zone, default_week_format= @default_week_format, character_set_client= @character_set_client,character_set_results= @character_set_results, sql_mode= @sql_mode, div_precision_increment= @div_precision_increment, lc_time_names= @lc_time_names, autocommit= @autocommit, group_concat_max_len= @group_concat_max_len, max_sort_length= @max_sort_length;
29+
30+
select * from information_schema.query_cache_info;
31+

plugin/qc_info/qc_info.cc

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
*/
2929

3030

31-
/*
32-
* TODO: report query cache flags
33-
*/
3431
#ifndef MYSQL_SERVER
3532
#define MYSQL_SERVER
3633
#endif
@@ -40,6 +37,8 @@
4037
#include <sql_acl.h> // PROCESS_ACL
4138
#include <sql_class.h> // THD
4239
#include <table.h> // ST_SCHEMA_TABLE
40+
#include <set_var.h> // sql_mode_string_representation
41+
#include <tztime.h>
4342
#include <mysql/plugin.h>
4443

4544
class Accessible_Query_Cache : public Query_cache {
@@ -58,6 +57,25 @@ bool schema_table_store_record(THD *thd, TABLE *table);
5857
#define COLUMN_RESULT_BLOCKS_COUNT 2
5958
#define COLUMN_RESULT_BLOCKS_SIZE 3
6059
#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
6179

6280
/* ST_FIELD_INFO is defined in table.h */
6381
static ST_FIELD_INFO qc_info_fields[]=
@@ -67,6 +85,24 @@ static ST_FIELD_INFO qc_info_fields[]=
6785
{"RESULT_BLOCKS_COUNT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0},
6886
{"RESULT_BLOCKS_SIZE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0},
6987
{"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},
70106
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
71107
};
72108

@@ -91,15 +127,22 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables,
91127
const uchar *query_cache_block_raw;
92128
Query_cache_block* query_cache_block;
93129
Query_cache_query* query_cache_query;
130+
Query_cache_query_flags flags;
94131
uint result_blocks_count;
95132
ulonglong result_blocks_size;
96133
ulonglong result_blocks_size_used;
97134
Query_cache_block *first_result_block;
98135
Query_cache_block *result_block;
99136
const char *statement_text;
100137
size_t statement_text_length;
138+
size_t flags_length;
101139
const char *key, *db;
102140
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;
103146

104147
query_cache_block_raw = my_hash_element(queries, i);
105148
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,
118161
/* get the entire key that identifies this query cache query */
119162
key = (const char*)query_cache_query_get_key(query_cache_block_raw,
120163
&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+
121196
/* The database against which the statement is executed is part of the
122197
query cache query key
123198
*/
@@ -198,15 +273,15 @@ maria_declare_plugin(query_cache_info)
198273
MYSQL_INFORMATION_SCHEMA_PLUGIN,
199274
&qc_info_plugin,
200275
"QUERY_CACHE_INFO",
201-
"Roland Bouman",
276+
"Roland Bouman, Daniel Black",
202277
"Lists all queries in the query cache.",
203278
PLUGIN_LICENSE_BSD,
204279
qc_info_plugin_init, /* Plugin Init */
205280
0, /* Plugin Deinit */
206-
0x0100, /* version, hex */
281+
0x0101, /* version, hex */
207282
NULL, /* status variables */
208283
NULL, /* system variables */
209-
"1.0", /* version as a string */
284+
"1.1", /* version as a string */
210285
MariaDB_PLUGIN_MATURITY_GAMMA
211286
}
212287
maria_declare_plugin_end;

0 commit comments

Comments
 (0)