[Commits] Rev 3403: Merge. in file:///home/igor/maria/maria-5.3-trunk-merge/

igor at askmonty.org igor at askmonty.org
Tue Jan 31 04:48:08 EET 2012


At file:///home/igor/maria/maria-5.3-trunk-merge/

------------------------------------------------------------
revno: 3403 [merge]
revision-id: igor at askmonty.org-20120131024742-zeqxvc3wxwyx5cqp
parent: psergey at askmonty.org-20120130163447-45fbi6mk1q6vz3w7
parent: igor at askmonty.org-20120131023545-i7q8bnoalyylu04j
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.3-trunk-merge
timestamp: Mon 2012-01-30 18:47:42 -0800
message:
  Merge.
modified:
  sql/sql_select.cc              sp1f-sql_select.cc-19700101030959-egb7whpkh76zzvikycs5nsnuviu4fdlb
-------------- next part --------------
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2012-01-25 18:05:20 +0000
+++ b/sql/sql_select.cc	2012-01-31 02:47:42 +0000
@@ -6067,8 +6067,14 @@
     while (pos && best_table != pos)
       pos= join->best_ref[++best_idx];
     DBUG_ASSERT((pos != NULL)); // should always find 'best_table'
-    /* move 'best_table' at the first free position in the array of joins */
-    swap_variables(JOIN_TAB*, join->best_ref[idx], join->best_ref[best_idx]);
+    /*
+      Maintain '#rows-sorted' order of 'best_ref[]':
+       - Shift 'best_ref[]' to make first position free. 
+       - Insert 'best_table' at the first free position in the array of joins.
+    */
+    memmove(join->best_ref + idx + 1, join->best_ref + idx,
+            sizeof(JOIN_TAB*) * (best_idx - idx));
+    join->best_ref[idx]= best_table;
 
     /* compute the cost of the new plan extended with 'best_table' */
     record_count*= join->positions[idx].records_read;
@@ -6386,8 +6392,20 @@
   if (join->emb_sjm_nest)
     allowed_tables= join->emb_sjm_nest->sj_inner_tables & ~join->const_table_map;
 
+  JOIN_TAB *saved_refs[MAX_TABLES];
+  /* Save 'best_ref[]' as we has to restore before return. */
+  memcpy(saved_refs, join->best_ref + idx, 
+         sizeof(JOIN_TAB*) * (join->table_count - idx));
+
   for (JOIN_TAB **pos= join->best_ref + idx ; (s= *pos) ; pos++)
   {
+    /*
+      Don't move swap inside conditional code: All items should
+      be uncond. swapped to maintain '#rows-ordered' best_ref[].
+      This is critical for early pruning of bad plans.
+    */
+    swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
+
     table_map real_table_bit= s->table->map;
     if ((remaining_tables & real_table_bit) && 
         (allowed_tables & real_table_bit) &&
@@ -6459,8 +6477,8 @@
       }
 
       if ( (search_depth > 1) && (remaining_tables & ~real_table_bit) & allowed_tables )
-      { /* Recursively expand the current partial plan */
-        swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
+      {
+        /* Explore more best extensions of plan */
         if (best_extension_by_limited_search(join,
                                              remaining_tables & ~real_table_bit,
                                              idx + 1,
@@ -6469,7 +6487,6 @@
                                              search_depth - 1,
                                              prune_level))
           DBUG_RETURN(TRUE);
-        swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
       }
       else
       { /*
@@ -6498,6 +6515,10 @@
       restore_prev_sj_state(remaining_tables, s, idx);
     }
   }
+
+  /* Restore previous #rows sorted best_ref[] */
+  memcpy(join->best_ref + idx, saved_refs,
+         sizeof(JOIN_TAB*) * (join->table_count-idx));
   DBUG_RETURN(FALSE);
 }
 



More information about the commits mailing list