List:Commits« Previous MessageNext Message »
From:Guilhem Bichot Date:October 15 2010 12:46pm
Subject:bzr commit into mysql-next-mr-bugfixing branch (guilhem:3220)
View as plain text  
#At file:///home/mysql_src/bzrrepos_new/mysql-next-mr-opt-backporting-wl4800/ based on revid:guilhem@stripped

 3220 Guilhem Bichot	2010-10-15
      less calls to strlen() for fixed-size strings:
      use String::append(char*,size_t) instead of String::append(char*).
      Fix for crash of subquery_mat --opt-trace-protocol (Item_ref again)
     @ mysql-test/r/optimizer_trace_ps_prot.result
        because now we print Item_ref's target only if Item_ref is fixed,
        we get a bit less information when using prepared statements in some cases.

    modified:
      WL4800_TODO.txt
      mysql-test/r/optimizer_trace_ps_prot.result
      sql/item.cc
      sql/opt_trace.cc
=== modified file 'WL4800_TODO.txt'
--- a/WL4800_TODO.txt	2010-10-05 10:29:43 +0000
+++ b/WL4800_TODO.txt	2010-10-15 12:46:54 +0000
@@ -1,6 +1,8 @@
 Short-term TODO list to remember for WL#4800
 ============================================
 
+avoid strlen() when appending constant strings.
+
 void QUICK_RANGE_SELECT::dbug_dump(int indent, bool verbose)
 doesn't use "verbose".
 

=== modified file 'mysql-test/r/optimizer_trace_ps_prot.result'
--- a/mysql-test/r/optimizer_trace_ps_prot.result	2010-10-09 15:04:30 +0000
+++ b/mysql-test/r/optimizer_trace_ps_prot.result	2010-10-15 12:46:54 +0000
@@ -490,7 +490,7 @@ QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM
 SELECT * FROM C WHERE 5 IN (SELECT 1 FROM D WHERE d = ifnull(c,null) UNION SELECT 2 FROM D WHERE d = ifnull(c,null))	{
   "steps": [
     {
-      "expanded_query": "/* select#1 */ select `test`.`C`.`c` AS `c` from `test`.`C` where <in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`D` where ((`d` = ifnull(`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`D` where ((`d` = ifnull(`c`,NULL)) and (<cache>(5) = 2))))"
+      "expanded_query": "/* select#1 */ select `test`.`C`.`c` AS `c` from `test`.`C` where <in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`D` where ((`d` = ifnull(`c`,NULL)) and (`<no matter>`.`<left expr>` = 1)) union /* select#3 */ select 1 from `test`.`D` where ((`d` = ifnull(`c`,NULL)) and (`<no matter>`.`<left expr>` = 2))))"
     },
     {
       "join_preparation": {
@@ -694,7 +694,7 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-8104
+8138
 set optimizer_trace_max_mem_size=8400;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
@@ -711,7 +711,7 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-8104	1	1
+8138	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-100) and (@@optimizer_trace_max_mem_size+100);
 length(@query2) + length(@trace2)
@@ -3332,7 +3332,7 @@ QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM
 select * from t1 where (t1.a,t1.b) not in (select c,d from t2 where c>0)	{
   "steps": [
     {
-      "expanded_query": "/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (not(<in_optimizer>((`t1`.`a`,`t1`.`b`),<exists>(/* select#2 */ select `c`,`d` from `test`.`t2` where ((`c` > 0) and trigcond_if(outer_field_is_not_null, ((`<no matter>`.`<left expr>` = `c`) or isnull(`c`)), true) and trigcond_if(outer_field_is_not_null, ((`<no matter>`.`<left expr>` = `d`) or isnull(`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`d`), true))))))"
+      "expanded_query": "/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (not(<in_optimizer>((`t1`.`a`,`t1`.`b`),<exists>(/* select#2 */ select `c`,`d` from `test`.`t2` where ((`c` > 0) and trigcond_if(outer_field_is_not_null, ((`<no matter>`.`<left expr>` = `<no matter>`.`<list ref>`) or isnull(`<no matter>`.`<list ref>`)), true) and trigcond_if(outer_field_is_not_null, ((`<no matter>`.`<left expr>` = `<no matter>`.`<list ref>`) or isnull(`<no matter>`.`<list ref>`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`<no matter>`.`<list ref>`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`<no matter>`.`<list ref>`), true))))))"
     },
     {
       "join_preparation": {

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2010-10-05 10:29:43 +0000
+++ b/sql/item.cc	2010-10-15 12:46:54 +0000
@@ -6465,9 +6465,11 @@ void Item_ref::print(String *str, enum_q
         Item_cache_row::cleanup() (called at the end of preparing, in
         Prepared_stmt::cleanup_stmt(), which calls cleanup_items()).
         Given that optimizer trace prints the item at this early stage, we
-        need to protect:
+        need to protect. There can also be cases where ref points to an Item,
+        in which case type() is pure virtual. It seems that when 'fixed' is
+        true, there is no risk:
       */
-      (*ref != NULL))
+      fixed)
   {
     if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
         !table_name && name && alias_name_used)

=== modified file 'sql/opt_trace.cc'
--- a/sql/opt_trace.cc	2010-10-09 15:04:30 +0000
+++ b/sql/opt_trace.cc	2010-10-15 12:46:54 +0000
@@ -46,12 +46,14 @@ void Opt_trace_struct::syntax_error(cons
   */
   if (key != NULL)
   {
-    stmt->buffer.append("** invalid JSON (unexpected key \"");
+    stmt->buffer.append(STRING_WITH_LEN("** invalid JSON"
+                                        " (unexpected key \""));
     stmt->buffer.append(key);
-    stmt->buffer.append("\") ** ");
+    stmt->buffer.append(STRING_WITH_LEN("\") ** "));
   }
   else
-    stmt->buffer.append("** invalid JSON (missing key) ** ");
+    stmt->buffer.append(STRING_WITH_LEN("** invalid JSON"
+                                        " (missing key) ** "));
 }
 
 
@@ -159,7 +161,7 @@ void Opt_trace_struct::add_key_name(cons
 #endif
     stmt->buffer.append('"');
     stmt->buffer.append(key);
-    stmt->buffer.append("\": ");
+    stmt->buffer.append(STRING_WITH_LEN("\": "));
   }
 }
 
@@ -196,9 +198,9 @@ void Opt_trace_struct::do_destruct(void)
     stmt->buffer.append(brackets[requires_key + 2]);
     if (stmt->ctx->end_marker && saved_key != NULL)
     {
-      stmt->buffer.append(" /* ");
+      stmt->buffer.append(STRING_WITH_LEN(" /* "));
       stmt->buffer.append(saved_key);
-      stmt->buffer.append(" */");
+      stmt->buffer.append(STRING_WITH_LEN(" */"));
     }
   }
   stmt->support_I_S= save_stmt_support_I_S;
@@ -280,13 +282,15 @@ Opt_trace_struct& Opt_trace_struct::do_a
 Opt_trace_struct& Opt_trace_struct::do_add(const char *key, bool val)
 {
   DBUG_ASSERT(started);
-  const char *readable= val ? "true" : "false";
-  DBUG_PRINT("opt_trace", ("%s: %s", key, readable));
+  DBUG_PRINT("opt_trace", ("%s: %d", key, (int)val));
   if (!stmt->support_I_S)
     return *this;
   stmt->separator();
   add_key_name(key);
-  stmt->buffer.append(readable);
+  LEX_CSTRING readables[]= { { STRING_WITH_LEN("false") },
+                             { STRING_WITH_LEN("true") } };
+  const LEX_CSTRING *readable= &readables[(int)val];
+  stmt->buffer.append(readable->str, readable->length);
   return *this;
 }
 
@@ -343,7 +347,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
     return *this;
   stmt->separator();
   add_key_name(key);
-  stmt->buffer.append("null");
+  stmt->buffer.append(STRING_WITH_LEN("null"));
   return *this;
 }
 
@@ -826,8 +830,8 @@ void Opt_trace_stmt::next_line(void)
   char spaces[]= "                               ";
   const int nb= depth * 2, spaces_len= sizeof(spaces) - 1;
   for (int i= 0; i < nb/spaces_len; i++)
-    buffer.append(spaces);
-  buffer.append(spaces + spaces_len - (nb % spaces_len));
+    buffer.append(spaces, spaces_len);
+  buffer.append(spaces, (nb % spaces_len));
 }
 
 


Attachment: [text/bzr-bundle] bzr/guilhem@mysql.com-20101015124654-zvfp2tq1kgqybo95.bundle
Thread
bzr commit into mysql-next-mr-bugfixing branch (guilhem:3220) Guilhem Bichot15 Oct