[Commits] a85f653: MDEV-8989: ORDER BY optimizer ignores equality propagation

Sergei Petrunia psergey at askmonty.org
Fri May 27 15:16:08 EEST 2016


revision-id: a85f6533f13a02a0b0547656a5ff918a1d91d887
parent(s): 99cd5a962c53e35620cdeeca35dfab4ab4b3bb4c
committer: Sergei Petrunia
branch nick: 10.1-dbg4
timestamp: 2016-05-27 15:16:08 +0300
message:

MDEV-8989: ORDER BY optimizer ignores equality propagation

Post-fix: add comments, remove dead-code.

---
 sql/sql_select.cc |   30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a278183..4b535b1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -12342,30 +12342,26 @@ static void update_depend_map_for_order(JOIN *join, ORDER *order)
 
             Item *item= order->item[0];
 
-            /* 
-              We are using Context_identity below. This means only do
-              substitution when equality means
+            /*
+              TODO: equality substitution in the context of ORDER BY is 
+              sometimes allowed when it is not allowed in the general case.
+              
+              We make the below call for its side effect: it will locate the
+              multiple equality the item belongs to and set item->item_equal
+              accordingly.
             */
             Item *res= item->propagate_equal_fields(join->thd,
                                                     Value_source::
                                                     Context_identity(),
                                                     join->cond_equal);
-            if (res != item)
-            {
-              /* Substituted to a constant */
-              can_subst_to_first_table= true;
-            }
-            else
+            Item_equal *item_eq;
+            if ((item_eq= res->get_item_equal()))
             {
-              Item_equal *item_eq= item->get_item_equal();
-              if (item_eq)
+              Item *first= item_eq->get_first(NO_PARTICULAR_TAB, NULL);
+              if (first->const_item() || first->used_tables() ==
+                                         first_table_bit)
               {
-                Item *first= item_eq->get_first(NO_PARTICULAR_TAB, NULL);
-                if (first->const_item() || first->used_tables() ==
-                                           first_table_bit)
-                {
-                  can_subst_to_first_table= true;
-                }
+                can_subst_to_first_table= true;
               }
             }
           }


More information about the commits mailing list