Repository navigation
Conversation
…E and ON conditions The arguments of AND and OR are evaluated left to right with short-circuiting, in the order written in the query. An expensive subcondition written first is therefore evaluated even for rows that a cheap one would reject (AND) or accept (OR). Reorder the arguments of each AND/OR so that the expensive ones come after the cheap ones, keeping the relative order within each group. The walk goes down into nested AND/OR and into trigger conditions. A subcondition is expensive if it contains a subquery, a stored function call, or an item that marks itself as expensive through is_expensive_processor() (a UDF, MATCH()). An AND/OR that has a non-deterministic argument (one with RAND_TABLE_BIT) keeps its order, to prevent unwanted change of behavior. Nested lists are still reordered. The reordering is applied to: - the conditions attached to tables (select_cond, select->cond, on_precond), at the end of make_join_select() and before the attached_conditions_summary trace, so the trace shows the final order; - BNL/BNLH scan filters, in make_scan_filter(). They are built from the original WHERE/ON, and check_join_cache_usage() may build them after make_join_select(); - outer_ref_cond, the condition a subquery checks once per execution before running its join. The steps that later build new conditions from these (index condition pushdown, removal of duplicate BNL conditions) take subsets and keep the order. The fix is OFF by default and enabled by setting REORDER_EXPENSIVE_CONDS flag in @@new_mode. Not covered yet: HAVING, exec_const_cond, terms added after make_join_select() (the index condition remainder rejected by an engine, HAVING moved to a table's condition). Reordering HAVING would need care with Item_is_not_null_test and Item_ref_null_helper, which record NULLs for IN->EXISTS.
Contributor
Author
|
This feature is backported to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…E and ON conditions
The arguments of AND and OR are evaluated left to right with short-circuiting, in the order written in the query. An expensive subcondition written first is therefore evaluated even for rows that a cheap one would reject (AND) or accept (OR).
Reorder the arguments of each AND/OR so that the expensive ones come after the cheap ones, keeping the relative order within each group. The walk goes down into nested AND/OR and into trigger conditions. A subcondition is expensive if it contains a subquery, a stored function call, or an item that marks itself as expensive through is_expensive_processor() (a UDF, MATCH()).
An AND/OR that has a non-deterministic argument (one with RAND_TABLE_BIT) keeps its order, to prevent unwanted change of behavior. Nested lists are still reordered.
The reordering is applied to:
The fix is OFF by default and enabled by setting REORDER_EXPENSIVE_CONDS flag in @@new_mode.
Not covered yet: HAVING, exec_const_cond, terms added after make_join_select() (the index condition remainder rejected by an engine, HAVING moved to a table's condition). Reordering HAVING would need care with Item_is_not_null_test and Item_ref_null_helper, which record NULLs for IN->EXISTS.