A bug in the restore_prev_nj_state function allowed interleaving
inner tables of outer join operations with outer tables. With the
current implementation of the nested loops algorithm it could lead
to wrong result sets for queries with nested outer joins.
Another bug in this procedure effectively blocked evaluation of some
valid execution plans for queries with nested outer joins.
- added join cache indication in EXPLAIN (Extra column).
- prefer filesort over full scan over
index for ORDER BY (because it's faster).
- when switching from REF to RANGE because
RANGE uses longer key turn off sort on
the head table only as the resulting
RANGE access is a candidate for join cache
and we don't want to disable it by sorting
on the first table only.
Two problems here:
Problem 1:
While constructing the join columns list the optimizer does as follows:
1. Sets the join_using_fields/natural_join members of the right JOIN
operand.
2. Makes a "table reference" (TABLE_LIST) to parent the two tables.
3. Assigns the join_using_fields/is_natural_join of the wrapper table
using join_using_fields/natural_join of the rightmost table
4. Sets join_using_fields to NULL for the right JOIN operand.
5. Passes the parent table up to the same procedure on the upper
level.
Step 1 overrides the the join_using_fields that are set for a nested
join wrapping table in step 4.
Fixed by making a designated variable SELECT_LEX::prev_join_using to
pass the data from step 1 to step 4 without destroying the wrapping
table data.
Problem 2:
The optimizer checks for ambiguous columns while transforming
NATURAL JOIN/JOIN USING to JOIN ON. While doing that there was no
distinction between columns that are used in the generated join
condition (where ambiguity can be checked) and the other columns
(where ambiguity can be checked only when resolving references
coming from outside the JOIN construct itself).
Fixed by allowing the non-USING columns to be present in multiple
copies in both sides of the join and moving the ambiguity check
to the place where unqualified references to the join columns are
resolved (find_field_in_natural_join()).
This bug appeared after the patch for bug 21390 that had added some code
to handle outer joins with no matches after substitution of a const
table in an efficient way. That code as it is cannot be applied to the case
of nested outer join operations. Being applied to the queries with
nested outer joins the code can cause crashes or wrong result sets.
The fix blocks row substitution for const inner tables of an outer join
if the inner operand is not a single table.
- Make the range-et-al optimizer produce E(#table records after table
condition is applied),
- Make the join optimizer use this value,
- Add "filtered" column to EXPLAIN EXTENDED to show
fraction of records left after table condition is applied
- Adjust test results, add comments
out of a nested join to the on conditions for the nest.
The bug happened due to:
1. The function simplify_joins could change on expressions for nested joins.
Yet modified on expressions were not saved in prep_on_expr.
2. On expressions were not restored for nested joins in
reinit_stmt_before_use.
The problem has manifested itself in the cases when we have a nested outer join
for which it can be inferred that one of the inner tables is a single row table.
* Provide backwards compatibility extension to name resolution of
coalesced columns. The patch allows such columns to be qualified
with a table (and db) name, as it is in 4.1.
Based on a patch from Monty.
* Adjusted tests accordingly to test both backwards compatible name
resolution of qualified columns, and ANSI-style resolution of
non-qualified columns.
For this, each affected test has two versions - one with qualified
columns, and one without.
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
Fixed bug #12154: a query returned: Column <name> cannot be null.
The problem was due to a bug in the function setup_table_map:
the flag maybe_null was set up incorrectly for inner tables of
nested outer joins.
join_nested.result, join_nested.test:
Added a test case for bug #12154.
Added a teast case for bug #11284.
sql_select.cc:
Fixed bug #11284.
Optimization with empty inner table currently cannot be
used in the case of nested outer join.
FOUND is not a reserved keyword anymore
Added Item_field::set_no_const_sub() to be able to mark fields that can't be substituted
Added 'simple_select' method to be able to quickly determinate if a select_result is a normal SELECT
Note that the 5.0 tree is not yet up to date: Sanja will have to fix multi-update-locks for this merge to be complete
Added the code processing on expressions for applying
multiple equalities.
sql_select.cc:
Post-merge fixes for Item_equal patch.
Added the code processing on expressions for applying
multiple equalities.
Many files:
Post-merge fixes for Item_equal patch.
item_cmpfunc.cc:
Post-merge fixes for Item_equal patch.
Fixed a problem when an equality field=const cannot be applied to
the predicate P(field,c) for constant propagation as a conversion
of field is needed.
item.h, item.cc:
Fixed a problem when an equality field=const cannot be applied to
the predicate P(field,c) for constant propagation as a conversion
of field is needed.
Added a case for bug #4976 when one of the inner tables is empty.
select.result, join.result:
Reversed the previous change of the erronious fix for bug #4976.
sql_select.cc:
The previous fix for bug 4976 was reversed as it
erroniously converted an outer join into an innner join
when on_expression does not refer to outer tables.
This is not valid if inner tables return an empty set.
Setting dependency on outer tables was added for the above cases.
To fix the crash in the test case of bug #4976
a guard was added that blocks running the crashing code for
nested outer joins.
Fixed bug #4976.
join_nested.result, join_nested.test:
Added a test case for bug #4976.
sql_select.cc:
Applied conversion from an outer join to an inner join
when the on expression does not depend on the outer table.
It fixed bug #4976.
Added a test case for bug #4922.
sql_select.cc:
Blocked an optimization performed by join_read_const_table when
applied to an inner table of a nested outer join.
It was done to fix bug #4922.
sql_yacc.yy:
Fixed a typo bug in the rule for join_table.
Post-merge fixes for nested joins.
The join_tab_cmp function in sql_select has been changed.
join_nested.result:
Post-merge fixes for nested joins.
The join_tab_cmp function in sql_select has been changed
sql_select.cc:
Post-merge fixes for nested joins.
Avoided re-execution of eliminate_not_funcs and simplify_joins
in optimize_cond.
Changed the join_tab_cmp function to take into account
the dependent relation.
sql_lex.cc, sql_lex.h:
Added the first_cond_optimization flag to st_select_lex to avoid
re-execution of some optimizations in optimize_cond.
sql_base.cc:
Post-merge fixes for nested joins.
Fixed problems with a proper column list substituted for '*' in
queries with natural joins.