From 4525e7fdb6a88873ed360f1ace7abeae210f6819 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 18 May 2015 22:03:01 +1000 Subject: [PATCH 1/2] plugin - qc_info - add Query Cache flags --- mysql-test/suite/plugins/r/qc_info.result | Bin 780 -> 2963 bytes mysql-test/suite/plugins/t/qc_info_init.inc | 17 ++++ plugin/qc_info/qc_info.cc | 87 ++++++++++++++++++-- 3 files changed, 98 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/plugins/r/qc_info.result b/mysql-test/suite/plugins/r/qc_info.result index ab646d745111b1788c26e797252210f066430345..14e155f6111adfd42fd9b3e189e0c419e7af89e6 100644 GIT binary patch literal 2963 zcmeHJTW_046wd4TSInE!726HA)9fljf{;mq!o`L0ZrYb4f+qFL?ohx1WViC79M-T5djYEel=EtSBxI9rLD9_#P4;|YGJC{l||B$EC@AF47(q4QBZ z(npigbi=77I>|*Lp~evMSfe|N6yK#rD^ag93HMo6!L>iHx)f^ta)JoaeH;Yf;Fl750jC#U*klbvbGG#BurEJOp-?s ztWtat;tMqKx6%Wgj$ZNI ziDmi?o-2{0wJJkeU?-^xZ*m&ucJ#9Z*02?Ej{UT5FLRI9k?g zJM!^LmPwiC=_Z^Vp(FKJm8)m$wIYcnC}U{7H9f@IYWf&)D_4k@CX03P*X^IbB3SRY z9RVsonx!fh91N@>-SP}`PhT5o1Y@QRRoNKdr$t=7j(gm;kj8i=AEp!JmRZ)!38q=# zkYcS`CZL6}wkfPJj(F(U94yxbZe6%68fyniY@BI(g)+u*1<~bL+o5cnXmkie<5Zt& zv{yJoKhf9F^tZ_9=;%mS$3z`!n{>gWyD`(~5Oj2C<}^BpCpCx22hi;cx2WS*Yp2Gb z=H@SkHarR_bAY4KeR%2qTxhg|Gc|V)2Oy{BP$hn@0yTSe**1K;*#FVmjkv{`$9xWv zeZxG9>v#?)o^=ON5OQ#tf6Z^m zbr>w>Xw0`Q4vN{*?Hen!Y|cW67zf*RFfOuBY~mqy;JOxf0-tclW1j<`kxO=EsZjr7 z>=v$q(6czXbpC{S$ZRJvu<)%*is--p zL4MVVnlZezrleUMWW6AoQ*8pmR#o{de)GyYDPPEpoMGX53xTZ19Pd7zoU|YPZP%FI z+Vy0H{_#+|sL=O+pneg{w0?plCDEq{n+I*r2oVKVyyFbrj+PkX_FZM$p1X_vKlgT_ dHrj!AG-}Y3ZHoU-;J // PROCESS_ACL #include // THD #include // ST_SCHEMA_TABLE +#include // sql_mode_string_representation +#include #include class Accessible_Query_Cache : public Query_cache { @@ -58,6 +57,25 @@ bool schema_table_store_record(THD *thd, TABLE *table); #define COLUMN_RESULT_BLOCKS_COUNT 2 #define COLUMN_RESULT_BLOCKS_SIZE 3 #define COLUMN_RESULT_BLOCKS_SIZE_USED 4 +#define COLUMN_LIMIT 5 +#define COLUMN_MAX_SORT_LENGTH 6 +#define COLUMN_GROUP_CONCAT_MAX_LENGTH 7 +#define COLUMN_CHARACTER_SET_CLIENT 8 +#define COLUMN_CHARACTER_SET_RESULT 9 +#define COLUMN_COLLATION 10 +#define COLUMN_TIMEZONE 11 +#define COLUMN_DEFAULT_WEEK_FORMAT 12 +#define COLUMN_DIV_PRECISION_INCREMENT 13 +#define COLUMN_SQL_MODE 14 +#define COLUMN_LC_TIME_NAMES 15 + +#define COLUMN_CLIENT_LONG_FLAG 16 +#define COLUMN_CLIENT_PROTOCOL_41 17 +#define COLUMN_PROTOCOL_TYPE 18 +#define COLUMN_MORE_RESULTS_EXISTS 19 +#define COLUMN_IN_TRANS 20 +#define COLUMN_AUTOCOMMIT 21 +#define COLUMN_PKT_NR 22 /* ST_FIELD_INFO is defined in table.h */ static ST_FIELD_INFO qc_info_fields[]= @@ -67,6 +85,24 @@ static ST_FIELD_INFO qc_info_fields[]= {"RESULT_BLOCKS_COUNT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0}, {"RESULT_BLOCKS_SIZE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, {"RESULT_BLOCKS_SIZE_USED", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"LIMIT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"MAX_SORT_LENGTH", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"GROUP_CONCAT_MAX_LENGTH", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, + {"CHARACTER_SET_CLIENT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"CHARACTER_SET_RESULT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"COLLATION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"TIMEZONE", 50, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"DEFAULT_WEEK_FORMAT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"DIV_PRECISION_INCREMENT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0}, + {"SQL_MODE", 250, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"LC_TIME_NAMES", 100, MYSQL_TYPE_STRING, 0, 0, 0, 0}, + {"CLIENT_LONG_FLAG", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, + {"CLIENT_PROTOCOL_41", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, + {"PROTOCOL_TYPE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, + {"MORE_RESULTS_EXISTS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, + {"IN_TRANS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, + {"AUTOCOMMIT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, + {"PACKET_NUMBER", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} }; @@ -91,6 +127,7 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables, const uchar *query_cache_block_raw; Query_cache_block* query_cache_block; Query_cache_query* query_cache_query; + Query_cache_query_flags flags; uint result_blocks_count; ulonglong result_blocks_size; ulonglong result_blocks_size_used; @@ -98,8 +135,14 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables, Query_cache_block *result_block; const char *statement_text; size_t statement_text_length; + size_t flags_length; const char *key, *db; size_t key_length, db_length; + LEX_STRING sql_mode_str; + const String *tz; + CHARSET_INFO *cs_client; + CHARSET_INFO *cs_result; + CHARSET_INFO *collation; query_cache_block_raw = my_hash_element(queries, i); 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, /* get the entire key that identifies this query cache query */ key = (const char*)query_cache_query_get_key(query_cache_block_raw, &key_length, 0); + /* get and store the flags */ + flags_length= key_length - QUERY_CACHE_FLAGS_SIZE; + memcpy(&flags, key+flags_length, QUERY_CACHE_FLAGS_SIZE); + table->field[COLUMN_LIMIT]->store(flags.limit, 0); + table->field[COLUMN_MAX_SORT_LENGTH]->store(flags.max_sort_length, 0); + table->field[COLUMN_GROUP_CONCAT_MAX_LENGTH]->store(flags.group_concat_max_len, 0); + + cs_client= get_charset(flags.character_set_client_num, MYF(MY_WME)); + table->field[COLUMN_CHARACTER_SET_CLIENT]->store(cs_client->csname, strlen(cs_client->csname), scs); + cs_result= get_charset(flags.character_set_results_num, MYF(MY_WME)); + table->field[COLUMN_CHARACTER_SET_RESULT]->store(cs_result->csname, strlen(cs_result->csname), scs); + collation= get_charset(flags.collation_connection_num, MYF(MY_WME)); + table->field[COLUMN_COLLATION]->store(collation->name, strlen(collation->name), scs); + + tz= flags.time_zone->get_name(); + table->field[COLUMN_TIMEZONE]->store(tz->ptr(), tz->length(), scs); + table->field[COLUMN_DEFAULT_WEEK_FORMAT]->store(flags.default_week_format, 0); + table->field[COLUMN_DIV_PRECISION_INCREMENT]->store(flags.div_precision_increment, 0); + + sql_mode_string_representation(thd, flags.sql_mode, &sql_mode_str); + table->field[COLUMN_SQL_MODE]->store(sql_mode_str.str, sql_mode_str.length, scs); + + table->field[COLUMN_LC_TIME_NAMES]->store(flags.lc_time_names->name,strlen(flags.lc_time_names->name), scs); + + table->field[COLUMN_CLIENT_LONG_FLAG]->store(flags.client_long_flag, 0); + table->field[COLUMN_CLIENT_PROTOCOL_41]->store(flags.client_protocol_41, 0); + table->field[COLUMN_PROTOCOL_TYPE]->store(flags.protocol_type, 0); + table->field[COLUMN_MORE_RESULTS_EXISTS]->store(flags.more_results_exists, 0); + table->field[COLUMN_IN_TRANS]->store(flags.in_trans, 0); + table->field[COLUMN_AUTOCOMMIT]->store(flags.autocommit, 0); + table->field[COLUMN_PKT_NR]->store(flags.pkt_nr, 0); + /* The database against which the statement is executed is part of the query cache query key */ @@ -198,15 +273,15 @@ maria_declare_plugin(query_cache_info) MYSQL_INFORMATION_SCHEMA_PLUGIN, &qc_info_plugin, "QUERY_CACHE_INFO", - "Roland Bouman", + "Roland Bouman, Daniel Black", "Lists all queries in the query cache.", PLUGIN_LICENSE_BSD, qc_info_plugin_init, /* Plugin Init */ 0, /* Plugin Deinit */ - 0x0100, /* version, hex */ + 0x0101, /* version, hex */ NULL, /* status variables */ NULL, /* system variables */ - "1.0", /* version as a string */ + "1.1", /* version as a string */ MariaDB_PLUGIN_MATURITY_GAMMA } maria_declare_plugin_end; From 61bfa3d1ba5f6e2037a3b548d1ec60c669d84853 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 28 May 2015 22:42:32 +1000 Subject: [PATCH 2/2] plugin: qc_info test - hide output so result isn't a binary file --- mysql-test/suite/plugins/r/qc_info.result | Bin 2963 -> 2947 bytes mysql-test/suite/plugins/t/qc_info_init.inc | 2 ++ 2 files changed, 2 insertions(+) diff --git a/mysql-test/suite/plugins/r/qc_info.result b/mysql-test/suite/plugins/r/qc_info.result index 14e155f6111adfd42fd9b3e189e0c419e7af89e6..ed85936a098b36f9d72b0983d60a3366e84232cc 100644 GIT binary patch delta 12 TcmbO%-YmZ15XX#+wha9AX0iRn7&z diff --git a/mysql-test/suite/plugins/t/qc_info_init.inc b/mysql-test/suite/plugins/t/qc_info_init.inc index 133cd28018c54..ca259abddc4cc 100644 --- a/mysql-test/suite/plugins/t/qc_info_init.inc +++ b/mysql-test/suite/plugins/t/qc_info_init.inc @@ -22,7 +22,9 @@ select @@autocommit into @autocommit; select @@group_concat_max_len into @group_concat_max_len; select Name into @new_time_zone from mysql.time_zone_name limit 1; 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; +--disable_result_log select * from t1; +--enable_result_log 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; select * from information_schema.query_cache_info;