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

timour at askmonty.org timour at askmonty.org
Tue Sep 14 13:11:44 EEST 2010


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

------------------------------------------------------------
revno: 2809
revision-id: timour at askmonty.org-20100914101129-tss1q5q6lheobtsq
parent: timour at askmonty.org-20100910153836-1ducaxeq2n2hzknd
committer: timour at askmonty.org
branch nick: 5.3-mwl89
timestamp: Tue 2010-09-14 13:11:29 +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-14 10:11:29 +0000
@@ -1113,9 +1113,9 @@ Item_allany_subselect::Item_allany_subse
 
 void Item_exists_subselect::fix_length_and_dec()
 {
-   decimals= 0;
-   max_length= 1;
-   max_columns= engine->cols();
+  decimals= 0;
+  max_length= 1;
+  max_columns= engine->cols();
   /* We need only 1 row to determine existence */
   unit->global_parameters->select_limit= new Item_int((int32) 1);
 }
@@ -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-10 15:38:36 +0000
+++ b/sql/opt_subselect.cc	2010-09-14 10:11:29 +0000
@@ -3566,13 +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)

=== 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-14 10:11:29 +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