List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:December 21 2010 7:35am
Subject:bzr push into mysql-next-mr-bugfixing branch (jorgen.loland:3241 to 3242)
WL#4800
View as plain text  
 3242 Jorgen Loland	2010-12-21
      WL#4800: 
      
      Revert print_quick() and friends to how they are in 
      next-mr-opt-backporting, i.e., remove optimizer tracing from 
      this function since tracing of quick is performed in 
      TABLE_READ_PLAN::trace_basic_info() instead.
     @ WL4800_TODO.txt
        Update todo-list
     @ sql/opt_range.cc
        Revert print_quick() and friends to how they are in next-mr-opt-backporting.

    modified:
      WL4800_TODO.txt
      sql/opt_range.cc
 3241 Guilhem Bichot	2010-12-19 [merge]
      merge Jorgen's changes

    modified:
      WL4800_TODO.txt
=== modified file 'WL4800_TODO.txt'
--- a/WL4800_TODO.txt	2010-12-19 14:28:08 +0000
+++ b/WL4800_TODO.txt	2010-12-21 07:34:33 +0000
@@ -29,8 +29,7 @@ Review comments left:
 - in changelog, mention /*select#*/; in doc, mention use of this (to
 decrypt what "id" is about in EXPLAIN).
 - more checks for non-unique keys?
-- revert print_quick() and dbug_dump() to how they are in
-  opt_backporting. dbug_dump() functions may not be needed anymore.
+
 Try to revert opt_range.cc and sql_test.cc as much as possible. Jorgen
 working on it.
 

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-12-19 14:24:03 +0000
+++ b/sql/opt_range.cc	2010-12-21 07:34:33 +0000
@@ -792,17 +792,13 @@ TABLE_READ_PLAN *get_best_disjunct_quick
 static
 TRP_GROUP_MIN_MAX *get_best_group_min_max(PARAM *param, SEL_TREE *tree,
                                           double read_time);
-#ifndef DBUG_OFF
+#if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
 static void print_sel_tree(PARAM *param, SEL_TREE *tree, key_map *tree_map,
                            const char *msg);
 static void print_ror_scans_arr(TABLE *table, const char *msg,
                                 struct st_ror_scan_info **start,
                                 struct st_ror_scan_info **end);
-#endif
-#if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
-#if 0
 static void print_quick(QUICK_SELECT_I *quick, const key_map *needed_reg);
-#endif
 static void append_range(String *out,
                          const KEY_PART_INFO *key_parts,
                          const uchar *min_key, const uchar *max_key,
@@ -1963,60 +1959,6 @@ public:
                                 Opt_trace_object *trace_object) const = 0;
 };
 
-
-#if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
-/**
-  Print a key into a stream
-
-  @param[out] out          String the key is appended to
-  @param[in]  key_part     Index components description
-  @param[in]  key          Key tuple
-  @param[in]  used_length  Key tuple length
-*/
-static void
-print_key_value(String *out, const KEY_PART_INFO *key_part, const uchar *key)
-{
-  String tmp;
-  uint store_length;
-  TABLE *table= key_part->field->table;
-  my_bitmap_map *old_sets[2];
-
-  dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
-
-  Field *field= key_part->field;
-  store_length= key_part->store_length;
-
-  if (field->real_maybe_null())
-  {
-    /*
-      Byte 0 of key is the null-byte. If set, key is NULL.
-      Otherwise, print the key value starting immediately after the
-      null-byte
-    */
-    if (*key)
-    {
-      out->append(STRING_WITH_LEN("NULL"));
-      goto restore_col_map;
-    }
-    key++;                                    // Skip null byte
-    store_length--;
-  }
-  field->set_key_image(key, key_part->length);
-  if (field->type() == MYSQL_TYPE_BIT)
-  {
-    // Prints bitfield as integer; val_str() prints as char: harder to read
-    (void) field->val_int_as_str(&tmp, 1); // may change tmp's charset
-  }
-  else
-    field->val_str(&tmp); // may change tmp's charset
-  out->append(tmp.ptr(), tmp.length(), tmp.charset());
-
-restore_col_map:
-  dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
-}
-#endif
-
-
 /*
   Plan for a QUICK_RANGE_SELECT scan.
   TRP_RANGE::make_quick ignores retrieve_full_rows parameter because
@@ -2800,6 +2742,8 @@ free_mem:
     thd->no_errors=0;
   }
 
+  DBUG_EXECUTE("info", print_quick(quick, &needed_reg););
+
   /*
     Assume that if the user is using 'limit' we will only need to scan
     limit rows if we are using a key
@@ -3160,7 +3104,7 @@ end:
 
 void store_key_image_to_rec(Field *field, uchar *ptr, uint len)
 {
-  /* Do the same as print_key() does */ 
+  /* Do the same as print_key_value() does */ 
   my_bitmap_map *old_map;
 
   if (field->real_maybe_null())
@@ -12310,14 +12254,58 @@ static void print_ror_scans_arr(TABLE *t
 
 #endif /* !DBUG_OFF */
 
+#if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
+
 /*****************************************************************************
-** Print a quick range for debugging
-** TODO:
-** This should be changed to use a String to store each row instead
-** of locking the DEBUG stream !
+** Append a range for a single keypart into a stream.
 *****************************************************************************/
 
-#if !defined(DBUG_OFF) || defined(OPTIMIZER_TRACE)
+/**
+  Print a key into a stream
+
+  @param[out] out          String the key is appended to
+  @param[in]  key_part     Index components description
+  @param[in]  key          Key tuple
+  @param[in]  used_length  Key tuple length
+*/
+static void
+print_key_value(String *out, const KEY_PART_INFO *key_part, const uchar *key)
+{
+  String tmp;
+  uint store_length;
+  TABLE *table= key_part->field->table;
+  my_bitmap_map *old_sets[2];
+
+  dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
+
+  Field *field= key_part->field;
+  store_length= key_part->store_length;
+
+  if (field->real_maybe_null())
+  {
+    /*
+      Byte 0 of key is the null-byte. If set, key is NULL.
+      Otherwise, print the key value starting immediately after the
+      null-byte
+    */
+    if (*key)
+    {
+      out->append(STRING_WITH_LEN("NULL"));
+      goto restore_col_map;
+    }
+    key++;                                    // Skip null byte
+    store_length--;
+  }
+  field->set_key_image(key, key_part->length);
+  if (field->type() == MYSQL_TYPE_BIT)
+    (void) field->val_int_as_str(&tmp, 1); // may change tmp's charset
+  else
+    field->val_str(&tmp); // may change tmp's charset
+  out->append(tmp.ptr(), tmp.length(), tmp.charset());
+
+restore_col_map:
+  dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
+}
 
 /**
   Append range info for a key part to a string
@@ -12358,7 +12346,53 @@ static void append_range(String *out,
   }
 }
 
-#if 0
+/*****************************************************************************
+** Print a quick range for debugging
+** TODO:
+** This should be changed to use a String to store each row instead
+** of locking the DEBUG stream !
+*****************************************************************************/
+
+static void
+print_multiple_key_values(KEY_PART *key_part, const uchar *key, 
+                          uint used_length)
+{
+  char buff[1024];
+  const uchar *key_end= key+used_length;
+  String tmp(buff,sizeof(buff),&my_charset_bin);
+  uint store_length;
+  TABLE *table= key_part->field->table;
+  my_bitmap_map *old_sets[2];
+
+  dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
+
+  for (; key < key_end; key+=store_length, key_part++)
+  {
+    Field *field=      key_part->field;
+    store_length= key_part->store_length;
+
+    if (field->real_maybe_null())
+    {
+      if (*key)
+      {
+        fwrite("NULL",sizeof(char),4,DBUG_FILE);
+        continue;
+      }
+      key++;                                    // Skip null byte
+      store_length--;
+    }
+    field->set_key_image(key, key_part->length);
+    if (field->type() == MYSQL_TYPE_BIT)
+      (void) field->val_int_as_str(&tmp, 1);
+    else
+      field->val_str(&tmp);
+    fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE);
+    if (key+store_length < key_end)
+      fputc('/',DBUG_FILE);
+  }
+  dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
+}
+
 static void print_quick(QUICK_SELECT_I *quick, const key_map *needed_reg)
 {
   char buf[MAX_KEY/8+1];
@@ -12383,87 +12417,92 @@ static void print_quick(QUICK_SELECT_I *
   DBUG_UNLOCK_FILE;
   DBUG_VOID_RETURN;
 }
-#endif /* if 0*/
+
 void QUICK_RANGE_SELECT::dbug_dump(int indent, bool verbose)
 {
-  Opt_trace_context *out= current_thd->opt_trace;
-  Opt_trace_object oto(out, "range_scan");
-  oto.add_utf8("index", head->key_info[index].name).
-    add("key_length", max_used_key_length).
-    add("used_keyparts", used_key_parts);
- 
-  Opt_trace_array trace_range(out, "ranges");
   /* purecov: begin inspected */
-  if (TRUE)
+  fprintf(DBUG_FILE, "%*squick range select, key %s, length: %d\n",
+          indent, "", head->key_info[index].name, max_used_key_length);
+
+  if (verbose)
   {
     QUICK_RANGE *range;
     QUICK_RANGE **pr= (QUICK_RANGE**)ranges.buffer;
     QUICK_RANGE **end_range= pr + ranges.elements;
     for (; pr != end_range; ++pr)
     {
-      String range_info;
-      range_info.set_charset(system_charset_info);
+      fprintf(DBUG_FILE, "%*s", indent + 2, "");
       range= *pr;
-      append_range(&range_info, head->key_info[index].key_part,
-                   range->min_key, range->max_key,
-                   range->flag);
-      trace_range.add_utf8(range_info.ptr(), range_info.length());
+      if (!(range->flag & NO_MIN_RANGE))
+      {
+        print_multiple_key_values(key_parts, range->min_key,
+                                  range->min_length);
+        if (range->flag & NEAR_MIN)
+          fputs(" < ",DBUG_FILE);
+        else
+          fputs(" <= ",DBUG_FILE);
+      }
+      fputs("X",DBUG_FILE);
+
+      if (!(range->flag & NO_MAX_RANGE))
+      {
+        if (range->flag & NEAR_MAX)
+          fputs(" < ",DBUG_FILE);
+        else
+          fputs(" <= ",DBUG_FILE);
+        print_multiple_key_values(key_parts, range->max_key,
+                                  range->max_length);
+      }
+      fputs("\n",DBUG_FILE);
     }
   }
-  /* purecov: end */    
+  /* purecov: end */
 }
 
 void QUICK_INDEX_MERGE_SELECT::dbug_dump(int indent, bool verbose)
 {
-  Opt_trace_context *out= current_thd->opt_trace;
   List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
   QUICK_RANGE_SELECT *quick;
-  /* purecov: begin inspected */
-  Opt_trace_array ota(out, "index_merge");
+  fprintf(DBUG_FILE, "%*squick index_merge select\n", indent, "");
+  fprintf(DBUG_FILE, "%*smerged scans {\n", indent, "");
   while ((quick= it++))
-  {
-    Opt_trace_object wrapper(out);
     quick->dbug_dump(indent+2, verbose);
-  }
   if (pk_quick_select)
   {
-    Opt_trace_object oto2(out, "clustered_pk_scan");
+    fprintf(DBUG_FILE, "%*sclustered PK quick:\n", indent, "");
     pk_quick_select->dbug_dump(indent+2, verbose);
   }
+  fprintf(DBUG_FILE, "%*s}\n", indent, "");
 }
 
 void QUICK_ROR_INTERSECT_SELECT::dbug_dump(int indent, bool verbose)
 {
-  Opt_trace_context *out= current_thd->opt_trace;
   List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
   QUICK_RANGE_SELECT *quick;
-  Opt_trace_array ota(out, "index_roworder_intersect");
+  fprintf(DBUG_FILE, "%*squick ROR-intersect select, %scovering\n",
+          indent, "", need_to_fetch_row? "":"non-");
+  fprintf(DBUG_FILE, "%*smerged scans {\n", indent, "");
   while ((quick= it++))
-  {
-    Opt_trace_object wrapper(out);
     quick->dbug_dump(indent+2, verbose);
-  }
   if (cpk_quick)
   {
-    Opt_trace_object oto2(out, "clustered_pk_scan");
+    fprintf(DBUG_FILE, "%*sclustered PK quick:\n", indent, "");
     cpk_quick->dbug_dump(indent+2, verbose);
   }
+  fprintf(DBUG_FILE, "%*s}\n", indent, "");
 }
 
 void QUICK_ROR_UNION_SELECT::dbug_dump(int indent, bool verbose)
 {
-  Opt_trace_context *out= current_thd->opt_trace;
   List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
   QUICK_SELECT_I *quick;
-  Opt_trace_array ota(out, "index_roworder_union");
+  fprintf(DBUG_FILE, "%*squick ROR-union select\n", indent, "");
+  fprintf(DBUG_FILE, "%*smerged scans {\n", indent, "");
   while ((quick= it++))
-  {
-    Opt_trace_object wrapper(out);
     quick->dbug_dump(indent+2, verbose);
-  }
+  fprintf(DBUG_FILE, "%*s}\n", indent, "");
 }
 
-
 /*
   Print quick select information to DBUG_FILE.
 
@@ -12486,14 +12525,9 @@ void QUICK_ROR_UNION_SELECT::dbug_dump(i
 
 void QUICK_GROUP_MIN_MAX_SELECT::dbug_dump(int indent, bool verbose)
 {
-  Opt_trace_context *out= current_thd->opt_trace;
-  Opt_trace_object oto(out, "index_group");
-  oto.add_utf8("index", index_info->name).
-    add("key_length", max_used_key_length);
-
   fprintf(DBUG_FILE,
           "%*squick_group_min_max_select: index %s (%d), length: %d\n",
-	  indent, "", index_info->name, index, max_used_key_length);
+          indent, "", index_info->name, index, max_used_key_length);
   if (key_infix_len > 0)
   {
     fprintf(DBUG_FILE, "%*susing key_infix with length %d:\n",
@@ -12511,6 +12545,7 @@ void QUICK_GROUP_MIN_MAX_SELECT::dbug_du
   }
 }
 
+
 #endif /* !DBUG_OFF || OPTIMIZER_TRACE */
 
 /*****************************************************************************

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-next-mr-bugfixing branch (jorgen.loland:3241 to 3242)WL#4800Jorgen Loland21 Dec