List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:March 15 2011 11:28am
Subject:bzr commit into mysql-trunk branch (jorgen.loland:3279)
View as plain text  
#At file:///export/home/jl208045/mysql/wl4800/mysql-next-mr-opt-backporting-wl4800/ based on revid:guilhem.bichot@stripped

 3279 Jorgen Loland	2011-03-15
      Review comment by Guilhem:
      
      Pass Opt_trace_array pointer to sel_arg_range_seq_next(), which 
      no longer needs to call get_current_struct() to get the optimizer
      trace array. With this, get_current_struct() is no longer used 
      outside the trace classes and can be made private or removed.

    modified:
      sql/handler.cc
      sql/handler.h
      sql/opt_range.cc
      sql/opt_range.h
      sql/sql_join_cache.cc
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2011-02-16 13:52:44 +0000
+++ b/sql/handler.cc	2011-03-15 11:28:17 +0000
@@ -4439,7 +4439,7 @@ handler::multi_range_read_info_const(uin
 
   seq_it= seq->init(seq_init_param, n_ranges, *flags);
   Opt_trace_array ota(thd->opt_trace, "ranges");
-  while (!seq->next(seq_it, &range))
+  while (!seq->next(seq_it, &range, &ota))
   {
     if (unlikely(thd->killed != 0))
       return HA_POS_ERROR;
@@ -4639,7 +4639,7 @@ int handler::multi_range_read_next(char 
 
 start:
     /* Try the next range(s) until one matches a record. */
-    while (!(range_res= mrr_funcs.next(mrr_iter, &mrr_cur_range)))
+    while (!(range_res= mrr_funcs.next(mrr_iter, &mrr_cur_range, NULL)))
     {
 scan_it_again:
       result= read_range_first(mrr_cur_range.start_key.keypart_map ?

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2011-02-16 13:52:44 +0000
+++ b/sql/handler.h	2011-03-15 11:28:17 +0000
@@ -28,6 +28,7 @@
 #include "thr_lock.h"          /* thr_lock_type, THR_LOCK_DATA */
 #include "sql_cache.h"
 #include "structs.h"                            /* SHOW_COMP_OPTION */
+#include "opt_trace.h"          // For Opt_trace_array
 
 #include <my_global.h>
 #include <my_handler.h>
@@ -1144,14 +1145,17 @@ typedef struct st_range_seq_if
 
     SYNOPSIS
       next()
-        seq    The value returned by RANGE_SEQ_IF::init()
-        range  OUT Information about the next range
+        seq          The value returned by RANGE_SEQ_IF::init()
+        range        OUT Information about the next range
+        trace_array  Optimizer trace-related information is appended to this if
+                     tracing is enabled. If NULL, no optimizer tracing is done
     
     RETURN
       0 - Ok, the range structure filled with info about the next range
       1 - No more ranges
   */
-  uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
+  uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range, 
+                Opt_trace_array *trace_array);
 
   /*
     Check whether range_info orders to skip the next record

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2011-02-16 15:06:06 +0000
+++ b/sql/opt_range.cc	2011-03-15 11:28:17 +0000
@@ -7969,13 +7969,16 @@ range_seq_t sel_arg_range_seq_init(void 
   return init_param;
 }
 
-
-static void step_down_to(String *s, SEL_ARG_RANGE_SEQ *arg, SEL_ARG *key_tree)
+/**
+ @param trace_string  Append range information for this part of the range
+                      condition to this String if not NULL. Used by optimizer
+                      trace
+*/
+static void step_down_to(String *trace_string, 
+                         SEL_ARG_RANGE_SEQ *arg, SEL_ARG *key_tree)
 {
 
-#ifdef OPTIMIZER_TRACE
-  if (unlikely(arg->param->thd->opt_trace != NULL) &&
-      arg->param->thd->opt_trace->is_started())
+  if (trace_string != NULL)
   {
     /*
        Stepping down will append the range for the current keypart (in
@@ -7985,11 +7988,10 @@ static void step_down_to(String *s, SEL_
     const KEY_PART_INFO *key_part=
       arg->param->table->key_info[arg->real_keyno].key_part + key_tree->part;
 
-    append_range(s, key_part,
+    append_range(trace_string, key_part,
                  key_tree->min_value, key_tree->max_value,
                  key_tree->min_flag | key_tree->max_flag);
   }
-#endif
 
   RANGE_SEQ_ENTRY *cur= &arg->stack[arg->i+1];
   RANGE_SEQ_ENTRY *prev= &arg->stack[arg->i];
@@ -8027,6 +8029,9 @@ static void step_down_to(String *s, SEL_
     sel_arg_range_seq_next()
       rseq        Value returned from sel_arg_range_seq_init
       range  OUT  Store information about the range here
+      trace_array Optimizer trace information about range boundaries are
+                  appended to this if tracing is enabled. If NULL, no 
+                  optimizer tracing is done
 
   DESCRIPTION
     This is "get_next" function for Range sequence interface implementation
@@ -8044,12 +8049,23 @@ static void step_down_to(String *s, SEL_
 */
 
 //psergey-merge-todo: support check_quick_keys:max_keypart
-uint sel_arg_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint sel_arg_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range, 
+                            Opt_trace_array *trace_array)
 {
   SEL_ARG *key_tree;
   SEL_ARG_RANGE_SEQ *seq= (SEL_ARG_RANGE_SEQ*)rseq;
   String key_range_trace;
-  key_range_trace.set_charset(system_charset_info);
+
+  bool is_tracing= false;
+#ifdef OPTIMIZER_TRACE
+  if (trace_array && 
+      unlikely(seq->param->thd->opt_trace != NULL) &&
+      seq->param->thd->opt_trace->is_started())
+  {
+    is_tracing= true;
+    key_range_trace.set_charset(system_charset_info);
+  }
+#endif
 
   if (seq->at_start)
   {
@@ -8066,7 +8082,7 @@ uint sel_arg_range_seq_next(range_seq_t 
   {
     //step down; (update the tuple, we'll step right and stay there)
     seq->i--;
-    step_down_to(&key_range_trace, seq, key_tree->next);
+    step_down_to(is_tracing ? &key_range_trace : NULL, seq, key_tree->next);
     key_tree= key_tree->next;
     seq->param->is_ror_scan= FALSE;
     goto walk_right_n_up;
@@ -8087,7 +8103,7 @@ uint sel_arg_range_seq_next(range_seq_t 
     {
       // Step down; update the tuple
       seq->i--;
-      step_down_to(&key_range_trace, seq, key_tree->next);
+      step_down_to(is_tracing ? &key_range_trace : NULL, seq, key_tree->next);
       key_tree= key_tree->next;
       seq->param->is_ror_scan= FALSE;
       break;
@@ -8127,9 +8143,7 @@ walk_right_n_up:
                                           &cur->max_key_flag,
                                           MAX_KEY);
 
-#ifdef OPTIMIZER_TRACE
-        if (unlikely(seq->param->thd->opt_trace != NULL) &&
-            seq->param->thd->opt_trace->is_started())
+        if (is_tracing)
         {
           // Trace the range we just stored
           KEY_PART_INFO *kpi=
@@ -8140,7 +8154,6 @@ walk_right_n_up:
                        store_key_part->min_value, store_key_part->max_value,
                        store_key_part->min_flag | store_key_part->max_flag);
         }
-#endif
         break;
       }
     }
@@ -8157,7 +8170,7 @@ walk_up_n_right:
       /* Step up */
       key_tree= key_tree->prev;
     }
-    step_down_to(&key_range_trace, seq, key_tree);
+    step_down_to(is_tracing ? &key_range_trace : NULL, seq, key_tree);
   }
 
   /* Ok got a tuple */
@@ -8219,22 +8232,12 @@ walk_up_n_right:
   seq->param->range_count++;
   seq->param->max_key_part=max(seq->param->max_key_part,key_tree->part);
 
-#ifdef OPTIMIZER_TRACE
-  if (key_range_trace.length())
+  if (is_tracing && key_range_trace.length())
   {
     DBUG_ASSERT(seq->param->thd->opt_trace);
     DBUG_ASSERT(seq->param->thd->opt_trace->is_started());
-    /* 
-       Should be Opt_trace_array, but don't cast because if it is
-       Opt_trace_object a cast will crash the server while just
-       add()'ing to Opt_trace_struct will cause a JSON syntax error
-       for the optimizer trace (less severe)
-     */
-    Opt_trace_struct *trace_range=  
-      seq->param->thd->opt_trace->get_current_struct();
-    trace_range->add_utf8(key_range_trace.ptr(), key_range_trace.length());
+    trace_array->add_utf8(key_range_trace.ptr(), key_range_trace.length());
   }
-#endif
 
   return 0;
 }
@@ -9258,7 +9261,8 @@ range_seq_t quick_range_seq_init(void *i
     1  No more ranges in the sequence
 */
 
-uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range, 
+                          Opt_trace_array *unused)
 {
   QUICK_RANGE_SEQ_CTX *ctx= (QUICK_RANGE_SEQ_CTX*)rseq;
 

=== modified file 'sql/opt_range.h'
--- a/sql/opt_range.h	2011-02-16 13:52:44 +0000
+++ b/sql/opt_range.h	2011-03-15 11:28:17 +0000
@@ -394,7 +394,8 @@ typedef struct st_quick_range_seq_ctx
 } QUICK_RANGE_SEQ_CTX;
 
 range_seq_t quick_range_seq_init(void *init_param, uint n_ranges, uint flags);
-uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
+uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range, 
+                          Opt_trace_array *unused);
 
 
 /*

=== modified file 'sql/sql_join_cache.cc'
--- a/sql/sql_join_cache.cc	2010-09-02 07:34:10 +0000
+++ b/sql/sql_join_cache.cc	2011-03-15 11:28:17 +0000
@@ -2169,7 +2169,8 @@ range_seq_t bka_range_seq_init(void *ini
 */    
 
 static 
-uint bka_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint bka_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range, 
+                        Opt_trace_array *unused)
 {
   DBUG_ENTER("bka_range_seq_next");
   JOIN_CACHE_BKA *cache= (JOIN_CACHE_BKA *) rseq;
@@ -2993,7 +2994,8 @@ range_seq_t bka_unique_range_seq_init(vo
 */    
 
 static 
-uint bka_unique_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
+uint bka_unique_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range,
+                               Opt_trace_array *unused)
 {
   DBUG_ENTER("bka_unique_range_seq_next");
   JOIN_CACHE_BKA_UNIQUE *cache= (JOIN_CACHE_BKA_UNIQUE *) rseq;


Attachment: [text/bzr-bundle] bzr/jorgen.loland@oracle.com-20110315112817-7xnumkmeza33gy38.bundle
Thread
bzr commit into mysql-trunk branch (jorgen.loland:3279) Jorgen Loland15 Mar
  • Re: bzr commit into mysql-trunk branch (jorgen.loland:3279)Guilhem Bichot15 Mar