Bug #24484:
To correctly decide which predicates can be evaluated with a given table the optimizer must know the exact set of tables that a predicate depends on. If that mask is too wide (refer to non-existing tables) the optimizer can erroneously skip a predicate. One such case of wrong table usage mask were the aggregate functions. The have a all-1 mask (meaning depend on all tables, including non-existent ones). Fixed by making a real used_tables mask for the aggregates. The mask is constructed in the following way : 1. OR the table dependency masks of all the arguments of the aggregate. 2. If all the arguments of the function are from the local name resolution context and it is evaluated in the same name resolution context where it is referenced all the tables from that name resolution context are OR-ed to the dependency mask. This is to denote that an aggregate function depends on the number of rows it processes. 3. Handle correctly the case of an aggregate function optimization (such that the aggregate function can be pre-calculated and made a constant). Made sure that an aggregate function is never a constant (unless subject of a specific optimization and pre-calculation). One other flaw was revealed and fixed in the process : references were not calling the recalculation method for used_tables of their targets. mysql-test/r/subselect3.result: Bug #24484: test case mysql-test/t/subselect3.test: Bug #24484: test case sql/item.h: Bug #24484: Item_ref must update the used tables. sql/item_sum.cc: Bug #24484: correct calculation of used_tables for aggregates. sql/item_sum.h: Bug #24484: correct calculation of used_tables for aggregates. sql/opt_range.cc: Bug #24484: fixed ref resolution in loose index scan sql/sql_base.cc: Bug #24484: moved counting of leaf tables inside setup_tables_and_check_access. sql/sql_class.h: Bug #24484: changed table count to more narrow type. sql/sql_insert.cc: Bug #24484: moved counting of leaf tables inside setup_tables_and_check_access. Substract the first table (and its subtables) of an INSERT statement from leaf_count. sql/sql_select.cc: Bug #24484: correct check for aggregates
Showing
Please register or sign in to comment