List:Commits« Previous MessageNext Message »
From:Roy Lyseng Date:June 9 2010 11:20am
Subject:bzr commit into mysql-next-mr-bugfixing branch (roy.lyseng:3186) WL#5266
View as plain text  
#At file:///home/rl136806/mysql/repo/mysql-work4/ based on revid:roy.lyseng@stripped

 3186 Roy Lyseng	2010-06-09
      WL#5266 - Refactor data used to collect correlated expressions in semijoins
      
      Additional patch that removes sj_inner_tables after it has become obsolete.
      Note: Must be applied after bugfix of bug#43768!
      Will be merged with main patch before pushing.
      
      sql/sql_select.cc
        Replaced sj_inner_tables with nested_join->used_tables.
      
      sql/table.h
        Removed sj_inner_tables.

    modified:
      sql/sql_select.cc
      sql/table.h
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-06-04 15:03:03 +0000
+++ b/sql/sql_select.cc	2010-06-09 11:17:21 +0000
@@ -4044,9 +4044,6 @@ int pull_out_semijoin_tables(JOIN *join)
     sj_nest->nested_join->used_tables&= ~pulled_tables;
     sj_nest->nested_join->not_null_tables&= ~pulled_tables;
 
-    /* sj_inner_tables is a copy of nested_join->used_tables */
-    sj_nest->sj_inner_tables= sj_nest->nested_join->used_tables;
-
     if (pulled_tables)
     {
       List<TABLE_LIST> *upper_join_list= (sj_nest->embedding != NULL) ?
@@ -4822,11 +4819,10 @@ static bool optimize_semijoin_nests(JOIN
     while ((sj_nest= sj_list_it++))
     {
       /* semi-join nests with only constant tables are not valid */
-      DBUG_ASSERT(sj_nest->sj_inner_tables & ~join->const_table_map);
+      DBUG_ASSERT(sj_nest->nested_join->used_tables & ~join->const_table_map);
 
       sj_nest->sj_mat_info= NULL;
-      if (sj_nest->sj_inner_tables && /* not everything was pulled out */
-          !sj_nest->sj_subq_pred->is_correlated && 
+      if (!sj_nest->sj_subq_pred->is_correlated && 
            sj_nest->sj_subq_pred->types_allow_materialization)
       {
         join->emb_sjm_nest= sj_nest;
@@ -4836,7 +4832,7 @@ static bool optimize_semijoin_nests(JOIN
           The best plan to run the subquery is now in join->best_positions,
           save it.
         */
-        uint n_tables= my_count_bits(sj_nest->sj_inner_tables);
+        uint n_tables= my_count_bits(sj_nest->nested_join->used_tables);
         SJ_MATERIALIZATION_INFO* sjm;
         if (!(sjm= new SJ_MATERIALIZATION_INFO) ||
             !(sjm->positions= (POSITION*)join->thd->alloc(sizeof(POSITION)*
@@ -6320,14 +6316,14 @@ public:
            FirstMatch strategy)
     */
     best_loose_scan_cost= DBL_MAX;
-    if (s->emb_sj_nest && !join->emb_sjm_nest &&                        // (1)
+    if (s->emb_sj_nest && !join->emb_sjm_nest &&                         // (1)
         s->emb_sj_nest->sj_in_exprs < 64 && 
-        ((remaining_tables & s->emb_sj_nest->sj_inner_tables) ==        // (2)
-         s->emb_sj_nest->sj_inner_tables) &&                            // (2)
-        join->cur_sj_inner_tables == 0 &&                                  // (3)
+        ((remaining_tables & s->emb_sj_nest->nested_join->used_tables) ==// (2)
+         s->emb_sj_nest->nested_join->used_tables) &&                    // (2)
+        join->cur_sj_inner_tables == 0 &&                                // (3)
         !(remaining_tables & 
-          s->emb_sj_nest->nested_join->sj_corr_tables) &&               // (4)
-        remaining_tables & s->emb_sj_nest->nested_join->sj_depends_on &&// (5)
+          s->emb_sj_nest->nested_join->sj_corr_tables) &&                // (4)
+        remaining_tables & s->emb_sj_nest->nested_join->sj_depends_on && // (5)
         join->thd->optimizer_switch_flag(OPTIMIZER_SWITCH_LOOSE_SCAN))
     {
       /* This table is an LooseScan scan candidate */
@@ -7429,14 +7425,14 @@ semijoin_order_allows_materialization(co
   const TABLE_LIST *emb_sj_nest= tab->emb_sj_nest;
   if (!emb_sj_nest ||
       !emb_sj_nest->sj_mat_info ||
-      (remaining_tables & emb_sj_nest->sj_inner_tables))
+      (remaining_tables & emb_sj_nest->nested_join->used_tables))
     return SJ_OPT_NONE;
 
   /* 
     Walk back and check if all immediately preceding tables are from
     this semi-join.
   */
-  const uint n_tables= my_count_bits(emb_sj_nest->sj_inner_tables);
+  const uint n_tables= my_count_bits(emb_sj_nest->nested_join->used_tables);
   for (uint i= 1; i < n_tables ; i++)
   {
     if (join->positions[idx - i].table->emb_sj_nest != emb_sj_nest)
@@ -7556,10 +7552,11 @@ greedy_search(JOIN      *join,
   DBUG_ENTER("greedy_search");
 
   /* number of tables that remain to be optimized */
-  n_tables= size_remain= my_count_bits(remaining_tables &
-                                       (join->emb_sjm_nest? 
-                                         join->emb_sjm_nest->sj_inner_tables :
-                                         ~(table_map)0));
+  n_tables= size_remain=
+    my_count_bits(remaining_tables &
+                  (join->emb_sjm_nest ? 
+                     join->emb_sjm_nest->nested_join->used_tables :
+                     ~(table_map)0));
 
   do {
     /* Find the extension of the current QEP with the lowest cost */
@@ -7813,7 +7810,7 @@ best_extension_by_limited_search(JOIN   
 
   table_map allowed_tables= ~(table_map)0;
   if (join->emb_sjm_nest)
-    allowed_tables= join->emb_sjm_nest->sj_inner_tables;
+    allowed_tables= join->emb_sjm_nest->nested_join->used_tables;
 
   bool has_sj= !join->select_lex->sj_nests.is_empty();
 
@@ -8373,7 +8370,8 @@ static void fix_semijoin_strategies_for_
         record_count *= join->best_positions[idx].records_read;
       }
       first_pos->sj_strategy= SJ_OPT_LOOSE_SCAN;
-      first_pos->n_sj_tables= my_count_bits(first_pos->table->emb_sj_nest->sj_inner_tables);
+      first_pos->n_sj_tables=
+        my_count_bits(first_pos->table->emb_sj_nest->nested_join->used_tables);
     }
     else if (pos->sj_strategy == SJ_OPT_DUPS_WEEDOUT)
     {
@@ -9241,7 +9239,7 @@ static bool make_join_select(JOIN *join,
       */
       if (tab->emb_sj_nest && tab->emb_sj_nest->sj_mat_info && 
           tab->emb_sj_nest->sj_mat_info->is_used &&
-          !(used_tables & tab->emb_sj_nest->sj_inner_tables))
+          !(used_tables & tab->emb_sj_nest->nested_join->used_tables))
       {
         save_used_tables= used_tables;
         used_tables= join->const_table_map | OUTER_REF_TABLE_BIT | 
@@ -9481,9 +9479,9 @@ static bool make_join_select(JOIN *join,
       if (pushdown_on_conditions(join, tab))
         DBUG_RETURN(1);
 
-      if (save_used_tables && !(used_tables & 
-                                ~(tab->emb_sj_nest->sj_inner_tables |
-                                  join->const_table_map | PSEUDO_TABLE_BITS)))
+      if (save_used_tables &&
+          !(used_tables & ~(tab->emb_sj_nest->nested_join->used_tables |
+                            join->const_table_map | PSEUDO_TABLE_BITS)))
       {
         /*
           We have reached the end of semi join nest. That is, the join order
@@ -10620,7 +10618,7 @@ bool setup_sj_materialization(JOIN_TAB *
         Item_field *item;
         while ((item= it++))
         {
-          if (!(item->used_tables() & ~emb_sj_nest->sj_inner_tables))
+          if (!(item->used_tables() & ~emb_sj_nest->nested_join->used_tables))
           {
             copy_to= item->field;
             break;
@@ -12331,7 +12329,7 @@ Item *eliminate_item_equal(COND *cond, C
         bool found= FALSE;
         while ((head_in_sjm= fit++))
         {
-          if (head_in_sjm->used_tables() & emb_nest->sj_inner_tables)
+          if (head_in_sjm->used_tables() & emb_nest->nested_join->used_tables)
           {
             if (head_in_sjm == item_field)
             {
@@ -13445,7 +13443,7 @@ void advance_sj_state(JOIN *join, table_
       new_join_tab->emb_sj_nest->nested_join->sj_corr_tables |
       new_join_tab->emb_sj_nest->nested_join->sj_depends_on;
     const table_map sj_inner_tables=
-      new_join_tab->emb_sj_nest->sj_inner_tables;
+      new_join_tab->emb_sj_nest->nested_join->used_tables;
 
     /* 
       Enter condition:
@@ -13525,9 +13523,10 @@ void advance_sj_state(JOIN *join, table_
       then 
          stop considering loose scan
     */
-    if ((pos->first_loosescan_table != MAX_TABLES) &&   // (1)
-        (first->table->emb_sj_nest->sj_inner_tables & remaining_tables) && //(2)
-        new_join_tab->emb_sj_nest != first->table->emb_sj_nest) //(2)
+    if ((pos->first_loosescan_table != MAX_TABLES) &&           // (1)
+        (first->table->emb_sj_nest->nested_join->used_tables &
+         remaining_tables) &&                                   // (2)
+        new_join_tab->emb_sj_nest != first->table->emb_sj_nest) // (2)
     {
       pos->first_loosescan_table= MAX_TABLES;
     }
@@ -13540,7 +13539,7 @@ void advance_sj_state(JOIN *join, table_
     {
       pos->first_loosescan_table= idx;
       pos->loosescan_need_tables=
-        new_join_tab->emb_sj_nest->sj_inner_tables | 
+        new_join_tab->emb_sj_nest->nested_join->used_tables | 
         new_join_tab->emb_sj_nest->nested_join->sj_depends_on |
         new_join_tab->emb_sj_nest->nested_join->sj_corr_tables;
     }
@@ -13554,7 +13553,8 @@ void advance_sj_state(JOIN *join, table_
       */
 
       first=join->positions + pos->first_loosescan_table; 
-      uint n_tables= my_count_bits(first->table->emb_sj_nest->sj_inner_tables);
+      uint n_tables=
+        my_count_bits(first->table->emb_sj_nest->nested_join->used_tables);
       /* Got a complete LooseScan range. Calculate its cost */
       double reopt_cost, reopt_rec_count, sj_inner_fanout;
       /*
@@ -13578,7 +13578,7 @@ void advance_sj_state(JOIN *join, table_
       pos->sj_strategy= SJ_OPT_LOOSE_SCAN;
       *current_read_time=    reopt_cost;
       *current_record_count= reopt_rec_count;
-      handled_by_fm_or_ls= first->table->emb_sj_nest->sj_inner_tables;
+      handled_by_fm_or_ls= first->table->emb_sj_nest->nested_join->used_tables;
     }
   }
 
@@ -13588,13 +13588,13 @@ void advance_sj_state(JOIN *join, table_
   */
   if ((emb_sj_nest= new_join_tab->emb_sj_nest))
   {
-    join->cur_sj_inner_tables |= emb_sj_nest->sj_inner_tables;
-    pos->dups_producing_tables |= emb_sj_nest->sj_inner_tables;
+    join->cur_sj_inner_tables |= emb_sj_nest->nested_join->used_tables;
+    pos->dups_producing_tables |= emb_sj_nest->nested_join->used_tables;
 
     /* Remove the sj_nest if all of its SJ-inner tables are in cur_table_map */
     if (!(remaining_tables &
-          emb_sj_nest->sj_inner_tables & ~new_join_tab->table->map))
-      join->cur_sj_inner_tables &= ~emb_sj_nest->sj_inner_tables;
+          emb_sj_nest->nested_join->used_tables & ~new_join_tab->table->map))
+      join->cur_sj_inner_tables &= ~emb_sj_nest->nested_join->used_tables;
   }
   pos->dups_producing_tables &= ~handled_by_fm_or_ls;
 
@@ -13624,7 +13624,7 @@ void advance_sj_state(JOIN *join, table_
       we reach the point #2.
     */
     pos->sjm_scan_need_tables=
-      new_join_tab->emb_sj_nest->sj_inner_tables | 
+      new_join_tab->emb_sj_nest->nested_join->used_tables | 
       new_join_tab->emb_sj_nest->nested_join->sj_depends_on |
       new_join_tab->emb_sj_nest->nested_join->sj_corr_tables;
     pos->sjm_scan_last_inner= idx;
@@ -13662,7 +13662,7 @@ void advance_sj_state(JOIN *join, table_
       *current_read_time=    mat_read_time;
       *current_record_count= prefix_rec_count;
       pos->dups_producing_tables &=
-        ~new_join_tab->emb_sj_nest->sj_inner_tables;
+        ~new_join_tab->emb_sj_nest->nested_join->used_tables;
     }
   }
   
@@ -13722,7 +13722,7 @@ void advance_sj_state(JOIN *join, table_
       pos->sj_strategy= SJ_OPT_MATERIALIZE_SCAN;
       *current_read_time=    prefix_cost;
       *current_record_count= prefix_rec_count;
-      pos->dups_producing_tables &= ~mat_nest->sj_inner_tables;
+      pos->dups_producing_tables &= ~mat_nest->nested_join->used_tables;
 
     }
   }
@@ -13739,7 +13739,7 @@ void advance_sj_state(JOIN *join, table_
       if (!pos->dupsweedout_tables)
         pos->first_dupsweedout_table= idx;
 
-      pos->dupsweedout_tables |= nest->sj_inner_tables |
+      pos->dupsweedout_tables |= nest->nested_join->used_tables |
                                  nest->nested_join->sj_depends_on |
                                  nest->nested_join->sj_corr_tables;
     }
@@ -13883,10 +13883,10 @@ static void backout_nj_sj_state(const ta
   if ((emb_sj_nest= tab->emb_sj_nest))
   {
     /* If we're removing the last SJ-inner table, remove the sj-nest */
-    if ((remaining_tables & emb_sj_nest->sj_inner_tables) ==
-        (emb_sj_nest->sj_inner_tables & ~tab->table->map))
+    if ((remaining_tables & emb_sj_nest->nested_join->used_tables) ==
+        (emb_sj_nest->nested_join->used_tables & ~tab->table->map))
     {
-      tab->join->cur_sj_inner_tables &= ~emb_sj_nest->sj_inner_tables;
+      tab->join->cur_sj_inner_tables &= ~emb_sj_nest->nested_join->used_tables;
     }
   }
 }
@@ -22624,7 +22624,7 @@ static void print_table_array(THD *thd, 
     }
     else if (curr->straight)
       str->append(STRING_WITH_LEN(" straight_join "));
-    else if (curr->sj_inner_tables)
+    else if (curr->sj_on_expr)
       str->append(STRING_WITH_LEN(" semi join "));
     else
       str->append(STRING_WITH_LEN(" join "));
@@ -22684,12 +22684,12 @@ static void print_join(THD *thd,
     If the first table is a semi-join nest, swap it with something that is
     not a semi-join nest.
   */
-  if ((*table)->sj_inner_tables)
+  if ((*table)->sj_on_expr)
   {
     TABLE_LIST **end= table + non_const_tables;
     for (TABLE_LIST **t2= table; t2!=end; t2++)
     {
-      if (!(*t2)->sj_inner_tables)
+      if (!(*t2)->sj_on_expr)
       {
         TABLE_LIST *tmp= *t2;
         *t2= *table;

=== modified file 'sql/table.h'
--- a/sql/table.h	2010-05-25 15:24:05 +0000
+++ b/sql/table.h	2010-06-09 11:17:21 +0000
@@ -1381,13 +1381,6 @@ struct TABLE_LIST
   char          *option;                /* Used by cache index  */
   Item		*on_expr;		/* Used with outer join */
   Item          *sj_on_expr;
-  /*
-    (Valid only for semi-join nests) Bitmap of tables that are within the
-    semi-join (this is different from bitmap of all nest's children because
-    tables that were pulled out of the semi-join nest remain listed as
-    nest's children).
-  */
-  table_map     sj_inner_tables;
   /* Number of IN-compared expressions */
   uint          sj_in_exprs; 
   Item_in_subselect  *sj_subq_pred;


Attachment: [text/bzr-bundle] bzr/roy.lyseng@sun.com-20100609111721-ybn87nvc92317mzg.bundle
Thread
bzr commit into mysql-next-mr-bugfixing branch (roy.lyseng:3186) WL#5266Roy Lyseng9 Jun