List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:May 2 2011 11:51am
Subject:bzr commit into mysql-trunk branch (jorgen.loland:3355) Bug#11766327
View as plain text  
#At file:///export/home/jl208045/mysql/mysql-trunk-59415/ based on revid:jorgen.loland@stripped

 3355 Jorgen Loland	2011-05-02
      BUG#11766327: Range analysis should not be done many times
                    for the same index
      (Former bug 59415)
      The optimizer often choses to access a table through an index
      that does not provide the correct ordering for free. To remedy
      this, the function test_if_skip_sort_order() is called to see
      if another index is as good as the chosen index and at the
      same time is able to provide ordering.
      This implies that test_if_skip_sort_ordering() goes through a
      full range analysis (if range access is applicable) to check
      whether or not another range access plan should be used
      instead of the currently chosen ref/range access method.
      The problem is that if range analysis is performed and it is
      decided that it is not better than whatever we had, the range
      analysis will most likely be performed again and again with
      the same outcome because test_if_skip_sort_order() is called
      from multiple locations.
      This patch avoids the unnecessarily repeated range analysis
      described above by introducing key_map
      JOIN_TAB::quick_order_tested which is checked to see
      if range analysis has already been performed for a given key.
     @ sql/sql_select.h
        Introduce JOIN_TAB::quick_order_tested used to avoid repeated range analysis for the same key in test_if_skip_sort_order()

=== modified file 'sql/'
--- a/sql/	2011-05-02 11:16:36 +0000
+++ b/sql/	2011-05-02 11:51:41 +0000
@@ -20318,8 +20318,11 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
     if (best_key >= 0)
-      if (table->quick_keys.is_set(best_key) && best_key != ref_key)
+      if (table->quick_keys.is_set(best_key) &&
+          !tab->quick_order_tested.is_set(best_key) &&
+          best_key != ref_key)
+        tab->quick_order_tested.set_bit(best_key);
         key_map map;           // Force the creation of quick select
         map.set_bit(best_key); // only best_key.
         select->quick= 0;

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2011-05-02 11:16:36 +0000
+++ b/sql/sql_select.h	2011-05-02 11:51:41 +0000
@@ -302,6 +302,15 @@ public:
   key_map	checked_keys;			/**< Keys checked */
   key_map	needed_reg;
   key_map       keys;                           /**< all keys with can be used */
+  /**
+    Used to avoid repeated range analysis for the same key in
+    test_if_skip_sort_order(). This would otherwise happen if the best
+    range access plan found for a key is turned down.
+    quick_order_tested is cleared every time the select condition for
+    this JOIN_TAB changes since a new condition may give another plan
+    and cost from range analysis.
+   */
+  key_map       quick_order_tested;
   /* Either #rows in the table or 1 for const table.  */
   ha_rows	records;
@@ -448,6 +457,7 @@ public:
                ("JOIN_TAB::m_condition changes %p -> %p at line %u tab %p",
                 m_condition, to, line, this));
     m_condition= to;
+    quick_order_tested.clear_all();
   Item *set_jt_and_sel_condition(Item *new_cond, uint line)
@@ -505,6 +515,7 @@ st_join_table::st_join_table()
+    quick_order_tested(),

Attachment: [text/bzr-bundle] bzr/
bzr commit into mysql-trunk branch (jorgen.loland:3355) Bug#11766327Jorgen Loland2 May