Skip to content

Commit 3fb4f9b

Browse files
committed
Merge branch '10.2-mdev9197-cons' of github.com:shagalla/server
into branch 10.2-mdev9197.
2 parents 670760d + eb2c147 commit 3fb4f9b

30 files changed

+8926
-14
lines changed

mysql-test/r/derived_cond_pushdown.result

Lines changed: 6436 additions & 0 deletions
Large diffs are not rendered by default.

mysql-test/t/derived_cond_pushdown.test

Lines changed: 812 additions & 0 deletions
Large diffs are not rendered by default.

sql/item.cc

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ Item::Item(THD *thd):
488488
}
489489
}
490490

491+
491492
/**
492493
Constructor used by Item_field, Item_ref & aggregate (sum)
493494
functions.
@@ -2258,6 +2259,73 @@ bool Item_func_or_sum::agg_item_set_converter(const DTCollation &coll,
22582259
}
22592260

22602261

2262+
/**
2263+
@brief
2264+
Building clone for Item_func_or_sum
2265+
2266+
@param thd thread handle
2267+
@param mem_root part of the memory for the clone
2268+
2269+
@details
2270+
This method gets copy of the current item and also
2271+
build clones for its referencies. For the referencies
2272+
build_copy is called again.
2273+
2274+
@retval
2275+
clone of the item
2276+
0 if an error occured
2277+
*/
2278+
2279+
Item* Item_func_or_sum::build_clone(THD *thd, MEM_ROOT *mem_root)
2280+
{
2281+
Item_func_or_sum *copy= (Item_func_or_sum *) get_copy(thd, mem_root);
2282+
if (!copy)
2283+
return 0;
2284+
if (arg_count > 2)
2285+
copy->args=
2286+
(Item**) alloc_root(mem_root, sizeof(Item*) * arg_count);
2287+
else if (arg_count > 0)
2288+
copy->args= copy->tmp_arg;
2289+
for (uint i= 0; i < arg_count; i++)
2290+
{
2291+
Item *arg_clone= args[i]->build_clone(thd, mem_root);
2292+
if (!arg_clone)
2293+
return 0;
2294+
copy->args[i]= arg_clone;
2295+
}
2296+
return copy;
2297+
}
2298+
2299+
2300+
/**
2301+
@brief
2302+
Building clone for Item_ref
2303+
2304+
@param thd thread handle
2305+
@param mem_root part of the memory for the clone
2306+
2307+
@details
2308+
This method gets copy of the current item and also
2309+
builds clone for its reference.
2310+
2311+
@retval
2312+
clone of the item
2313+
0 if an error occured
2314+
*/
2315+
2316+
Item* Item_ref::build_clone(THD *thd, MEM_ROOT *mem_root)
2317+
{
2318+
Item_ref *copy= (Item_ref *) get_copy(thd, mem_root);
2319+
if (!copy)
2320+
return 0;
2321+
Item *item_clone= (* ref)->build_clone(thd, mem_root);
2322+
if (!item_clone)
2323+
return 0;
2324+
*copy->ref= item_clone;
2325+
return copy;
2326+
}
2327+
2328+
22612329
void Item_ident_for_show::make_field(THD *thd, Send_field *tmp_field)
22622330
{
22632331
tmp_field->table_name= tmp_field->org_table_name= table_name;
@@ -6708,6 +6776,85 @@ Item *Item_field::update_value_transformer(THD *thd, uchar *select_arg)
67086776
}
67096777

67106778

6779+
Item *Item_field::derived_field_transformer_for_having(THD *thd, uchar *arg)
6780+
{
6781+
st_select_lex *sl= (st_select_lex *)arg;
6782+
table_map map= sl->master_unit()->derived->table->map;
6783+
if (!((Item_field*)this)->item_equal)
6784+
{
6785+
if (used_tables() == map)
6786+
{
6787+
Item_ref *rf=
6788+
new (thd->mem_root) Item_ref(thd, &sl->context,
6789+
NullS, NullS,
6790+
((Item_field*) this)->field_name);
6791+
if (!rf)
6792+
return 0;
6793+
return rf;
6794+
}
6795+
}
6796+
else
6797+
{
6798+
Item_equal *cond= (Item_equal *) ((Item_field*)this)->item_equal;
6799+
Item_equal_fields_iterator li(*cond);
6800+
Item *item;
6801+
while ((item=li++))
6802+
{
6803+
if (item->used_tables() == map && item->type() == FIELD_ITEM)
6804+
{
6805+
Item_ref *rf=
6806+
new (thd->mem_root) Item_ref(thd, &sl->context,
6807+
NullS, NullS,
6808+
((Item_field*) item)->field_name);
6809+
if (!rf)
6810+
return 0;
6811+
return rf;
6812+
}
6813+
}
6814+
}
6815+
return this;
6816+
}
6817+
6818+
6819+
Item *Item_field::derived_field_transformer_for_where(THD *thd, uchar *arg)
6820+
{
6821+
st_select_lex *sl= (st_select_lex *)arg;
6822+
List_iterator<Grouping_tmp_field> li(sl->grouping_tmp_fields);
6823+
Grouping_tmp_field *field;
6824+
table_map map= sl->master_unit()->derived->table->map;
6825+
if (used_tables() == map)
6826+
{
6827+
while ((field=li++))
6828+
{
6829+
if (((Item_field*) this)->field == field->tmp_field)
6830+
return field->producing_item->build_clone(thd, thd->mem_root);
6831+
}
6832+
}
6833+
else if (((Item_field*)this)->item_equal)
6834+
{
6835+
Item_equal *cond= (Item_equal *) ((Item_field*)this)->item_equal;
6836+
Item_equal_fields_iterator it(*cond);
6837+
Item *item;
6838+
while ((item=it++))
6839+
{
6840+
if (item->used_tables() == map && item->type() == FIELD_ITEM)
6841+
{
6842+
Item_field *field_item= (Item_field *) item;
6843+
li.rewind();
6844+
while ((field=li++))
6845+
{
6846+
if (field_item->field == field->tmp_field)
6847+
{
6848+
return field->producing_item->build_clone(thd, thd->mem_root);
6849+
}
6850+
}
6851+
}
6852+
}
6853+
}
6854+
return this;
6855+
}
6856+
6857+
67116858
void Item_field::print(String *str, enum_query_type query_type)
67126859
{
67136860
if (field && field->table->const_table &&
@@ -9933,5 +10080,62 @@ const char *dbug_print_item(Item *item)
993310080
return "Couldn't fit into buffer";
993410081
}
993510082

10083+
993610084
#endif /*DBUG_OFF*/
993710085

10086+
bool Item_field::exclusive_dependence_on_table_processor(uchar *map)
10087+
{
10088+
table_map tab_map= *((table_map *) map);
10089+
return !((used_tables() == tab_map ||
10090+
(item_equal && item_equal->used_tables() & tab_map)));
10091+
}
10092+
10093+
bool Item_field::exclusive_dependence_on_grouping_fields_processor(uchar *arg)
10094+
{
10095+
st_select_lex *sl= (st_select_lex *)arg;
10096+
List_iterator<Grouping_tmp_field> li(sl->grouping_tmp_fields);
10097+
Grouping_tmp_field *field;
10098+
table_map map= sl->master_unit()->derived->table->map;
10099+
if (used_tables() == map)
10100+
{
10101+
while ((field=li++))
10102+
{
10103+
if (((Item_field*) this)->field == field->tmp_field)
10104+
return false;
10105+
}
10106+
}
10107+
else if (((Item_field*)this)->item_equal)
10108+
{
10109+
Item_equal *cond= (Item_equal *) ((Item_field*)this)->item_equal;
10110+
Item_equal_fields_iterator it(*cond);
10111+
Item *item;
10112+
while ((item=it++))
10113+
{
10114+
if (item->used_tables() == map && item->type() == FIELD_ITEM)
10115+
{
10116+
li.rewind();
10117+
while ((field=li++))
10118+
{
10119+
if (((Item_field *)item)->field == field->tmp_field)
10120+
return false;
10121+
}
10122+
}
10123+
}
10124+
}
10125+
return true;
10126+
}
10127+
10128+
10129+
/*Item *Item::get_copy(THD *thd, MEM_ROOT *mem_root)
10130+
{
10131+
dbug_print_item(this);
10132+
DBUG_ASSERT(0);
10133+
return 0;
10134+
}*/
10135+
10136+
10137+
void Item::register_in(THD *thd)
10138+
{
10139+
next= thd->free_list;
10140+
thd->free_list= this;
10141+
}

0 commit comments

Comments
 (0)