mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Bug#16630: The update fields of the INSERT .. SELECT .. ON DUPLICATE KEY
UPDATE contains wrong data if the SELECT employs a temporary table. If the UPDATE values of the INSERT .. SELECT .. ON DUPLICATE KEY UPDATE statement contains fields from the SELECT part and the select employs a temporary table then those fields will contain wrong values because they aren't corrected to get data from the temporary table. The solution is to add these fields to the selects all_fields list, to store pointers to those fields in the selects ref_pointer_array and to access them via Item_ref objects. The substitution for Item_ref objects is done in the new function called Item_field::update_value_transformer(). It is called through the item->transform() mechanism at the end of the select_insert::prepare() function.
This commit is contained in:
@ -2388,7 +2388,23 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
|
||||
next_name_resolution_table= ctx_state.save_next_local;
|
||||
}
|
||||
res= res || setup_fields(thd, 0, *info.update_values, 1, 0, 0);
|
||||
if (!res)
|
||||
{
|
||||
/*
|
||||
Traverse the update values list and substitute fields from the
|
||||
select for references (Item_ref objects) to them. This is done in
|
||||
order to get correct values from those fields when the select
|
||||
employs a temporary table.
|
||||
*/
|
||||
List_iterator<Item> li(*info.update_values);
|
||||
Item *item;
|
||||
|
||||
while ((item= li++))
|
||||
{
|
||||
item->transform(&Item::update_value_transformer,
|
||||
(byte*)lex->current_select);
|
||||
}
|
||||
}
|
||||
/* Restore the current context. */
|
||||
ctx_state.restore_state(context, table_list);
|
||||
}
|
||||
|
Reference in New Issue
Block a user