Skip to content

Commit eb2c147

Browse files
author
Galina Shalygina
committed
The consolidated patch for mdev-9197.
1 parent 8b94aec commit eb2c147

30 files changed

+8923
-13
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
@@ -479,6 +479,7 @@ Item::Item(THD *thd):
479479
}
480480
}
481481

482+
482483
/**
483484
Constructor used by Item_field, Item_ref & aggregate (sum)
484485
functions.
@@ -2161,6 +2162,73 @@ bool Item_func_or_sum::agg_item_set_converter(const DTCollation &coll,
21612162
}
21622163

21632164

2165+
/**
2166+
@brief
2167+
Building clone for Item_func_or_sum
2168+
2169+
@param thd thread handle
2170+
@param mem_root part of the memory for the clone
2171+
2172+
@details
2173+
This method gets copy of the current item and also
2174+
build clones for its referencies. For the referencies
2175+
build_copy is called again.
2176+
2177+
@retval
2178+
clone of the item
2179+
0 if an error occured
2180+
*/
2181+
2182+
Item* Item_func_or_sum::build_clone(THD *thd, MEM_ROOT *mem_root)
2183+
{
2184+
Item_func_or_sum *copy= (Item_func_or_sum *) get_copy(thd, mem_root);
2185+
if (!copy)
2186+
return 0;
2187+
if (arg_count > 2)
2188+
copy->args=
2189+
(Item**) alloc_root(mem_root, sizeof(Item*) * arg_count);
2190+
else if (arg_count > 0)
2191+
copy->args= copy->tmp_arg;
2192+
for (uint i= 0; i < arg_count; i++)
2193+
{
2194+
Item *arg_clone= args[i]->build_clone(thd, mem_root);
2195+
if (!arg_clone)
2196+
return 0;
2197+
copy->args[i]= arg_clone;
2198+
}
2199+
return copy;
2200+
}
2201+
2202+
2203+
/**
2204+
@brief
2205+
Building clone for Item_ref
2206+
2207+
@param thd thread handle
2208+
@param mem_root part of the memory for the clone
2209+
2210+
@details
2211+
This method gets copy of the current item and also
2212+
builds clone for its reference.
2213+
2214+
@retval
2215+
clone of the item
2216+
0 if an error occured
2217+
*/
2218+
2219+
Item* Item_ref::build_clone(THD *thd, MEM_ROOT *mem_root)
2220+
{
2221+
Item_ref *copy= (Item_ref *) get_copy(thd, mem_root);
2222+
if (!copy)
2223+
return 0;
2224+
Item *item_clone= (* ref)->build_clone(thd, mem_root);
2225+
if (!item_clone)
2226+
return 0;
2227+
*copy->ref= item_clone;
2228+
return copy;
2229+
}
2230+
2231+
21642232
void Item_ident_for_show::make_field(THD *thd, Send_field *tmp_field)
21652233
{
21662234
tmp_field->table_name= tmp_field->org_table_name= table_name;
@@ -6554,6 +6622,85 @@ Item *Item_field::update_value_transformer(THD *thd, uchar *select_arg)
65546622
}
65556623

65566624

6625+
Item *Item_field::derived_field_transformer_for_having(THD *thd, uchar *arg)
6626+
{
6627+
st_select_lex *sl= (st_select_lex *)arg;
6628+
table_map map= sl->master_unit()->derived->table->map;
6629+
if (!((Item_field*)this)->item_equal)
6630+
{
6631+
if (used_tables() == map)
6632+
{
6633+
Item_ref *rf=
6634+
new (thd->mem_root) Item_ref(thd, &sl->context,
6635+
NullS, NullS,
6636+
((Item_field*) this)->field_name);
6637+
if (!rf)
6638+
return 0;
6639+
return rf;
6640+
}
6641+
}
6642+
else
6643+
{
6644+
Item_equal *cond= (Item_equal *) ((Item_field*)this)->item_equal;
6645+
Item_equal_fields_iterator li(*cond);
6646+
Item *item;
6647+
while ((item=li++))
6648+
{
6649+
if (item->used_tables() == map && item->type() == FIELD_ITEM)
6650+
{
6651+
Item_ref *rf=
6652+
new (thd->mem_root) Item_ref(thd, &sl->context,
6653+
NullS, NullS,
6654+
((Item_field*) item)->field_name);
6655+
if (!rf)
6656+
return 0;
6657+
return rf;
6658+
}
6659+
}
6660+
}
6661+
return this;
6662+
}
6663+
6664+
6665+
Item *Item_field::derived_field_transformer_for_where(THD *thd, uchar *arg)
6666+
{
6667+
st_select_lex *sl= (st_select_lex *)arg;
6668+
List_iterator<Grouping_tmp_field> li(sl->grouping_tmp_fields);
6669+
Grouping_tmp_field *field;
6670+
table_map map= sl->master_unit()->derived->table->map;
6671+
if (used_tables() == map)
6672+
{
6673+
while ((field=li++))
6674+
{
6675+
if (((Item_field*) this)->field == field->tmp_field)
6676+
return field->producing_item->build_clone(thd, thd->mem_root);
6677+
}
6678+
}
6679+
else if (((Item_field*)this)->item_equal)
6680+
{
6681+
Item_equal *cond= (Item_equal *) ((Item_field*)this)->item_equal;
6682+
Item_equal_fields_iterator it(*cond);
6683+
Item *item;
6684+
while ((item=it++))
6685+
{
6686+
if (item->used_tables() == map && item->type() == FIELD_ITEM)
6687+
{
6688+
Item_field *field_item= (Item_field *) item;
6689+
li.rewind();
6690+
while ((field=li++))
6691+
{
6692+
if (field_item->field == field->tmp_field)
6693+
{
6694+
return field->producing_item->build_clone(thd, thd->mem_root);
6695+
}
6696+
}
6697+
}
6698+
}
6699+
}
6700+
return this;
6701+
}
6702+
6703+
65576704
void Item_field::print(String *str, enum_query_type query_type)
65586705
{
65596706
if (field && field->table->const_table)
@@ -9722,5 +9869,62 @@ const char *dbug_print_item(Item *item)
97229869
return "Couldn't fit into buffer";
97239870
}
97249871

9872+
97259873
#endif /*DBUG_OFF*/
97269874

9875+
bool Item_field::exclusive_dependence_on_table_processor(uchar *map)
9876+
{
9877+
table_map tab_map= *((table_map *) map);
9878+
return !((used_tables() == tab_map ||
9879+
(item_equal && item_equal->used_tables() & tab_map)));
9880+
}
9881+
9882+
bool Item_field::exclusive_dependence_on_grouping_fields_processor(uchar *arg)
9883+
{
9884+
st_select_lex *sl= (st_select_lex *)arg;
9885+
List_iterator<Grouping_tmp_field> li(sl->grouping_tmp_fields);
9886+
Grouping_tmp_field *field;
9887+
table_map map= sl->master_unit()->derived->table->map;
9888+
if (used_tables() == map)
9889+
{
9890+
while ((field=li++))
9891+
{
9892+
if (((Item_field*) this)->field == field->tmp_field)
9893+
return false;
9894+
}
9895+
}
9896+
else if (((Item_field*)this)->item_equal)
9897+
{
9898+
Item_equal *cond= (Item_equal *) ((Item_field*)this)->item_equal;
9899+
Item_equal_fields_iterator it(*cond);
9900+
Item *item;
9901+
while ((item=it++))
9902+
{
9903+
if (item->used_tables() == map && item->type() == FIELD_ITEM)
9904+
{
9905+
li.rewind();
9906+
while ((field=li++))
9907+
{
9908+
if (((Item_field *)item)->field == field->tmp_field)
9909+
return false;
9910+
}
9911+
}
9912+
}
9913+
}
9914+
return true;
9915+
}
9916+
9917+
9918+
/*Item *Item::get_copy(THD *thd, MEM_ROOT *mem_root)
9919+
{
9920+
dbug_print_item(this);
9921+
DBUG_ASSERT(0);
9922+
return 0;
9923+
}*/
9924+
9925+
9926+
void Item::register_in(THD *thd)
9927+
{
9928+
next= thd->free_list;
9929+
thd->free_list= this;
9930+
}

0 commit comments

Comments
 (0)