summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc63
1 files changed, 43 insertions, 20 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 10884a95b74..992fa8f6212 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -276,15 +276,15 @@ bool handle_select(THD *thd, LEX *lex, select_result *result,
setup_tables_done_option changed for next rexecution
*/
res= mysql_select(thd, &select_lex->ref_pointer_array,
- (TABLE_LIST*) select_lex->table_list.first,
+ select_lex->table_list.first,
select_lex->with_wild, select_lex->item_list,
select_lex->where,
select_lex->order_list.elements +
select_lex->group_list.elements,
- (ORDER*) select_lex->order_list.first,
- (ORDER*) select_lex->group_list.first,
+ select_lex->order_list.first,
+ select_lex->group_list.first,
select_lex->having,
- (ORDER*) lex->proc_list.first,
+ lex->proc_list.first,
select_lex->options | thd->variables.option_bits |
setup_tables_done_option,
result, unit, select_lex);
@@ -2747,31 +2747,53 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables_arg, COND *conds,
/*
Build transitive closure for relation 'to be dependent on'.
This will speed up the plan search for many cases with outer joins,
- as well as allow us to catch illegal cross references/
+ as well as allow us to catch illegal cross references.
Warshall's algorithm is used to build the transitive closure.
- As we use bitmaps to represent the relation the complexity
- of the algorithm is O((number of tables)^2).
+ As we may restart the outer loop upto 'table_count' times, the
+ complexity of the algorithm is O((number of tables)^3).
+ However, most of the iterations will be shortcircuited when
+ there are no pedendencies to propogate.
*/
- for (i= 0, s= stat ; i < table_count ; i++, s++)
+ for (i= 0 ; i < table_count ; i++)
{
- for (uint j= 0 ; j < table_count ; j++)
+ uint j;
+ table= stat[i].table;
+
+ if (!table->reginfo.join_tab->dependent)
+ continue;
+
+ /* Add my dependencies to other tables depending on me */
+ for (j= 0, s= stat ; j < table_count ; j++, s++)
{
- table= stat[j].table;
if (s->dependent & table->map)
+ {
+ table_map was_dependent= s->dependent;
s->dependent |= table->reginfo.join_tab->dependent;
+ /*
+ If we change dependencies for a table we already have
+ processed: Redo dependency propagation from this table.
+ */
+ if (i > j && s->dependent != was_dependent)
+ {
+ i = j-1;
+ break;
+ }
+ }
}
- if (outer_join & s->table->map)
- s->table->maybe_null= 1;
}
- /* Catch illegal cross references for outer joins */
+
for (i= 0, s= stat ; i < table_count ; i++, s++)
{
+ /* Catch illegal cross references for outer joins */
if (s->dependent & s->table->map)
{
join->tables=0; // Don't use join->table
my_message(ER_WRONG_OUTER_JOIN, ER(ER_WRONG_OUTER_JOIN), MYF(0));
goto error;
}
+
+ if (outer_join & s->table->map)
+ s->table->maybe_null= 1;
s->key_dependent= s->dependent;
}
}
@@ -8824,6 +8846,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
NESTED_JOIN *nested_join;
TABLE_LIST *prev_table= 0;
List_iterator<TABLE_LIST> li(*join_list);
+ bool straight_join= test(join->select_options & SELECT_STRAIGHT_JOIN);
DBUG_ENTER("simplify_joins");
/*
@@ -8934,7 +8957,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
if (prev_table)
{
/* The order of tables is reverse: prev_table follows table */
- if (prev_table->straight)
+ if (prev_table->straight || straight_join)
prev_table->dep_tables|= used_tables;
if (prev_table->on_expr)
{
@@ -17005,15 +17028,15 @@ bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
thd->lex->current_select= first;
unit->set_limit(unit->global_parameters);
res= mysql_select(thd, &first->ref_pointer_array,
- (TABLE_LIST*) first->table_list.first,
+ first->table_list.first,
first->with_wild, first->item_list,
first->where,
first->order_list.elements +
first->group_list.elements,
- (ORDER*) first->order_list.first,
- (ORDER*) first->group_list.first,
+ first->order_list.first,
+ first->group_list.first,
first->having,
- (ORDER*) thd->lex->proc_list.first,
+ thd->lex->proc_list.first,
first->options | thd->variables.option_bits | SELECT_DESCRIBE,
result, unit, first);
}
@@ -17316,7 +17339,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
if (group_list.elements)
{
str->append(STRING_WITH_LEN(" group by "));
- print_order(str, (ORDER *) group_list.first, query_type);
+ print_order(str, group_list.first, query_type);
switch (olap)
{
case CUBE_TYPE:
@@ -17347,7 +17370,7 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
if (order_list.elements)
{
str->append(STRING_WITH_LEN(" order by "));
- print_order(str, (ORDER *) order_list.first, query_type);
+ print_order(str, order_list.first, query_type);
}
// limit