mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
sql_base.cc:
Fixed bug #12382. INSERT statement effectively changed thd->set_query_id to 0, while SELECT statement changed it to 0. As a result the insert_fields function that expanded '*' was called with different values of thd->set_query_id for the query SELECT * FROM view depending on whether it was run after an INSERT or after a SELECT statement. This was corrected by restoring the old value of thd->set_query_id when returning from the function setup_fields where possible reset could occur. If the value of thd->set_query_id == 0 then the fields substituted instead of '*' were not registered as used for bitmaps used_keys. This caused selection of an invalid execution plan for the query SELECT * from <view>. view.result, view.test: Added a test case for bug #12382. mysql-test/t/view.test: Added a test case for bug #12382. mysql-test/r/view.result: Added a test case for bug #12382. sql/sql_base.cc: Fixed bug #12382. INSERT statement effectively changed thd->set_query_id to 0, while SELECT statement changed it to 0. As a result the insert_fields function that expanded '*' was called with different values of thd->set_query_id for the query SELECT * FROM view depending on whether it was run after an INSERT or after a SELECT statement. This was corrected by restoring the old value of thd->set_query_id when returning from the function setup_fields where possible reset could occur. If the value of thd->set_query_id == 0 then the fields substituted instead of '*' were not registered as used for bitmaps used_keys. This caused selection of an invalid execution plan for the query SELECT * from <view>.
This commit is contained in:
@ -3181,6 +3181,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
|
||||
List<Item> *sum_func_list, bool allow_sum_func)
|
||||
{
|
||||
reg2 Item *item;
|
||||
bool save_set_query_id= thd->set_query_id;
|
||||
List_iterator<Item> it(fields);
|
||||
DBUG_ENTER("setup_fields");
|
||||
|
||||
@ -3208,6 +3209,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
|
||||
if (!item->fixed && item->fix_fields(thd, it.ref()) ||
|
||||
(item= *(it.ref()))->check_cols(1))
|
||||
{
|
||||
thd->set_query_id= save_set_query_id;
|
||||
DBUG_RETURN(TRUE); /* purecov: inspected */
|
||||
}
|
||||
if (ref)
|
||||
@ -3215,8 +3217,9 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
|
||||
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM &&
|
||||
sum_func_list)
|
||||
item->split_sum_func(thd, ref_pointer_array, *sum_func_list);
|
||||
thd->used_tables|=item->used_tables();
|
||||
thd->used_tables|= item->used_tables();
|
||||
}
|
||||
thd->set_query_id= save_set_query_id;
|
||||
DBUG_RETURN(test(thd->net.report_error));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user