mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-12387 Push conditions into materialized subqueries
The logic and the implementation scheme are similar with the MDEV-9197 Pushdown conditions into non-mergeable views/derived tables How the push down is made on the example: select * from t1 where a>3 and b>10 and (a,b) in (select x,max(y) from t2 group by x); --> select * from t1 where a>3 and b>10 and (a,b) in (select x,max(y) from t2 where x>3 group by x having max(y)>10); The implementation scheme: 1. Search for the condition cond that depends only on the fields from the left part of the IN subquery (left_part) 2. Find fields F_group in the select of the right part of the IN subquery (right_part) that are used in the GROUP BY 3. Extract from the cond condition cond_where that depends only on the fields from the left_part that stay at the same places in the left_part (have the same indexes) as the F_group fields in the projection of the right_part 4. Transform cond_where so it can be pushed into the WHERE clause of the right_part and delete cond_where from the cond 5. Transform cond so it can be pushed into the HAVING clause of the right_part The optimization is made in the Item_in_subselect::pushdown_cond_for_in_subquery() and is controlled by the variable condition_pushdown_for_subquery. New test file in_subq_cond_pushdown.test is created. There are also some changes made for setup_jtbm_semi_joins(). Now it is decomposed into the 2 procedures: setup_degenerate_jtbm_semi_joins() that is called before optimize_cond() for cond and setup_jtbm_semi_joins() that is called after optimize_cond(). New setup_jtbm_semi_joins() is made in the way so that the result of its work is the same as if it was called before optimize_cond(). The code that is common for pushdown into materialized derived and into materialized IN subqueries is factored out into pushdown_cond_for_derived(), Item_in_subselect::pushdown_cond_for_in_subquery() and st_select_lex::pushdown_cond_into_where_clause().
This commit is contained in:
@ -1470,6 +1470,11 @@ public:
|
||||
Dynamic_array<KEYUSE_EXT> *ext_keyuses_for_splitting;
|
||||
|
||||
JOIN_TAB *sort_and_group_aggr_tab;
|
||||
/*
|
||||
Flag is set to true if select_lex was found to be degenerated before
|
||||
the optimize_cond() call in JOIN::optimize_inner() method.
|
||||
*/
|
||||
bool is_orig_degenerated;
|
||||
|
||||
JOIN(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg,
|
||||
select_result *result_arg)
|
||||
@ -1564,6 +1569,7 @@ public:
|
||||
emb_sjm_nest= NULL;
|
||||
sjm_lookup_tables= 0;
|
||||
sjm_scan_tables= 0;
|
||||
is_orig_degenerated= false;
|
||||
}
|
||||
|
||||
/* True if the plan guarantees that it will be returned zero or one row */
|
||||
@ -1734,6 +1740,7 @@ public:
|
||||
bool fix_all_splittings_in_plan();
|
||||
|
||||
bool transform_in_predicates_into_in_subq(THD *thd);
|
||||
bool add_equalities_to_where_condition(THD *thd, List<Item> &eq_list);
|
||||
private:
|
||||
/**
|
||||
Create a temporary table to be used for processing DISTINCT/ORDER
|
||||
@ -2325,7 +2332,7 @@ Item_equal *find_item_equal(COND_EQUAL *cond_equal, Field *field,
|
||||
extern bool test_if_ref(Item *,
|
||||
Item_field *left_item,Item *right_item);
|
||||
|
||||
inline bool optimizer_flag(THD *thd, uint flag)
|
||||
inline bool optimizer_flag(THD *thd, ulonglong flag)
|
||||
{
|
||||
return (thd->variables.optimizer_switch & flag);
|
||||
}
|
||||
@ -2440,4 +2447,13 @@ int create_sort_index(THD *thd, JOIN *join, JOIN_TAB *tab, Filesort *fsort);
|
||||
JOIN_TAB *first_explain_order_tab(JOIN* join);
|
||||
JOIN_TAB *next_explain_order_tab(JOIN* join, JOIN_TAB* tab);
|
||||
|
||||
bool check_simple_equality(THD *thd, const Item::Context &ctx,
|
||||
Item *left_item, Item *right_item,
|
||||
COND_EQUAL *cond_equal);
|
||||
|
||||
void propagate_new_equalities(THD *thd, Item *cond,
|
||||
List<Item_equal> *new_equalities,
|
||||
COND_EQUAL *inherited,
|
||||
bool *is_simplifiable_cond);
|
||||
|
||||
#endif /* SQL_SELECT_INCLUDED */
|
||||
|
Reference in New Issue
Block a user