Commit ab9b1461 authored by Igor Babaev's avatar Igor Babaev

MDEV-32225 Test case from opt_tvc.test fails with statement memory protection

Memory for type holders of the columns of a table value constructor must
be allocated only once.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
parent 1ee0d09a
...@@ -227,7 +227,7 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl, ...@@ -227,7 +227,7 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl,
List_item *first_elem= li++; List_item *first_elem= li++;
uint cnt= first_elem->elements; uint cnt= first_elem->elements;
Type_holder *holders; Type_holder *holders= type_holders;
if (cnt == 0) if (cnt == 0)
{ {
...@@ -238,12 +238,14 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl, ...@@ -238,12 +238,14 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl,
if (fix_fields_for_tvc(thd, li)) if (fix_fields_for_tvc(thd, li))
DBUG_RETURN(true); DBUG_RETURN(true);
if (!(holders= new (thd->stmt_arena->mem_root) Type_holder[cnt]) || if (!holders)
{
holders= type_holders= new (thd->stmt_arena->mem_root) Type_holder[cnt];
if (!holders ||
join_type_handlers_for_tvc(thd, li, holders, cnt) || join_type_handlers_for_tvc(thd, li, holders, cnt) ||
get_type_attributes_for_tvc(thd, li, holders, get_type_attributes_for_tvc(thd, li, holders,
lists_of_values.elements, cnt)) lists_of_values.elements, cnt))
DBUG_RETURN(true); DBUG_RETURN(true);
List_iterator_fast<Item> it(*first_elem); List_iterator_fast<Item> it(*first_elem);
Item *item; Item *item;
Query_arena *arena, backup; Query_arena *arena, backup;
...@@ -264,6 +266,7 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl, ...@@ -264,6 +266,7 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl,
if (unlikely(thd->is_fatal_error)) if (unlikely(thd->is_fatal_error))
DBUG_RETURN(true); // out of memory DBUG_RETURN(true); // out of memory
}
result= tmp_result; result= tmp_result;
......
...@@ -24,6 +24,7 @@ class Explain_query; ...@@ -24,6 +24,7 @@ class Explain_query;
class Item_func_in; class Item_func_in;
class st_select_lex_unit; class st_select_lex_unit;
typedef class st_select_lex SELECT_LEX; typedef class st_select_lex SELECT_LEX;
class Type_holder;
/** /**
@class table_value_constr @class table_value_constr
...@@ -38,6 +39,7 @@ class table_value_constr : public Sql_alloc ...@@ -38,6 +39,7 @@ class table_value_constr : public Sql_alloc
List<List_item> lists_of_values; List<List_item> lists_of_values;
select_result *result; select_result *result;
SELECT_LEX *select_lex; SELECT_LEX *select_lex;
Type_holder *type_holders;
enum { QEP_NOT_PRESENT_YET, QEP_AVAILABLE} have_query_plan; enum { QEP_NOT_PRESENT_YET, QEP_AVAILABLE} have_query_plan;
...@@ -46,7 +48,7 @@ class table_value_constr : public Sql_alloc ...@@ -46,7 +48,7 @@ class table_value_constr : public Sql_alloc
table_value_constr(List<List_item> tvc_values, SELECT_LEX *sl, table_value_constr(List<List_item> tvc_values, SELECT_LEX *sl,
ulonglong select_options_arg) : ulonglong select_options_arg) :
lists_of_values(tvc_values), result(0), select_lex(sl), lists_of_values(tvc_values), result(0), select_lex(sl), type_holders(0),
have_query_plan(QEP_NOT_PRESENT_YET), explain(0), have_query_plan(QEP_NOT_PRESENT_YET), explain(0),
select_options(select_options_arg) select_options(select_options_arg)
{ }; { };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment