Skip to content

Commit 4de3fd4

Browse files
committed
MDEV-7486: Cosmetic changes
- Removed dead code - Renamed a function - Removed a parameter that not needed. - Corrected comments
1 parent 9741930 commit 4de3fd4

File tree

2 files changed

+36
-71
lines changed

2 files changed

+36
-71
lines changed

sql/sql_lex.cc

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7754,13 +7754,13 @@ void binlog_unsafe_map_init()
77547754

77557755
/**
77567756
@brief
7757-
Finding fiels that are used in the GROUP BY of this st_select_lex
7757+
Collect fiels that are used in the GROUP BY of this st_select_lex
77587758
77597759
@param thd The thread handle
77607760
77617761
@details
7762-
This method looks through the fields which are used in the GROUP BY of this
7763-
st_select_lex and saves this fields.
7762+
This method looks through the fields that are used in the GROUP BY of this
7763+
st_select_lex and saves onfo on these fields.
77647764
*/
77657765

77667766
void st_select_lex::collect_grouping_fields_for_derived(THD *thd,
@@ -7826,7 +7826,7 @@ bool st_select_lex::collect_grouping_fields(THD *thd)
78267826
This method traverses the AND-OR condition cond and for each subformula of
78277827
the condition it checks whether it can be usable for the extraction of a
78287828
condition over the grouping fields of this select. The method uses
7829-
the call-back parameter checker to ckeck whether a primary formula
7829+
the call-back parameter checker to check whether a primary formula
78307830
depends only on grouping fields.
78317831
The subformulas that are not usable are marked with the flag NO_EXTRACTION_FL.
78327832
The subformulas that can be entierly extracted are marked with the flag
@@ -7870,7 +7870,7 @@ st_select_lex::check_cond_extraction_for_grouping_fields(THD *thd, Item *cond,
78707870
else if (!and_cond)
78717871
break;
78727872
}
7873-
if (item)
7873+
if ((and_cond && count == 0) || item)
78747874
cond->set_extraction_flag(NO_EXTRACTION_FL);
78757875
if (count_full == arg_list->elements)
78767876
{
@@ -9723,7 +9723,7 @@ void st_select_lex::mark_or_conds_to_avoid_pushdown(Item *cond)
97239723
@details
97249724
The method finds out what conditions can be extracted from cond depended
97259725
only on the grouping fields of this SELECT or fields equal to them.
9726-
If the condition that can be pushed is AND-condition it is splitted out
9726+
If the condition that can be pushed is AND-condition it is splitted up
97279727
and for each its element it is checked if it can be pushed.
97289728
Pushable elements are attached to the attach_to_conds list.
97299729
If the condition isn't AND-condition it is entirely pushed into
@@ -9745,9 +9745,11 @@ void st_select_lex::mark_or_conds_to_avoid_pushdown(Item *cond)
97459745

97469746
bool
97479747
st_select_lex::build_pushable_cond_for_having_pushdown(THD *thd,
9748-
Item *cond,
9749-
Pushdown_checker checker)
9748+
Item *cond)
97509749
{
9750+
Pushdown_checker checker=
9751+
&Item::pushable_equality_checker_for_having_pushdown;
9752+
97519753
bool is_multiple_equality= cond->type() == Item::FUNC_ITEM &&
97529754
((Item_func*) cond)->functype() == Item_func::MULT_EQUAL_FUNC;
97539755

@@ -9862,33 +9864,15 @@ Field_pair *get_corresponding_field_pair(Item *item,
98629864

98639865
/**
98649866
@brief
9865-
Find fields in WHERE clause multiple equalities that can be used in pushdown
9867+
Collect fields in multiple equalities usable for pushdown from having
98669868
98679869
@param thd The thread handle
98689870
98699871
@details
98709872
This method looks through the multiple equalities of the WHERE clause
9871-
trying to find any of them which fields are used in the GROUP BY of the
9872-
SELECT. If such multiple equality exists conditions in the HAVING
9873-
clause that use fields of this multiple equality can be pushed down
9874-
into the WHERE clause as well as the conditions depended on the fields
9875-
from the GROUP BY or fields equal to them that are taken from the HAVING
9876-
clause multiple equalities.
9877-
9878-
Example:
9879-
9880-
SELECT a,MAX(b),c
9881-
FROM t1
9882-
WHERE (t1.a=t1.c)
9883-
GROUP BY t1.a
9884-
HAVING (t1.c>1)
9885-
9886-
=>
9887-
9888-
SELECT a,MAX(b),c
9889-
FROM t1
9890-
WHERE (t1.a=t1.c) AND (t1.c>1)
9891-
GROUP BY t1.a
9873+
trying to find any of them whose fields are used in the GROUP BY of the
9874+
SELECT. Any field from these multiple equality is included into the
9875+
the list of fields against which any candidate for pushing is checked.
98929876
98939877
@retval
98949878
true - if an error occurs
@@ -9909,22 +9893,16 @@ bool st_select_lex::collect_fields_equal_to_grouping(THD *thd)
99099893
Item *item;
99109894
while ((item= it++))
99119895
{
9912-
if (item->type() != Item::FIELD_ITEM &&
9913-
item->type() != Item::REF_ITEM)
9914-
continue;
9915-
99169896
if (get_corresponding_field_pair(item, grouping_tmp_fields))
99179897
break;
99189898
}
99199899
if (!item)
99209900
break;
9921-
it.rewind();
99229901

9902+
it.rewind();
99239903
while ((item= it++))
99249904
{
9925-
if ((item->type() != Item::FIELD_ITEM &&
9926-
item->type() != Item::REF_ITEM) ||
9927-
get_corresponding_field_pair(item, grouping_tmp_fields))
9905+
if (get_corresponding_field_pair(item, grouping_tmp_fields))
99289906
continue;
99299907
Field_pair *grouping_tmp_field=
99309908
new Field_pair(((Item_field *)item->real_item())->field, item);
@@ -9937,7 +9915,7 @@ bool st_select_lex::collect_fields_equal_to_grouping(THD *thd)
99379915

99389916
/**
99399917
@brief
9940-
Cleanup and fix for the condition that is ready to be pushed down
9918+
Cleanup and fix of the condition that is ready to be pushed down
99419919
99429920
@param thd The thread handle
99439921
@param cond The condition to be processed
@@ -9954,7 +9932,7 @@ bool st_select_lex::collect_fields_equal_to_grouping(THD *thd)
99549932
*/
99559933

99569934
static
9957-
bool cleanup_inequalities_for_having_pushdown(THD *thd, Item *cond)
9935+
bool cleanup_condition_pushed_from_having(THD *thd, Item *cond)
99589936
{
99599937
if (cond->type() == Item::FUNC_ITEM &&
99609938
((Item_func*) cond)->functype() == Item_func::MULT_EQUAL_FUNC)
@@ -9966,7 +9944,7 @@ bool cleanup_inequalities_for_having_pushdown(THD *thd, Item *cond)
99669944
Item *item;
99679945

99689946
while ((item=it++))
9969-
cleanup_inequalities_for_having_pushdown(thd, item);
9947+
cleanup_condition_pushed_from_having(thd, item);
99709948
}
99719949
else
99729950
{
@@ -10075,7 +10053,7 @@ Item *remove_pushed_top_conjuncts_for_having(THD *thd, Item *cond)
1007510053
This function builds the most restrictive condition depending only on
1007610054
the fields used in the GROUP BY of this select (directly or indirectly
1007710055
through equality) that can be extracted from the HAVING clause of this
10078-
select having and pushes it into the WHERE clause of this select.
10056+
select and pushes it into the WHERE clause of this select.
1007910057
1008010058
Example of the transformation:
1008110059
@@ -10095,11 +10073,11 @@ Item *remove_pushed_top_conjuncts_for_having(THD *thd, Item *cond)
1009510073
In details:
1009610074
1. Collect fields used in the GROUP BY grouping_fields of this SELECT
1009710075
2. Collect fields equal to grouping_fields from the WHERE clause
10098-
of this SELECT and attach them to the grouping_fields list.
10099-
3. Search for the conditions in the HAVING clause of this select
10100-
that depends only on grouping_fields. Store them in the
10101-
attach_to_conds list.
10102-
4. Remove pushable conditions from the HAVING clause having.
10076+
of this SELECT and add them to the grouping_fields list.
10077+
3. Extract the most restrictive condition from the HAVING clause of this
10078+
select that depends only on the grouping fields (directly or indirectly
10079+
through equality). Store it in the attach_to_conds list.
10080+
4. Remove pushable conditions from the HAVING clause if it's possible.
1010310081
1010410082
@note
1010510083
This method is similar to st_select_lex::pushdown_cond_into_where_clause().
@@ -10119,52 +10097,40 @@ Item *st_select_lex::pushdown_from_having_into_where(THD *thd, Item *having)
1011910097
thd->lex->current_select= this;
1012010098

1012110099
/*
10122-
1. Collect fields used in the GROUP BY grouping_fields of this SELECT
10100+
1. Collect fields used in the GROUP BY grouping fields of this SELECT
1012310101
2. Collect fields equal to grouping_fields from the WHERE clause
10124-
of this SELECT and attach them to the grouping_fields list.
10102+
of this SELECT and add them to the grouping fields list.
1012510103
*/
10126-
if (have_window_funcs())
10127-
{
10128-
if (group_list.first || join->implicit_grouping)
10129-
return having;
10130-
ORDER *common_partition_fields=
10131-
find_common_window_func_partition_fields(thd);
10132-
if (!common_partition_fields ||
10133-
collect_grouping_fields(thd) ||
10134-
collect_fields_equal_to_grouping(thd))
10135-
return having;
10136-
}
10137-
else if (collect_grouping_fields(thd) ||
10138-
collect_fields_equal_to_grouping(thd))
10104+
if (collect_grouping_fields(thd) ||
10105+
collect_fields_equal_to_grouping(thd))
1013910106
return having;
1014010107

1014110108
/*
10142-
3. Search for the conditions in the HAVING clause of this select
10143-
that depends only on grouping_fields. Store them in the
10144-
attach_to_conds list.
10109+
3. Extract the most restrictive condition from the HAVING clause of this
10110+
select that depends only on the grouping fields (directly or indirectly
10111+
through equality). Store it in the attach_to_conds list.
1014510112
*/
1014610113
thd->having_pushdown= true;
1014710114
List_iterator_fast<Item> it(attach_to_conds);
1014810115
Item *item;
1014910116
check_cond_extraction_for_grouping_fields(thd, having,
1015010117
&Item::dep_on_grouping_fields_checker_for_having_pushdown);
10151-
if (build_pushable_cond_for_having_pushdown(thd, having,
10152-
&Item::pushable_equality_checker_for_having_pushdown))
10118+
if (build_pushable_cond_for_having_pushdown(thd, having))
1015310119
{
1015410120
attach_to_conds.empty();
1015510121
goto exit;
1015610122
}
1015710123
if (attach_to_conds.elements != 0)
1015810124
{
1015910125
/*
10160-
4. Remove pushable conditions from the HAVING clause having.
10126+
4. Remove pushable conditions from the HAVING clause if it's possible.
1016110127
*/
1016210128
having= remove_pushed_top_conjuncts_for_having(thd, having);
1016310129

1016410130
it.rewind();
1016510131
while ((item=it++))
1016610132
{
10167-
if (cleanup_inequalities_for_having_pushdown(thd, item))
10133+
if (cleanup_condition_pushed_from_having(thd, item))
1016810134
{
1016910135
attach_to_conds.empty();
1017010136
goto exit;

sql/sql_lex.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,7 @@ class st_select_lex: public st_select_lex_node
15041504
{ return !olap && !explicit_limit && !tvc; }
15051505

15061506
bool build_pushable_cond_for_having_pushdown(THD *thd,
1507-
Item *cond,
1508-
Pushdown_checker checker);
1507+
Item *cond);
15091508
void pushdown_cond_into_where_clause(THD *thd, Item *extracted_cond,
15101509
Item **remaining_cond,
15111510
Item_transformer transformer,

0 commit comments

Comments
 (0)