MySQL 9.1.0
Source Code Documentation
replace_item.cc File Reference

Functions

static Itempossibly_outerize_replacement (Item *sub_item, Item *replacement)
 
static ItemFindReplacementItem (Item *item, const Func_ptr_array &items_to_copy, bool need_exact_match)
 Check what field the given item will be materialized into under the given temporary table parameters. More...
 
ItemFindReplacementOrReplaceMaterializedItems (THD *thd, Item *item, const Func_ptr_array &items_to_copy, bool need_exact_match, Func_ptr_array *agg_items_to_copy)
 
void ReplaceMaterializedItems (THD *thd, Item *item, const Func_ptr_array &items_to_copy, bool need_exact_match, bool window_frame_buffer)
 Like FindReplacementOrReplaceMaterializedItems, but only search below the item, ie. More...
 
ItemReplaceSetVarItem (THD *thd, Item *item, Item *new_item)
 Replace "@var:=<expr>" with "@var:=<tmp_table_column>" rather than "<tmp_table_column>". More...
 

Function Documentation

◆ FindReplacementItem()

static Item * FindReplacementItem ( Item item,
const Func_ptr_array items_to_copy,
bool  need_exact_match 
)
static

Check what field the given item will be materialized into under the given temporary table parameters.

If the item is materialized (ie., found in items_to_copy), we return a canonical Item_field for that field; ie., the same every time. This means that you can do the same replacement in a SELECT list and then in items_to_copy itself, and still have them match. This is used in particular when updating Temp_table_param itself, in FinalizePlanForQueryBlock().

Normally, we want to search for only the same item, up to references (need_exact_match=true). However, in ORDER BY specifications of windows, we can sometimes have the same field referred to by different Item_field, and the callers may need to set need_exact_match=false, which compares using Item::eq() instead. This also disables the behavior of checking and propagating Item::hidden.

◆ FindReplacementOrReplaceMaterializedItems()

Item * FindReplacementOrReplaceMaterializedItems ( THD thd,
Item item,
const Func_ptr_array items_to_copy,
bool  need_exact_match,
Func_ptr_array agg_items_to_copy 
)

◆ possibly_outerize_replacement()

static Item * possibly_outerize_replacement ( Item sub_item,
Item replacement 
)
static

◆ ReplaceMaterializedItems()

void ReplaceMaterializedItems ( THD thd,
Item item,
const Func_ptr_array items_to_copy,
bool  need_exact_match,
bool  window_frame_buffer = false 
)

Like FindReplacementOrReplaceMaterializedItems, but only search below the item, ie.

ignore point 2 above. This can be useful if doing self-replacement, ie., we are replacing source items in items_to_copy and don't want to replace an item with its own output.

◆ ReplaceSetVarItem()

Item * ReplaceSetVarItem ( THD thd,
Item item,
Item new_item 
)

Replace "@var:=<expr>" with "@var:=<tmp_table_column>" rather than "<tmp_table_column>".

If a join field such as "@var:=expr" points to a temp table field, the var assignment won't happen because there is no re-evaluation of the materialized field. . So, rather than returning the temp table field, return a new Item_func_set_user_var item that points to temp table field, so that "@var" gets updated.

(It's another thing that the temp table field itself is an Item_func_set_user_var field, i.e. of the form "@var:=<expr>", which means the var assignment redundantly happens for each temp table record while initializing the table; but this function does not fix that)

TODO: remove this function cf. deprecated setting of variable in expressions when it is finally disallowed.