List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:August 26 2010 12:03pm
Subject:bzr commit into mysql-next-mr-bugfixing branch (jorgen.loland:3248) Bug#30597
View as plain text  
#At file:///export/home/jl208045/mysql/mysql-next-mr-bugfixing-30597/ based on revid:holyfoot@stripped

 3248 Jorgen Loland	2010-08-26
      Bug#30597: Change EXPLAIN output to include extrema of 
                 UNION components
            
      Previously, EXPLAIN of a large union would truncate the 
      UNION RESULT row at the end of the list like this if the 
      string got too large:
            
      <union1,2,3,4,...>
            
      With this patch, truncation happens in the middle of the string
      like this:
            
      <union1,2,3,...,9>
            
      This makes it easier to understand the boundaries of the UNION.
     @ mysql-test/r/explain.result
        Added test for BUG#30597
     @ mysql-test/t/explain.test
        Added test for BUG#30597
     @ sql/sql_lex.h
        Add inline function st_select_lex::last_select()
     @ sql/sql_select.cc
        Truncate UNION RESULT row of large UNIONs in the middle of the
        string instead of in the end

    modified:
      mysql-test/r/explain.result
      mysql-test/t/explain.test
      sql/sql_lex.h
      sql/sql_select.cc
=== modified file 'mysql-test/r/explain.result'
--- a/mysql-test/r/explain.result	2010-08-05 14:09:06 +0000
+++ b/mysql-test/r/explain.result	2010-08-26 12:02:59 +0000
@@ -283,4 +283,45 @@ explain extended select 1 from `t1`, `t1
 where `t1`.`a`  > all ( (select `a` from `t1` ) union (select `a`) );
 ERROR 23000: Column 'a' in field list is ambiguous
 drop table t1;
+# 
+# BUG#30597: Change EXPLAIN output to include extrema of 
+#            UNION components
+# 
+EXPLAIN
+SELECT 1
+UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+2	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+3	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+4	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+5	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+6	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+7	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+8	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+9	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+10	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+11	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+12	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+13	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+14	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+15	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+16	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+17	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+18	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+19	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+20	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+21	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+22	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+23	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+24	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+25	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+NULL	UNION RESULT	<union1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,...,25>	ALL	NULL	NULL	NULL	NULL	NULL	
+# End BUG#30597
 End of 6.0 tests.

=== modified file 'mysql-test/t/explain.test'
--- a/mysql-test/t/explain.test	2010-08-05 14:09:06 +0000
+++ b/mysql-test/t/explain.test	2010-08-26 12:02:59 +0000
@@ -262,4 +262,21 @@ explain extended select 1 from `t1`, `t1
 where `t1`.`a`  > all ( (select `a` from `t1` ) union (select `a`) );
 drop table t1;
 
+--echo # 
+--echo # BUG#30597: Change EXPLAIN output to include extrema of 
+--echo #            UNION components
+--echo # 
+
+EXPLAIN
+ SELECT 1
+ UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+ UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+ UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+ UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+ UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+ UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1
+ ;
+
+--echo # End BUG#30597
+
 --echo End of 6.0 tests.

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2010-08-20 03:51:38 +0000
+++ b/sql/sql_lex.h	2010-08-26 12:02:59 +0000
@@ -759,6 +759,14 @@ public:
   }
   st_select_lex* outer_select();
   st_select_lex* next_select() { return (st_select_lex*) next; }
+
+  inline st_select_lex* last_select() 
+  { 
+    st_select_lex* mylast= this;
+    for (; mylast->next_select(); mylast= mylast->next_select());
+    return mylast; 
+  }
+
   st_select_lex* next_select_in_list() 
   {
     return (st_select_lex*) link_next;

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-08-16 07:30:40 +0000
+++ b/sql/sql_select.cc	2010-08-26 12:02:59 +0000
@@ -22040,7 +22040,7 @@ void select_describe(JOIN *join, bool ne
       the UNION to provide precise EXPLAIN information will hardly be
       appreciated :)
     */
-    char table_name_buffer[NAME_LEN];
+    char table_name_buffer[NAME_CHAR_LEN];
     item_list.empty();
     /* id */
     item_list.push_back(new Item_null);
@@ -22050,25 +22050,35 @@ void select_describe(JOIN *join, bool ne
 					cs));
     /* table */
     {
+      SELECT_LEX *last_select= join->unit->first_select()->last_select();
+      // # characters needed to print select_number of last select
+      int last_length= log10(last_select->select_number)+1;
+
       SELECT_LEX *sl= join->unit->first_select();
       uint len= 6, lastop= 0;
       memcpy(table_name_buffer, STRING_WITH_LEN("<union"));
-      for (; sl && len + lastop + 5 < NAME_LEN; sl= sl->next_select())
+      /*
+        - len + lastop: current position in table_name_buffer
+        - 6 + last_length: the number of characters needed to print
+          '...,'<last_select->select_number>'>\0'
+      */
+      for (; 
+           sl && len + lastop + 6 + last_length < NAME_CHAR_LEN; 
+           sl= sl->next_select())
       {
         len+= lastop;
-        lastop= my_snprintf(table_name_buffer + len, NAME_LEN - len,
+        lastop= my_snprintf(table_name_buffer + len, NAME_CHAR_LEN - len,
                             "%u,", sl->select_number);
       }
-      if (sl || len + lastop >= NAME_LEN)
+      if (sl || len + lastop >= NAME_CHAR_LEN)
       {
-        memcpy(table_name_buffer + len, STRING_WITH_LEN("...>") + 1);
+        memcpy(table_name_buffer + len, STRING_WITH_LEN("...,"));
         len+= 4;
+        lastop= my_snprintf(table_name_buffer + len, NAME_CHAR_LEN - len,
+                            "%u,", last_select->select_number);
       }
-      else
-      {
-        len+= lastop;
-        table_name_buffer[len - 1]= '>';  // change ',' to '>'
-      }
+      len+= lastop;
+      table_name_buffer[len - 1]= '>';  // change ',' to '>'
       item_list.push_back(new Item_string(table_name_buffer, len, cs));
     }
     /* partitions */


Attachment: [text/bzr-bundle] bzr/jorgen.loland@oracle.com-20100826120259-h7hhhe9k0t05fytd.bundle
Thread
bzr commit into mysql-next-mr-bugfixing branch (jorgen.loland:3248) Bug#30597Jorgen Loland26 Aug