[Commits] Rev 3504: Make SHOW EXPLAIN FOR produce a warning with the original text of query in file:///home/psergey/dev2/5.3-show-explain-r20/

Sergey Petrunya psergey at askmonty.org
Thu Apr 26 06:18:32 EEST 2012


At file:///home/psergey/dev2/5.3-show-explain-r20/

------------------------------------------------------------
revno: 3504
revision-id: psergey at askmonty.org-20120426031831-0iujnre01v3tlwkf
parent: psergey at askmonty.org-20120426014734-1az0fcps2270w100
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.3-show-explain-r20
timestamp: Thu 2012-04-26 08:48:31 +0530
message:
  Make SHOW EXPLAIN FOR produce a warning with the original text of query 
  that the EXPLAIN is for.
=== modified file 'mysql-test/r/show_explain.result'
--- a/mysql-test/r/show_explain.result	2012-04-26 01:10:36 +0000
+++ b/mysql-test/r/show_explain.result	2012-04-26 03:18:31 +0000
@@ -20,12 +20,16 @@
 show explain for $thr2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	index	a	a	5	NULL	1000	Using where; Using index
+Warnings:
+Note	1003	select count(*) from t1 where a < 100000
 count(*)
 1000
 select max(c) from t1 where a < 10;
 show explain for $thr2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	range	a	a	5	NULL	10	Using index condition
+Warnings:
+Note	1003	select max(c) from t1 where a < 10
 max(c)
 9
 # We can catch EXPLAIN, too.
@@ -35,6 +39,8 @@
 show explain for $thr2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	range	a	a	5	NULL	10	Using index condition; Rowid-ordered scan
+Warnings:
+Note	1003	explain select max(c) from t1 where a < 10
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	range	a	a	5	NULL	10	Using index condition; Rowid-ordered scan
 set optimizer_switch= @show_expl_tmp;
@@ -47,6 +53,8 @@
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	
 2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	
 NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
+Warnings:
+Note	1003	explain select a from t0 A union select a+1 from t0 B
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	
 2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	
@@ -60,6 +68,8 @@
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	
 2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	
 NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
+Warnings:
+Note	1003	explain select a from t0 A union select a+1 from t0 B
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	
 2	UNION	B	ALL	NULL	NULL	NULL	NULL	10	
@@ -72,6 +82,8 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	SUBQUERY	B	ALL	NULL	NULL	NULL	NULL	10	
+Warnings:
+Note	1003	select a, (select max(a) from t0 B) from t0 A where a<1
 a	(select max(a) from t0 B)
 0	9
 # Uncorrelated  subquery, explain
@@ -82,6 +94,8 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	SUBQUERY	B	ALL	NULL	NULL	NULL	NULL	10	
+Warnings:
+Note	1003	explain select a, (select max(a) from t0 B) from t0 A where a<1
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	A	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	SUBQUERY	B	ALL	NULL	NULL	NULL	NULL	10	
@@ -93,6 +107,8 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
 a	(select max(a) from t0 b where b.a+a.a<10)
 0	9
 # correlated  subquery, explain
@@ -103,6 +119,8 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
 a	(select max(a) from t0 b where b.a+a.a<10)
 0	9
 # correlated  subquery, select, while inside the subquery
@@ -113,6 +131,8 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
 a	(select max(a) from t0 b where b.a+a.a<10)
 0	9
 # correlated  subquery, explain, while inside the subquery
@@ -123,6 +143,8 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	a	ALL	NULL	NULL	NULL	NULL	10	Using where
 2	DEPENDENT SUBQUERY	b	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1
 a	(select max(a) from t0 b where b.a+a.a<10)
 0	9
 # Try to do SHOW EXPLAIN for a query that runs a  SET command:
@@ -168,14 +190,20 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
 2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
-show explain for $thr2;
-id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
-2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
-show explain for $thr2;
-id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
-2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
+show explain for $thr2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
+2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
+show explain for $thr2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
+2	DEPENDENT SUBQUERY	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
+Warnings:
+Note	1003	select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2
 a	SUBQ
 0	0
 1	0

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2012-04-26 01:10:36 +0000
+++ b/sql/sql_class.cc	2012-04-26 03:18:31 +0000
@@ -3030,14 +3030,20 @@
   //TODO: change mem_root to point to request_thd->mem_root.
   //      Actually, change the ARENA, because we're going to allocate items!
   Query_arena backup_arena;
-  req->target_thd->set_n_backup_active_arena((Query_arena*)req->request_thd,
-                                             &backup_arena);
-
-  if (req->target_thd->lex->unit.print_explain(req->explain_buf))
+  THD *target_thd= req->target_thd;
+
+  target_thd->set_n_backup_active_arena((Query_arena*)req->request_thd,
+                                        &backup_arena);
+  
+  req->query_str.copy(target_thd->query(), 
+                      target_thd->query_length(),
+                      &my_charset_bin);
+
+  if (target_thd->lex->unit.print_explain(req->explain_buf))
     req->failed_to_produce= TRUE;
 
-  req->target_thd->restore_active_arena((Query_arena*)req->request_thd, 
-                                        &backup_arena);
+  target_thd->restore_active_arena((Query_arena*)req->request_thd, 
+                                   &backup_arena);
 }
 
 

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2012-04-26 01:10:36 +0000
+++ b/sql/sql_class.h	2012-04-26 03:18:31 +0000
@@ -1471,6 +1471,8 @@
   
   select_result_explain_buffer *explain_buf;
 
+  String query_str;
+
   static void get_explain_data(void *arg);
 };
 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2012-04-26 01:10:36 +0000
+++ b/sql/sql_show.cc	2012-04-26 03:18:31 +0000
@@ -2126,6 +2126,11 @@
                "Target is not running EXPLAINable command");
       bres= TRUE;
     }
+    else
+    {
+      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+                   ER_YES, explain_req.query_str.c_ptr_safe());
+    }
     pthread_mutex_unlock(&tmp->LOCK_thd_data);
     if (!bres)
     {



More information about the commits mailing list