-
Norvald H. Ryeng authored
BITMAP_IS_SET(TABLE->READ_SET, This is a fix for a regression introduced by the fix for bug #14728142. Problem: A query with an EXISTS/IN/ALL/ANY subquery with an ORDER BY clause ordering by an outer column of type BLOB that is not in the select list causes an assertion to fire. The subquery has an ORDER BY clause that is removed by remove_redundant_subquery_clauses(), but after the fix for bug #14728142, the clause is resolved before it is removed. This happens when JOIN::prepare() calls setup_without_group(), which again calls setup_order() to resolve the ORDER BY clause. The clause resolves to a column that is not already in the select list, so it is added to the front of the subquery's JOIN::all_fields. After resolving the ORDER BY clause, JOIN::prepare() calls remove_redundant_subquery_clauses(), which removes the ORDER BY clause from SELECT_LEX::order_list and JOIN::order, but no attempt is made to remove it from JOIN::all_fields. During execution, this field is made part of a temporary table, but since the clause that referenced the field now has been removed from the query, the server fails an assertion in Field_blob::val_str() requiring the column to be marked for read. The problem in bug #14728142 was that the removed GROUP BY and ORDER BY clauses were not resolved. This bug is caused by the side effects of resolving them. Fix: Resolve GROUP BY before ORDER BY to allow rolling back resolving of clauses when they are removed. The items are removed from JOIN::all_fields, and any removed aggregation functions are also removed from st_select_lex::inner_sum_func_list if moved there by Item_sum::register_sum_func(). Also, the hierarchy of st_select_lex_unit and st_select_lex objects are kept in sync with the item tree so that when an Item_subselect is removed, the corresponding st_select_lex_unit and st_select_lex are unlinked from the tree so that they are not reachable when traversing the tree or all_selects_list. This patch also fixes bug #15876549. mysql-test/r/group_by.result EXPLAIN changes due to st_select_lex cleanup. sql/item.h New Item::clean_up_after_removal() walk processor function that cleans up after removing an item from the query. sql/item_subselect.cc New Item_subselect::clean_up_after_removal() walk processor function that unlinks the st_select_lex_unit and st_select_lex objects from the tree of st_select_lex_nodes and the global select_lex list. sql/item_subselect.h New Item_subselect::clean_up_after_removal() walk processor function. sql/item_sum.cc New Item_sum::clean_up_after_removal() walk processor function that removes the item from st_select_lex::inner_sum_funcs list. sql/item_sum.h New Item_sum::clean_up_after_removal() walk processor function. sql/sql_optimizer.cc New hidden_group_field_count field that counts the number of hidden group fields added by setup_group(). sql/sql_resolver.cc Expand remove_redundant_subquery_clauses() to also remove the clauses from all_fields and ref_pointer_array and to clean up after removal of Item_subselect and Item_sum items. Clean-up is also done in find_order_in_list() if an item is resolved to point to an item in the select or grouping list. In setup_without_group(), the order of resolving is changed to resolve GROUP BY before ORDER BY. This makes it possible for remove_redundant_subquery_clauses() to remove ORDER BY from all_fields without first removing GROUP BY. Because of this change, match_exprs_for_only_full_group_by() is adapted to understand the new ordering of items in all_fields.
Norvald H. Ryeng authoredBITMAP_IS_SET(TABLE->READ_SET, This is a fix for a regression introduced by the fix for bug #14728142. Problem: A query with an EXISTS/IN/ALL/ANY subquery with an ORDER BY clause ordering by an outer column of type BLOB that is not in the select list causes an assertion to fire. The subquery has an ORDER BY clause that is removed by remove_redundant_subquery_clauses(), but after the fix for bug #14728142, the clause is resolved before it is removed. This happens when JOIN::prepare() calls setup_without_group(), which again calls setup_order() to resolve the ORDER BY clause. The clause resolves to a column that is not already in the select list, so it is added to the front of the subquery's JOIN::all_fields. After resolving the ORDER BY clause, JOIN::prepare() calls remove_redundant_subquery_clauses(), which removes the ORDER BY clause from SELECT_LEX::order_list and JOIN::order, but no attempt is made to remove it from JOIN::all_fields. During execution, this field is made part of a temporary table, but since the clause that referenced the field now has been removed from the query, the server fails an assertion in Field_blob::val_str() requiring the column to be marked for read. The problem in bug #14728142 was that the removed GROUP BY and ORDER BY clauses were not resolved. This bug is caused by the side effects of resolving them. Fix: Resolve GROUP BY before ORDER BY to allow rolling back resolving of clauses when they are removed. The items are removed from JOIN::all_fields, and any removed aggregation functions are also removed from st_select_lex::inner_sum_func_list if moved there by Item_sum::register_sum_func(). Also, the hierarchy of st_select_lex_unit and st_select_lex objects are kept in sync with the item tree so that when an Item_subselect is removed, the corresponding st_select_lex_unit and st_select_lex are unlinked from the tree so that they are not reachable when traversing the tree or all_selects_list. This patch also fixes bug #15876549. mysql-test/r/group_by.result EXPLAIN changes due to st_select_lex cleanup. sql/item.h New Item::clean_up_after_removal() walk processor function that cleans up after removing an item from the query. sql/item_subselect.cc New Item_subselect::clean_up_after_removal() walk processor function that unlinks the st_select_lex_unit and st_select_lex objects from the tree of st_select_lex_nodes and the global select_lex list. sql/item_subselect.h New Item_subselect::clean_up_after_removal() walk processor function. sql/item_sum.cc New Item_sum::clean_up_after_removal() walk processor function that removes the item from st_select_lex::inner_sum_funcs list. sql/item_sum.h New Item_sum::clean_up_after_removal() walk processor function. sql/sql_optimizer.cc New hidden_group_field_count field that counts the number of hidden group fields added by setup_group(). sql/sql_resolver.cc Expand remove_redundant_subquery_clauses() to also remove the clauses from all_fields and ref_pointer_array and to clean up after removal of Item_subselect and Item_sum items. Clean-up is also done in find_order_in_list() if an item is resolved to point to an item in the select or grouping list. In setup_without_group(), the order of resolving is changed to resolve GROUP BY before ORDER BY. This makes it possible for remove_redundant_subquery_clauses() to remove ORDER BY from all_fields without first removing GROUP BY. Because of this change, match_exprs_for_only_full_group_by() is adapted to understand the new ordering of items in all_fields.
Loading