List:Commits« Previous MessageNext Message »
From:Guilhem Bichot Date:June 9 2011 1:45pm
Subject:bzr commit into mysql-trunk branch (guilhem.bichot:3323)
View as plain text  
#At file:///home/mysql_src/bzrrepos_new/mysql-next-mr-opt-backporting-wl4800/ based on revid:guilhem.bichot@stripped

 3323 Guilhem Bichot	2011-06-09
      Trying to improve performance when opt trace is compiled in but disabled at runtime.
      There are a few places which look like
      if (opt trace is enabled)
       ...
      if (opt trace is enabled)
       ...
      if (opt trace is enabled)
       ...
      if (opt trace is enabled)
       ...
      And also some code like:
      for(some iterations)
      {
        set some local helper variables;
        if (opt trace is enabled)
           ...
      }
      So I put all that under one enclosing "if (opt trace is enabled)". Let's see if it helps.
      Also trying some micro optimizations (like don't compute sweep_cost.total_cost() twice).
     @ sql/opt_trace_context.h
        so that we can use is_started() even if OPTIMIZER_TRACE is not defined.

    modified:
      sql/opt_range.cc
      sql/opt_trace_context.h
      sql/sql_select.cc
      sql/sql_test.cc
=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2011-05-24 12:46:22 +0000
+++ b/sql/opt_range.cc	2011-06-09 13:45:13 +0000
@@ -2692,7 +2692,8 @@ int SQL_SELECT::test_quick_select(THD *t
       Opt_trace_object grp_summary(trace,
                                    "best_group_range_summary",
                                    Opt_trace_context::RANGE_OPTIMIZER);
-      group_trp->trace_basic_info(&param, &grp_summary);
+      if (unlikely(trace->is_started()))
+        group_trp->trace_basic_info(&param, &grp_summary);
       if (group_trp->read_cost < best_read_time)
       {
         grp_summary.add("chosen", true);
@@ -2806,15 +2807,14 @@ int SQL_SELECT::test_quick_select(THD *t
     }
 
 free_mem:
-    if (quick)
+    if (unlikely(quick && trace->is_started()))
     {
       Opt_trace_object trace_range_summary(trace,
                                            "chosen_range_access_summary");
       {
         Opt_trace_object trace_range_plan(trace,
-                                           "range_access_plan");
+                                          "range_access_plan");
         best_trp->trace_basic_info(&param, &trace_range_plan);
-
       }
       trace_range_summary.add("records_for_plan", quick->records).
         add("cost_for_plan", quick->read_time).
@@ -4271,9 +4271,10 @@ TABLE_READ_PLAN *get_best_disjunct_quick
     bool is_interrupted= test(join && join->tables != 1);
     get_sweep_read_cost(param->table, non_cpk_scan_records, is_interrupted,
                         &sweep_cost);
-    imerge_cost += sweep_cost.total_cost();
+    const double sweep_total_cost= sweep_cost.total_cost();
+    imerge_cost+= sweep_total_cost;
     trace_best_disjunct.add("cost_sort_rowid_and_read_disk",
-                            sweep_cost.total_cost());
+                            sweep_total_cost);
   }
   DBUG_PRINT("info",("index_merge cost with rowid-to-row scan: %g",
                      imerge_cost));
@@ -4299,8 +4300,8 @@ TABLE_READ_PLAN *get_best_disjunct_quick
   }
 
   {
-    double dup_removal_cost= 
-      Unique::get_use_cost(param->imerge_cost_buff, 
+    const double dup_removal_cost=
+      Unique::get_use_cost(param->imerge_cost_buff,
                            (uint)non_cpk_scan_records,
                            param->table->file->ref_length,
                            param->thd->variables.sortbuff_size);
@@ -4354,7 +4355,8 @@ skip_to_ror_scan:
        ptree++, cur_child++, cur_roru_plan++)
   {
     Opt_trace_object trp_info(trace);
-    (*cur_child)->trace_basic_info(param, &trp_info);
+    if (unlikely(trace->is_started()))
+      (*cur_child)->trace_basic_info(param, &trp_info);
 
     /*
       Assume the best ROR scan is the one that has cheapest
@@ -4970,11 +4972,11 @@ TRP_ROR_INTERSECT *get_best_ror_intersec
   if ((tree->n_ror_scans < 2) || !param->table->file->stats.records ||
       !param->thd->optimizer_switch_flag(OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT))
   {
+    trace_ror.add("usable", false);
     if (tree->n_ror_scans < 2)
-      trace_ror.add("usable", false).
-        add_alnum("cause", "too_few_roworder_scans");
+      trace_ror.add_alnum("cause", "too_few_roworder_scans");
     else
-      trace_ror.add("usable", false).add("need_tracing", true);
+      trace_ror.add("need_tracing", true);
     DBUG_RETURN(NULL);
   }
 
@@ -5054,8 +5056,8 @@ TRP_ROR_INTERSECT *get_best_ror_intersec
   while (cur_ror_scan != tree->ror_scans_end && !intersect->is_covering)
   {
     Opt_trace_object trace_idx(trace);
-    char *idx_name= param->table->key_info[(*cur_ror_scan)->keynr].name;
-    trace_idx.add_utf8("index", idx_name);
+    trace_idx.add_utf8("index",
+                       param->table->key_info[(*cur_ror_scan)->keynr].name);
     /* S= S + first(R);  R= R - first(R); */
     if (!ror_intersect_add(intersect, *cur_ror_scan, FALSE))
     {
@@ -5211,8 +5213,8 @@ TRP_ROR_INTERSECT *get_best_covering_ror
   if (!param->thd->optimizer_switch_flag(OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT))
     DBUG_RETURN(NULL);
 
-  Opt_trace_object trace_covering (&param->thd->opt_trace,
-                                   "make_covering_roworder_intersect");
+  Opt_trace_context * const trace= &param->thd->opt_trace;
+  Opt_trace_object trace_covering(trace, "make_covering_roworder_intersect");
 
   for (ROR_SCAN_INFO **scan= tree->ror_scans; scan != ror_scans_end; ++scan)
     (*scan)->key_components=
@@ -5243,7 +5245,7 @@ TRP_ROR_INTERSECT *get_best_covering_ror
   DBUG_PRINT("info", ("Building covering ROR-intersection"));
 
   // Note: trace_idx.end() is called to close this object after this loop.
-  Opt_trace_array trace_idx(&param->thd->opt_trace, "included_indices");
+  Opt_trace_array trace_idx(trace, "included_indices");
 
   do
   {
@@ -5288,18 +5290,14 @@ TRP_ROR_INTERSECT *get_best_covering_ror
   {
     trace_covering.add("covering", false).add("chosen", false);
     DBUG_RETURN(NULL);
-  } 
-  else 
+  }
+  trace_covering.add("covering", true);
+  if (unlikely((ror_scan_mark < ror_scans_end) && trace->is_started()))
   {
-    trace_covering.add("covering", true);
-    if (ror_scan_mark < ror_scans_end)
-    {
-      Opt_trace_array ota(&param->thd->opt_trace, "not_included_indices");
-
-      ROR_SCAN_INFO **remaining_idx= ror_scan_mark;      
-      for (;remaining_idx < ror_scans_end; remaining_idx++)
-        ota.add_utf8(param->table->key_info[(*remaining_idx)->keynr].name);
-    }
+    Opt_trace_array ota(trace, "not_included_indices");
+    for (ROR_SCAN_INFO **remaining_idx= ror_scan_mark;
+         remaining_idx < ror_scans_end; remaining_idx++)
+      ota.add_utf8(param->table->key_info[(*remaining_idx)->keynr].name);
   }
 
   if ((ror_scan_mark - tree->ror_scans) == 1)
@@ -8332,11 +8330,7 @@ range_seq_t sel_arg_range_seq_init(void 
   return init_param;
 }
 
-/**
- @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(SEL_ARG_RANGE_SEQ *arg, SEL_ARG *key_tree)
 {
 
@@ -8376,9 +8370,6 @@ static void step_down_to(SEL_ARG_RANGE_S
     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
@@ -10842,10 +10833,9 @@ get_best_group_min_max(PARAM *param, SEL
                                                    &dummy_cost);
 
 #ifdef OPTIMIZER_TRACE
-      if (cur_index_tree &&
-          param->thd->opt_trace.is_started())
+      if (unlikely(cur_index_tree && trace->is_started()))
       {
-        Opt_trace_array trace_range(&param->thd->opt_trace, "ranges");
+        Opt_trace_array trace_range(trace, "ranges");
 
         const KEY_PART_INFO *key_part= cur_index_info->key_part;
 

=== modified file 'sql/opt_trace_context.h'
--- a/sql/opt_trace_context.h	2011-05-23 09:51:41 +0000
+++ b/sql/opt_trace_context.h	2011-06-09 13:45:13 +0000
@@ -427,6 +427,7 @@ public:
     FLAG_END_MARKER= 1 << 1,
     FLAG_ONE_LINE=   1 << 2
   };
+  static bool is_started() { return false; }
 };
 
 #endif /* OPTIMIZER_TRACE */

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-05-31 13:00:14 +0000
+++ b/sql/sql_select.cc	2011-06-09 13:45:13 +0000
@@ -10379,13 +10379,17 @@ static bool make_join_select(JOIN *join,
       }
     }
     trace_attached_comp.end();
-    Opt_trace_array trace_attached_summary(trace, "attached_conditions_summary");
-    for (uint i= join->const_tables ; i < join->tables ; i++)
+    if (unlikely(trace->is_started()))
     {
-      const JOIN_TAB *tab= join->join_tab+i;
-      Opt_trace_object trace_one_table(trace);
-      trace_one_table.add_utf8_table(tab->table);
-      trace_one_table.add("attached", tab->condition());
+      Opt_trace_array trace_attached_summary(trace,
+                                             "attached_conditions_summary");
+      for (uint i= join->const_tables ; i < join->tables ; i++)
+      {
+        const JOIN_TAB * const tab= &join->join_tab[i];
+        Opt_trace_object trace_one_table(trace);
+        trace_one_table.add_utf8_table(tab->table).
+          add("attached", tab->condition());
+      }
     }
   }
   DBUG_RETURN(0);

=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc	2011-05-24 12:46:22 +0000
+++ b/sql/sql_test.cc	2011-06-09 13:45:13 +0000
@@ -244,9 +244,7 @@ void print_keyuse_array(Opt_trace_contex
                         const Key_use_array *keyuse_array)
 {
 #if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
-  bool add_more_debug_info= false;
-  DBUG_EXECUTE("opt", add_more_debug_info= true;);
-  if (likely((trace == NULL || !trace->is_started()) && !add_more_debug_info))
+  if (unlikely(!trace->is_started()))
     return;
   Opt_trace_object wrapper(trace);
   Opt_trace_array  trace_key_uses(trace, "ref_optimizer_key_uses");


Attachment: [text/bzr-bundle] bzr/guilhem.bichot@oracle.com-20110609134513-kpupd3l9wglgqwov.bundle
Thread
bzr commit into mysql-trunk branch (guilhem.bichot:3323) Guilhem Bichot9 Jun