List:Internals« Previous MessageNext Message »
From:Luciano Rodrigues Furtado Date:December 10 2004 1:17pm
Subject:SHOW QUERY CACHE patch proposal
View as plain text  
Hi

i have created this patch , that creates SHOW QUERY CACHE; command
that enables a user to see the queries in the cache. I would like
somme feed back, to see if i am doing something terribly wrong.

One thing i am having problems is that i had to set a fixed size of 200
for the max query size that is shown, i havent found in the code
the limit for the query size. Is it the max_allowed_packet_size?

anyways here is the patch

diff -u -r mysql-4.1.7/sql/sql_cache.cc mysql-4.1.7-query_cache/sql/sql_cache.cc
--- mysql-4.1.7/sql/sql_cache.cc	2004-10-23 05:28:47.000000000 -0200
+++ mysql-4.1.7-query_cache/sql/sql_cache.cc	2004-12-10 09:55:18.000000000 -0200
@@ -898,6 +898,43 @@
 }
 
 
+void 
+Query_cache::list_queries(THD *thd)
+{
+  List<Item> field_list;
+  Protocol *protocol= thd->protocol;
+
+  DBUG_ENTER("Query_cache::list_queries");
+
+  field_list.push_back(new Item_empty_string("Query",200));
+
+  if (protocol->send_fields(&field_list,1))
+    DBUG_VOID_RETURN;
+
+
+  STRUCT_LOCK(&structure_guard_mutex);
+  for (uint idx=0 ; idx < queries.records ; idx++)
+  {
+     protocol->prepare_for_resend();
+     Query_cache_block *b= (Query_cache_block*) hash_element(&queries,idx);
+
+
+     protocol->store(b->query()->query(), system_charset_info);
+     
+     if (protocol->write()) 
+     {
+       STRUCT_UNLOCK(&structure_guard_mutex);
+       DBUG_VOID_RETURN;
+     }
+  }
+  STRUCT_UNLOCK(&structure_guard_mutex);
+
+  send_eof(thd);
+
+  DBUG_VOID_RETURN;
+}
+
+
 /*
   Check if the query is in the cache. If it was cached, send it
   to the user.
diff -u -r mysql-4.1.7/sql/sql_cache.h mysql-4.1.7-query_cache/sql/sql_cache.h
--- mysql-4.1.7/sql/sql_cache.h	2004-10-23 05:28:44.000000000 -0200
+++ mysql-4.1.7-query_cache/sql/sql_cache.h	2004-12-10 09:55:18.000000000 -0200
@@ -361,6 +361,8 @@
   /* register query in cache */
   void store_query(THD *thd, TABLE_LIST *used_tables);
 
+
+  void list_queries(THD *thd);
   /*
     Check if the query is in the cache and if this is true send the
     data to client.
diff -u -r mysql-4.1.7/sql/sql_lex.h mysql-4.1.7-query_cache/sql/sql_lex.h
--- mysql-4.1.7/sql/sql_lex.h	2004-10-23 05:28:43.000000000 -0200
+++ mysql-4.1.7-query_cache/sql/sql_lex.h	2004-12-10 09:55:18.000000000 -0200
@@ -47,7 +47,7 @@
   SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT,
   SQLCOM_DELETE, SQLCOM_TRUNCATE, SQLCOM_DROP_TABLE, SQLCOM_DROP_INDEX,
 
-  SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
+  SQLCOM_SHOW_QUERY_CACHE, SQLCOM_SHOW_DATABASES, SQLCOM_SHOW_TABLES, SQLCOM_SHOW_FIELDS,
   SQLCOM_SHOW_KEYS, SQLCOM_SHOW_VARIABLES, SQLCOM_SHOW_LOGS, SQLCOM_SHOW_STATUS,
   SQLCOM_SHOW_INNODB_STATUS,
   SQLCOM_SHOW_PROCESSLIST, SQLCOM_SHOW_MASTER_STAT, SQLCOM_SHOW_SLAVE_STAT,
diff -u -r mysql-4.1.7/sql/sql_parse.cc mysql-4.1.7-query_cache/sql/sql_parse.cc
--- mysql-4.1.7/sql/sql_parse.cc	2004-10-23 05:28:43.000000000 -0200
+++ mysql-4.1.7-query_cache/sql/sql_parse.cc	2004-12-10 09:55:18.000000000 -0200
@@ -16,6 +16,7 @@
 
 #include "mysql_priv.h"
 #include "sql_acl.h"
+#include "sql_cache.h"
 #include "sql_repl.h"
 #include "repl_failsafe.h"
 #include <m_ctype.h>
@@ -71,6 +72,7 @@
 };
 
 static char empty_c_string[1]= {0};		// Used for not defined 'db'
+extern Query_cache query_cache;
 
 #ifdef __WIN__
 static void  test_signal(int sig_ptr)
@@ -2857,6 +2859,9 @@
     else
       res = mysql_drop_index(thd, tables, &lex->alter_info);
     break;
+  case SQLCOM_SHOW_QUERY_CACHE:
+    query_cache.list_queries(thd);
+    break;
   case SQLCOM_SHOW_DATABASES:
 #if defined(DONT_ALLOW_SHOW_COMMANDS)
     send_error(thd,ER_NOT_ALLOWED_COMMAND);   /* purecov: inspected */
diff -u -r mysql-4.1.7/sql/sql_yacc.yy mysql-4.1.7-query_cache/sql/sql_yacc.yy
--- mysql-4.1.7/sql/sql_yacc.yy	2004-10-23 05:28:44.000000000 -0200
+++ mysql-4.1.7-query_cache/sql/sql_yacc.yy	2004-12-10 09:55:18.000000000 -0200
@@ -4293,7 +4293,9 @@
 	;
 
 show_param:
-	DATABASES wild
+          QUERY_SYM CACHE_SYM
+          { Lex->sql_command= SQLCOM_SHOW_QUERY_CACHE;}
+	| DATABASES wild
 	  { Lex->sql_command= SQLCOM_SHOW_DATABASES; }
 	| TABLES opt_db wild
 	  {


-- 
Luciano Rodrigues Furtado                | Linux Certified Professional(LPIC1) 
Analista de Sistemas                     | LPI ID: LPI000061073 
ICQ: 306317188                           | Verification Code: 2qhb3mgvs7
MSN: lrfurtado@stripped               | MySQL Certified Professional 
--------------------------------------------------------------------------------
Bread from the bakery, Meat from the butcher and Multiplatform 
operating systems from the NetBSD Foundation.

Attachment: [application/pgp-signature]
Thread
SHOW QUERY CACHE patch proposalLuciano Rodrigues Furtado10 Dec
  • Re: SHOW QUERY CACHE patch proposalDouglas K. Fischer10 Dec
  • Re: SHOW QUERY CACHE patch proposalSanja Byelkin11 Dec
    • Re: SHOW QUERY CACHE patch proposalLuciano Rodrigues Furtado11 Dec
      • Re: SHOW QUERY CACHE patch proposalSanja Byelkin12 Dec