~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Jay Pipes
  • Date: 2009-01-30 06:16:29 UTC
  • mto: (779.3.22 devel)
  • mto: This revision was merged to the branch mainline in revision 823.
  • Revision ID: jpipes@serialcoder-20090130061629-wwb26gezc5x2nu8v
Modified JOIN::flatten_subqueries() to ensure that when a LEFT JOIN
is found with semi-joins, we still must finalize the subqueries that
were not converted.  Previously, after finding a semi-join and LEFT JOIN, 
the code returned from the function without cleaning up other joins.

Included is a change to the subselect2.test case which now shows a
different EXPLAIN plan for a LEFT OUTER JOIN with multiple dependent
subqueries.  We should monitor the optimizer team's input on this 
function to see if they come up with an appropriate solution.

But for now, this fixes bug #314911 and all tests pass cleanly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3096
3096
      (*in_subq)->is_correlated * MAX_TABLES + child_join->outer_tables;
3097
3097
  }
3098
3098
  
 
3099
  bool outer_join_disable_semi_join= false;
3099
3100
  /*
3100
3101
   * Temporary measure: disable semi-joins when they are together with outer
3101
3102
   * joins.
3109
3110
                                            !embedding->embedding)))
3110
3111
    {
3111
3112
      in_subq= sj_subselects.front();
3112
 
      return false;
3113
 
    }
3114
 
  }
3115
 
 
3116
 
  /*
3117
 
    2. Pick which subqueries to convert:
3118
 
      sort the subquery array
3119
 
      - prefer correlated subqueries over uncorrelated;
3120
 
      - prefer subqueries that have greater number of outer tables;
3121
 
  */
3122
 
  sj_subselects.sort(subq_sj_candidate_cmp);
3123
 
  // #tables-in-parent-query + #tables-in-subquery < MAX_TABLES
3124
 
  /* Replace all subqueries to be flattened with Item_int(1) */
3125
 
  for (in_subq= sj_subselects.front();
3126
 
       in_subq != in_subq_end &&
3127
 
       tables + ((*in_subq)->sj_convert_priority % MAX_TABLES) < MAX_TABLES;
3128
 
       in_subq++)
3129
 
  {
3130
 
    if (replace_where_subcondition(this, *in_subq, new Item_int(1), false))
3131
 
      return(true);
3132
 
  }
3133
 
 
3134
 
  for (in_subq= sj_subselects.front();
3135
 
       in_subq != in_subq_end &&
3136
 
       tables + ((*in_subq)->sj_convert_priority % MAX_TABLES) < MAX_TABLES;
3137
 
       in_subq++)
3138
 
  {
3139
 
    if (convert_subq_to_sj(this, *in_subq))
3140
 
      return(true);
 
3113
      outer_join_disable_semi_join= true;
 
3114
    }
 
3115
  }
 
3116
 
 
3117
  if (! outer_join_disable_semi_join)
 
3118
  {
 
3119
    /*
 
3120
      2. Pick which subqueries to convert:
 
3121
        sort the subquery array
 
3122
        - prefer correlated subqueries over uncorrelated;
 
3123
        - prefer subqueries that have greater number of outer tables;
 
3124
    */
 
3125
    sj_subselects.sort(subq_sj_candidate_cmp);
 
3126
    // #tables-in-parent-query + #tables-in-subquery < MAX_TABLES
 
3127
    /* Replace all subqueries to be flattened with Item_int(1) */
 
3128
    for (in_subq= sj_subselects.front();
 
3129
        in_subq != in_subq_end &&
 
3130
        tables + ((*in_subq)->sj_convert_priority % MAX_TABLES) < MAX_TABLES;
 
3131
        in_subq++)
 
3132
    {
 
3133
      if (replace_where_subcondition(this, *in_subq, new Item_int(1), false))
 
3134
        return(true);
 
3135
    }
 
3136
 
 
3137
    for (in_subq= sj_subselects.front();
 
3138
        in_subq != in_subq_end &&
 
3139
        tables + ((*in_subq)->sj_convert_priority % MAX_TABLES) < MAX_TABLES;
 
3140
        in_subq++)
 
3141
    {
 
3142
      if (convert_subq_to_sj(this, *in_subq))
 
3143
        return(true);
 
3144
    }
3141
3145
  }
3142
3146
 
3143
3147
  /* 3. Finalize those we didn't convert */