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.
mysql-test/r/join_nested.result:
Added a test case for bug #29604.
mysql-test/t/join_nested.test:
Added a test case for bug #29604.
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()).
mysql-test/r/join_nested.result:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- test case
mysql-test/t/join_nested.test:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- test case
sql/mysql_priv.h:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- use SELECT_LEX to store the ref to JOIN USING list needed by the
parser
sql/sql_base.cc:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- proper check for duplicate cols
- more detailed debug output
sql/sql_lex.h:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- use SELECT_LEX to store the ref to JOIN USING list needed by the
parser
sql/sql_parse.cc:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- proper check for duplicate cols in JOIN USING
sql/sql_yacc.yy:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- use SELECT_LEX to store the ref to JOIN USING list needed by the
parser
sql/table.cc:
BUG#25575: ERROR 1052 (Column in from clause is ambiguous) with sub-join
- return null if no table ref (as in nested join columns).
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.
mysql-test/r/join_nested.result:
Added a test case for bug #24345.
mysql-test/t/join_nested.test:
Added a test case for bug #24345.
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.
mysql-test/r/join_nested.result:
Added a test case for bug #18279.
mysql-test/t/join_nested.test:
Added a test case for bug #18279.
sql/sql_prepare.cc:
Fixed bug #18279.
On expressions were not restored for nested joins in
reinit_stmt_before_use.
sql/sql_select.cc:
Fixed bug #18279.
The function simplify_joins could change on expressions for nested joins.
Yet modified on expressions were not saved in prep_on_expr.
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.
mysql-test/r/join_nested.result:
Added a test case for bug #16260.
mysql-test/t/join_nested.test:
Added a test case for bug #16260.
sql/sql_select.cc:
Fixed bug #16260.
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.
A table is never considered as a const table if it is used in a nested join
that serves as an inner operand of an outer join.
'ref' accesses to all tables that are direct children of the nested join and are
not inner wrt their siblings.
mysql-test/r/join_nested.result:
Testcase for BUG#16393
mysql-test/t/join_nested.test:
Testcase for BUG#16393
orders that cannot be handled by the executioner.
mysql-test/r/bigint.result:
Added mssing "drop table if exists"
mysql-test/r/join_nested.result:
Testcase for BUG#13126
mysql-test/t/bigint.test:
Added mssing "drop table if exists"
mysql-test/t/join_nested.test:
Testcase for BUG#13126
sql/mysql_priv.h:
BUG#13126: Added nested_join_map type.
sql/sql_prepare.cc:
BUG#13126: Don't set NESTED_JOIN::counter to 0 here as it is reset in other place now.
sql/sql_select.cc:
BUG#13126: When choosing join order for join with nested joins, don't produce join orders
that the executioner cannot handle. The work is done by check_interleaving_with_nj() and
restore_prev_nj_state() functions that are used from the join optimizer to avoid building
invalid join orders.
sql/sql_select.h:
BUG#13126: Added JOIN_TAB::embedding_map and JOIN::cur_embedding_map.
sql/table.h:
BUG#13126: In NESTED_JOIN: added nj_map, added comment about where counter is used.
sql/sql_base.cc:
fix for bug #13545: Server crash caused by select query.
- compare table qualifier only with tables which are not nested joins.
- perform recursion accordingly.
- DBUG_ASSERT(table_list->table); added before the find_field_in_table() call.
* 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.
mysql-test/include/ps_query.inc:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/bdb.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/innodb.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/join.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/join_nested.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/join_outer.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/null_key.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/order_by.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/ps_2myisam.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/ps_3innodb.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/ps_4heap.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/ps_5merge.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/ps_6bdb.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/ps_7ndb.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/select.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/subselect.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/r/type_ranges.result:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/bdb.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/innodb.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/join.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/join_nested.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/join_outer.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/null_key.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/order_by.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/select.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/subselect.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
mysql-test/t/type_ranges.test:
Put back old tests to test that coalesced columns of natural joins can be qualified.
sql/sql_base.cc:
* Applied Monty's patch for backwards compatible name resolution
of qualified columns. The idea is:
- When a column is qualified, search for the column in all
tables/views underlying each natural join. In this case
natural joins are *not* considered leaves.
- If a column is not qualified, then consider natural joins
as leaves, thus directly search the result columns of
natural joins.
* Simplified 'find_field_in_tables()' - unified two similar
loops into one.
sql/table.cc:
- Removed method & members not needed after Monty's patch.
sql/table.h:
- Removed method & members not needed after Monty's patch.
tests/mysql_client_test.c:
Put back old tests to test that coalesced columns of natural joins can be qualified.
into mysql.com:/home/timka/mysql/src/5.0-2486-merge
mysql-test/r/errors.result:
Auto merged
mysql-test/r/fulltext.result:
Auto merged
mysql-test/r/fulltext_order_by.result:
Auto merged
mysql-test/r/innodb.result:
Auto merged
mysql-test/r/join_nested.result:
Auto merged
mysql-test/r/subselect.result:
Auto merged
mysql-test/t/errors.test:
Auto merged
mysql-test/t/fulltext.test:
Auto merged
mysql-test/t/fulltext_order_by.test:
Auto merged
mysql-test/t/innodb.test:
Auto merged
mysql-test/t/join_nested.test:
Auto merged
mysql-test/t/subselect.test:
Auto merged
sql/item.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sp.cc:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
sql/table.h:
Auto merged
tests/mysql_client_test.c:
Auto merged
sql/sql_insert.cc:
merge WL#2486
sql/sql_show.cc:
merge WL#2486
"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
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
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.
mysql-test/t/join_nested.test:
Added a test case for bug #12154.
mysql-test/r/join_nested.result:
Added a test case for bug #12154.
sql/mysql_priv.h:
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.
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.
sql/sql_select.cc:
Fixed bug #11284.
Optimization with empty inner table currently cannot be
used in the case of nested outer join.
mysql-test/t/join_nested.test:
Added a teast case for bug #11284.
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.
sql/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.
The crash of the test case for bug #4976 was fixed
adding a guard that blocks running the code for
nested outer joins.
mysql-test/r/join.result:
Reversed the previous change of the erronious fix for bug #4976.
mysql-test/r/select.result:
Reversed the previous change of the erronious fix for bug #4976.
mysql-test/r/join_nested.result:
Added a case for bug #4976 when one of the inner tables is empty.
mysql-test/t/join_nested.test:
Added a case for bug #4976 when one of the inner tables is empty.
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.
sql/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.
mysql-test/t/join_nested.test:
Added a case test for bug #4976.
mysql-test/r/join_nested.result:
Added a case test for bug #4976.
mysql-test/r/select.result:
Fixed bug #4976.
mysql-test/r/join.result:
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.
sql/sql_yacc.yy:
Fixed a typo bug in the rule for join_table.
sql/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.
mysql-test/t/join_nested.test:
Added a test case for bug #4922.
mysql-test/r/join_nested.result:
Added a test case for bug #4922.
spaces at line end in fresh definitions removed
fixed printing of nested joins (BUG#4352)
mysql-test/r/join_nested.result:
fixed join_nested test independence of environment
print of nested join test added
mysql-test/t/join_nested.test:
fixed join_nested test independence of environment
print of nested join test added
sql/sql_lex.h:
space at line end in fresh definition removed
sql/sql_select.cc:
fixed printing of nested joins
sql/table.h:
spaces at line end in fresh definitions removed
method for table printing