[Commits] Rev 2809: MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation in file:///home/tsk/mprog/src/5.3-mwl89-lp/

timour at askmonty.org timour at askmonty.org
Thu Sep 16 17:07:07 EEST 2010


At file:///home/tsk/mprog/src/5.3-mwl89-lp/

------------------------------------------------------------
revno: 2809
revision-id: timour at askmonty.org-20100916140658-2hu9mhv2yqfzax2p
parent: timour at askmonty.org-20100916134920-rgifso5qmg3qi6k3
committer: timour at askmonty.org
branch nick: 5.3-mwl89-lp
timestamp: Thu 2010-09-16 17:06:58 +0300
message:
  MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation
    
  Reset correctly the LIMIT and the uncacheable flag of a subquery when executing
  it via materialization.
-------------- next part --------------
=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2010-09-06 11:26:30 +0000
+++ b/sql/item_subselect.cc	2010-09-16 14:06:58 +0000
@@ -2436,16 +2436,6 @@ bool Item_in_subselect::setup_mat_engine
   if (mat_engine->init(&select_engine->join->fields_list))
     DBUG_RETURN(TRUE);
 
-  /*
-    Reset the "LIMIT 1" set in Item_exists_subselect::fix_length_and_dec.
-    TODO:
-    Currently we set the subquery LIMIT to infinity, and this is correct
-    because we forbid at parse time LIMIT inside IN subqueries (see
-    Item_in_subselect::test_limit). However, once we allow this, here
-    we should set the correct limit if given in the query.
-  */
-  unit->global_parameters->select_limit= NULL;
-
   engine= mat_engine;
   DBUG_RETURN(FALSE);
 }

=== modified file 'sql/opt_subselect.cc'
--- a/sql/opt_subselect.cc	2010-09-16 13:49:20 +0000
+++ b/sql/opt_subselect.cc	2010-09-16 14:06:58 +0000
@@ -3566,14 +3566,29 @@ bool JOIN::choose_subquery_plan()
   else
     in_subs->exec_method= Item_in_subselect::IN_TO_EXISTS;
 
-  if (in_subs->exec_method ==  Item_in_subselect::MATERIALIZATION)
+  if (in_subs->exec_method == Item_in_subselect::MATERIALIZATION)
   {
+    /* TODO: should we set/unset this flag for both select_lex and its unit? */
+    in_subs->unit->uncacheable&= ~UNCACHEABLE_DEPENDENT;
+    select_lex->uncacheable&= ~UNCACHEABLE_DEPENDENT;
 
-    // TODO: should we unset the UNCACHEABLE_DEPENDENT flag fro
-    // select_lex->uncacheable; ?
-    // This affects how we execute JOIN::join_free - full or not.
-    // inner_join->restore_plan (keyuse, best_positions, best_read)
-    ;
+    /*
+      Reset the "LIMIT 1" set in Item_exists_subselect::fix_length_and_dec.
+      TODO:
+      Currently we set the subquery LIMIT to infinity, and this is correct
+      because we forbid at parse time LIMIT inside IN subqueries (see
+      Item_in_subselect::test_limit). However, once we allow this, here
+      we should set the correct limit if given in the query.
+    */
+    in_subs->unit->global_parameters->select_limit= NULL;
+    in_subs->unit->set_limit(unit->global_parameters);
+    /*
+      Set the limit of this JOIN object as well, because normally its being
+      set in the beginning of JOIN::optimize, which was already done.
+    */
+    select_limit= in_subs->unit->select_limit_cnt;
+
+    // TODO: inner_join->restore_plan (keyuse, best_positions, best_read)
   }
   else if (in_subs->exec_method == Item_in_subselect::IN_TO_EXISTS)
     res= in_subs->inject_in_to_exists_cond(this);

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2010-09-05 15:43:47 +0000
+++ b/sql/sql_lex.cc	2010-09-16 14:06:58 +0000
@@ -3115,6 +3115,7 @@ bool st_select_lex::optimize_unflattened
         DBUG_ASSERT(!item_in || (item_in && !item_in->is_min_max_optimized));
         if (item_in && item_in->create_in_to_exists_cond(inner_join))
             return TRUE;
+        /* We need only 1 row to determine existence */
         un->set_limit(un->global_parameters);
         un->thd->lex->current_select= sl;
         res= inner_join->optimize();



More information about the commits mailing list