mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Bug#34773: query with explain extended and derived table / other table
crashes server
When creating temporary table that contains aggregate functions a
non-reversible source transformation was performed to redirect aggregate
function arguments towards temporary table columns.
This caused EXPLAIN EXTENDED to fail because it was trying to resolve
references to the (freed) temporary table.
Fixed by preserving the original aggregate function arguments and
using them (instead of the transformed ones) for EXPLAIN EXTENDED.
mysql-test/r/explain.result:
Bug#34773: test case
mysql-test/t/explain.test:
Bug#34773: test case
sql/item.cc:
Bug#34773: use accessor functions instead of public members
sql/item_sum.cc:
Bug#34773:
- Encapsulate the arguments into Item_sum and
provide accessor and mutator methods
- print the orginal arguments (if present)
in EXPLAIN EXTENDED
- preserve the original arguments list.
sql/item_sum.h:
Bug#34773:
- Encapsulate the arguments into Item_sum and
provide accessor and mutator methods
- print the orginal arguments (if present)
in EXPLAIN EXTENDED
- preserve the original arguments list.
sql/opt_range.cc:
Bug#34773: use accessor functions instead of public members
sql/opt_sum.cc:
Bug#34773: use accessor functions instead of public members
sql/sql_select.cc:
Bug#34773: use accessor functions instead of public members
This commit is contained in:
@@ -9780,11 +9780,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
|
||||
}
|
||||
if (type == Item::SUM_FUNC_ITEM && !group && !save_sum_fields)
|
||||
{ /* Can't calc group yet */
|
||||
((Item_sum*) item)->result_field=0;
|
||||
for (i=0 ; i < ((Item_sum*) item)->arg_count ; i++)
|
||||
Item_sum *sum_item= (Item_sum *) item;
|
||||
sum_item->result_field=0;
|
||||
for (i=0 ; i < sum_item->get_arg_count() ; i++)
|
||||
{
|
||||
Item **argp= ((Item_sum*) item)->args + i;
|
||||
Item *arg= *argp;
|
||||
Item *arg= sum_item->get_arg(i);
|
||||
if (!arg->const_item())
|
||||
{
|
||||
Field *new_field=
|
||||
@@ -9812,7 +9812,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
|
||||
string_total_length+= new_field->pack_length();
|
||||
}
|
||||
thd->mem_root= mem_root_save;
|
||||
thd->change_item_tree(argp, new Item_field(new_field));
|
||||
arg= sum_item->set_arg(i, thd, new Item_field(new_field));
|
||||
thd->mem_root= &table->mem_root;
|
||||
if (!(new_field->flags & NOT_NULL_FLAG))
|
||||
{
|
||||
@@ -9821,7 +9821,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
|
||||
new_field->maybe_null() is still false, it will be
|
||||
changed below. But we have to setup Item_field correctly
|
||||
*/
|
||||
(*argp)->maybe_null=1;
|
||||
arg->maybe_null=1;
|
||||
}
|
||||
new_field->field_index= fieldnr++;
|
||||
}
|
||||
@@ -14491,9 +14491,9 @@ count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param,
|
||||
param->quick_group=0; // UDF SUM function
|
||||
param->sum_func_count++;
|
||||
|
||||
for (uint i=0 ; i < sum_item->arg_count ; i++)
|
||||
for (uint i=0 ; i < sum_item->get_arg_count() ; i++)
|
||||
{
|
||||
if (sum_item->args[0]->real_item()->type() == Item::FIELD_ITEM)
|
||||
if (sum_item->get_arg(i)->real_item()->type() == Item::FIELD_ITEM)
|
||||
param->field_count++;
|
||||
else
|
||||
param->func_count++;
|
||||
|
||||
Reference in New Issue
Block a user