- current_arena to stmt_arena: the thread may have more than one
'current' arenas: one for runtime data, and one for the parsed 
tree of a statement. Only one of them is active at any moment.
- set_item_arena -> set_query_arena, because Item_arena was renamed to 
Query_arena a while ago
- set_n_backup_item_arena -> set_n_backup_active_arena;
the active arena is the arena thd->mem_root and thd->free_list
are currently pointing at.
- restore_backup_item_arena -> restore_active_arena (with the same
rationale)
- change_arena_if_needed -> activate_stmt_arena_if_needed; this
method sets thd->stmt_arena active if it's not done yet.
This commit is contained in:
konstantin@mysql.com 2005-09-02 17:21:19 +04:00
parent b44b36bd1f
commit a3ddcdf8fb
20 changed files with 128 additions and 137 deletions

View File

@ -1296,7 +1296,7 @@ bool agg_item_charsets(DTCollation &coll, const char *fname,
In case we're in statement prepare, create conversion item In case we're in statement prepare, create conversion item
in its memory: it will be reused on each execute. in its memory: it will be reused on each execute.
*/ */
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
for (arg= args, last= args + nargs; arg < last; arg++) for (arg= args, last= args + nargs; arg < last; arg++)
{ {
@ -1342,7 +1342,7 @@ bool agg_item_charsets(DTCollation &coll, const char *fname,
conv->fix_fields(thd, arg); conv->fix_fields(thd, arg);
} }
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
return res; return res;
} }
@ -1385,7 +1385,7 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
structure can go away and pop up again between subsequent executions structure can go away and pop up again between subsequent executions
of a prepared statement). of a prepared statement).
*/ */
if (thd->current_arena->is_stmt_prepare_or_first_sp_execute()) if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
{ {
if (db_name) if (db_name)
orig_db_name= thd->strdup(db_name); orig_db_name= thd->strdup(db_name);

View File

@ -671,7 +671,7 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
If it is preparation PS only then we do not know values of parameters => If it is preparation PS only then we do not know values of parameters =>
cant't get there values and do not need that values. cant't get there values and do not need that values.
*/ */
if (!thd->current_arena->is_stmt_prepare()) if (!thd->stmt_arena->is_stmt_prepare())
cache->store(args[0]); cache->store(args[0]);
if (cache->cols() == 1) if (cache->cols() == 1)
{ {

View File

@ -1875,7 +1875,7 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref)
if (arg_count) if (arg_count)
{ // Only use argument once in query { // Only use argument once in query
/* /*
Allocate rand structure once: we must use thd->current_arena Allocate rand structure once: we must use thd->stmt_arena
to create rand in proper mem_root if it's a prepared statement or to create rand in proper mem_root if it's a prepared statement or
stored procedure. stored procedure.
@ -1883,7 +1883,7 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref)
as it will be replicated in the query as such. as it will be replicated in the query as such.
*/ */
if (!rand && !(rand= (struct rand_struct*) if (!rand && !(rand= (struct rand_struct*)
thd->current_arena->alloc(sizeof(*rand)))) thd->stmt_arena->alloc(sizeof(*rand))))
return TRUE; return TRUE;
/* /*
PARAM_ITEM is returned if we're in statement prepare and consequently PARAM_ITEM is returned if we're in statement prepare and consequently

View File

@ -333,7 +333,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
return RES_OK; return RES_OK;
SELECT_LEX *select_lex= join->select_lex; SELECT_LEX *select_lex= join->select_lex;
Query_arena *arena= thd->current_arena; Query_arena *arena= thd->stmt_arena;
if (!select_lex->master_unit()->first_select()->next_select() && if (!select_lex->master_unit()->first_select()->next_select() &&
!select_lex->table_list.elements && !select_lex->table_list.elements &&
@ -1287,10 +1287,10 @@ Item_in_subselect::select_in_like_transformer(JOIN *join, Comp_creator *func)
*/ */
if (!optimizer) if (!optimizer)
{ {
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
result= (!(optimizer= new Item_in_optimizer(left_expr, this))); result= (!(optimizer= new Item_in_optimizer(left_expr, this)));
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
if (result) if (result)
goto err; goto err;
} }
@ -1306,7 +1306,7 @@ Item_in_subselect::select_in_like_transformer(JOIN *join, Comp_creator *func)
goto err; goto err;
transformed= 1; transformed= 1;
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
/* /*
Both transformers call fix_fields() only for Items created inside them, Both transformers call fix_fields() only for Items created inside them,
and all that items do not make permanent changes in current item arena and all that items do not make permanent changes in current item arena
@ -1322,14 +1322,14 @@ Item_in_subselect::select_in_like_transformer(JOIN *join, Comp_creator *func)
if (func != &eq_creator) if (func != &eq_creator)
{ {
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
my_error(ER_OPERAND_COLUMNS, MYF(0), 1); my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
DBUG_RETURN(RES_ERROR); DBUG_RETURN(RES_ERROR);
} }
res= row_value_transformer(join); res= row_value_transformer(join);
} }
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
err: err:
thd->where= save_where; thd->where= save_where;
DBUG_RETURN(res); DBUG_RETURN(res);

View File

@ -26,7 +26,6 @@ class JOIN;
class select_subselect; class select_subselect;
class subselect_engine; class subselect_engine;
class Item_bool_func2; class Item_bool_func2;
class Item_arena;
/* base class for subselects */ /* base class for subselects */

View File

@ -23,8 +23,6 @@
#include <my_tree.h> #include <my_tree.h>
class Item_arena;
class Item_sum :public Item_result_field class Item_sum :public Item_result_field
{ {
public: public:

View File

@ -408,7 +408,6 @@ enum enum_parsing_place
struct st_table; struct st_table;
class THD; class THD;
class Item_arena;
/* Struct to handle simple linked lists */ /* Struct to handle simple linked lists */

View File

@ -1338,7 +1338,7 @@ static void sp_update_stmt_used_routines(THD *thd, LEX *lex, HASH *src)
for (uint i=0 ; i < src->records ; i++) for (uint i=0 ; i < src->records ; i++)
{ {
Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i); Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i);
(void)add_used_routine(lex, thd->current_arena, &rt->key); (void)add_used_routine(lex, thd->stmt_arena, &rt->key);
} }
} }
@ -1485,7 +1485,7 @@ void
sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex, sp_cache_routines_and_add_tables_for_triggers(THD *thd, LEX *lex,
Table_triggers_list *triggers) Table_triggers_list *triggers)
{ {
if (add_used_routine(lex, thd->current_arena, &triggers->sroutines_key)) if (add_used_routine(lex, thd->stmt_arena, &triggers->sroutines_key))
{ {
Sroutine_hash_entry **last_cached_routine_ptr= Sroutine_hash_entry **last_cached_routine_ptr=
(Sroutine_hash_entry **)lex->sroutines_list.next; (Sroutine_hash_entry **)lex->sroutines_list.next;

View File

@ -131,12 +131,12 @@ sp_prepare_func_item(THD* thd, Item **it_addr)
do \ do \
{ \ { \
if (condition) \ if (condition) \
thd->set_n_backup_item_arena(thd->spcont->callers_arena, \ thd->set_n_backup_active_arena(thd->spcont->callers_arena, \
backup_arena); \ backup_arena); \
new_command; \ new_command; \
if (condition) \ if (condition) \
thd->restore_backup_item_arena(thd->spcont->callers_arena, \ thd->restore_active_arena(thd->spcont->callers_arena, \
&backup_current_arena); \ backup_arena); \
} while(0) } while(0)
/* /*
@ -167,7 +167,7 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type,
DBUG_ENTER("sp_eval_func_item"); DBUG_ENTER("sp_eval_func_item");
Item *it= sp_prepare_func_item(thd, it_addr); Item *it= sp_prepare_func_item(thd, it_addr);
uint rsize; uint rsize;
Query_arena backup_current_arena; Query_arena backup_arena;
DBUG_PRINT("info", ("type: %d", type)); DBUG_PRINT("info", ("type: %d", type));
if (!it) if (!it)
@ -187,7 +187,7 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type,
} }
DBUG_PRINT("info", ("INT_RESULT: %d", i)); DBUG_PRINT("info", ("INT_RESULT: %d", i));
CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_int(i), CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_int(i),
use_callers_arena, &backup_current_arena); use_callers_arena, &backup_arena);
break; break;
} }
case REAL_RESULT: case REAL_RESULT:
@ -210,7 +210,7 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type,
max_length= it->max_length; max_length= it->max_length;
DBUG_PRINT("info", ("REAL_RESULT: %g", d)); DBUG_PRINT("info", ("REAL_RESULT: %g", d));
CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_float(d), CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_float(d),
use_callers_arena, &backup_current_arena); use_callers_arena, &backup_arena);
it->decimals= decimals; it->decimals= decimals;
it->max_length= max_length; it->max_length= max_length;
break; break;
@ -221,7 +221,7 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type,
if (it->null_value) if (it->null_value)
goto return_null_item; goto return_null_item;
CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_decimal(val), CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_decimal(val),
use_callers_arena, &backup_current_arena); use_callers_arena, &backup_arena);
#ifndef DBUG_OFF #ifndef DBUG_OFF
{ {
char dbug_buff[DECIMAL_MAX_STR_LENGTH+1]; char dbug_buff[DECIMAL_MAX_STR_LENGTH+1];
@ -246,7 +246,7 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type,
s->length(), s->c_ptr_quick())); s->length(), s->c_ptr_quick()));
CHARSET_INFO *itcs= it->collation.collation; CHARSET_INFO *itcs= it->collation.collation;
CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_string(itcs), CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_string(itcs),
use_callers_arena, &backup_current_arena); use_callers_arena, &backup_arena);
/* /*
We have to use special constructor and allocate string We have to use special constructor and allocate string
on system heap here. This is because usual Item_string on system heap here. This is because usual Item_string
@ -276,7 +276,7 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type,
return_null_item: return_null_item:
CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_null(), CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) Item_null(),
use_callers_arena, &backup_current_arena); use_callers_arena, &backup_arena);
it->rsize= rsize; it->rsize= rsize;
DBUG_RETURN(it); DBUG_RETURN(it);
@ -765,7 +765,7 @@ int sp_head::execute(THD *thd)
/* per-instruction arena */ /* per-instruction arena */
MEM_ROOT execute_mem_root; MEM_ROOT execute_mem_root;
Query_arena execute_arena(&execute_mem_root, INITIALIZED_FOR_SP), Query_arena execute_arena(&execute_mem_root, INITIALIZED_FOR_SP),
execute_backup_arena; backup_arena;
query_id_t old_query_id; query_id_t old_query_id;
TABLE *old_derived_tables; TABLE *old_derived_tables;
LEX *old_lex; LEX *old_lex;
@ -812,7 +812,7 @@ int sp_head::execute(THD *thd)
if ((ctx= thd->spcont)) if ((ctx= thd->spcont))
ctx->clear_handler(); ctx->clear_handler();
thd->query_error= 0; thd->query_error= 0;
old_arena= thd->current_arena; old_arena= thd->stmt_arena;
/* /*
We have to save/restore this info when we are changing call level to We have to save/restore this info when we are changing call level to
@ -848,13 +848,13 @@ int sp_head::execute(THD *thd)
Switch to per-instruction arena here. We can do it since we cleanup Switch to per-instruction arena here. We can do it since we cleanup
arena after every instruction. arena after every instruction.
*/ */
thd->set_n_backup_item_arena(&execute_arena, &execute_backup_arena); thd->set_n_backup_active_arena(&execute_arena, &backup_arena);
/* /*
Save callers arena in order to store instruction results and out Save callers arena in order to store instruction results and out
parameters in it later during sp_eval_func_item() parameters in it later during sp_eval_func_item()
*/ */
thd->spcont->callers_arena= &execute_backup_arena; thd->spcont->callers_arena= &backup_arena;
do do
{ {
@ -869,12 +869,12 @@ int sp_head::execute(THD *thd)
if (!thd->in_sub_stmt) if (!thd->in_sub_stmt)
thd->set_time(); // Make current_time() et al work thd->set_time(); // Make current_time() et al work
/* /*
We have to set thd->current_arena before executing the instruction We have to set thd->stmt_arena before executing the instruction
to store in the instruction free_list all new items, created to store in the instruction free_list all new items, created
during the first execution (for example expanding of '*' or the during the first execution (for example expanding of '*' or the
items made during other permanent subquery transformations). items made during other permanent subquery transformations).
*/ */
thd->current_arena= i; thd->stmt_arena= i;
ret= i->execute(thd, &ip); ret= i->execute(thd, &ip);
/* /*
@ -907,9 +907,9 @@ int sp_head::execute(THD *thd)
case SP_HANDLER_NONE: case SP_HANDLER_NONE:
break; break;
case SP_HANDLER_CONTINUE: case SP_HANDLER_CONTINUE:
thd->restore_backup_item_arena(&execute_arena, &execute_backup_arena); thd->restore_active_arena(&execute_arena, &backup_arena);
ctx->save_variables(hf); ctx->save_variables(hf);
thd->set_n_backup_item_arena(&execute_arena, &execute_backup_arena); thd->set_n_backup_active_arena(&execute_arena, &backup_arena);
ctx->push_hstack(ip); ctx->push_hstack(ip);
// Fall through // Fall through
default: default:
@ -924,7 +924,7 @@ int sp_head::execute(THD *thd)
} }
} while (ret == 0 && !thd->killed); } while (ret == 0 && !thd->killed);
thd->restore_backup_item_arena(&execute_arena, &execute_backup_arena); thd->restore_active_arena(&execute_arena, &backup_arena);
/* Restore all saved */ /* Restore all saved */
@ -939,7 +939,7 @@ int sp_head::execute(THD *thd)
thd->derived_tables= old_derived_tables; thd->derived_tables= old_derived_tables;
thd->variables.sql_mode= save_sql_mode; thd->variables.sql_mode= save_sql_mode;
thd->current_arena= old_arena; thd->stmt_arena= old_arena;
state= EXECUTED; state= EXECUTED;
done: done:
@ -1532,7 +1532,7 @@ sp_head::restore_thd_mem_root(THD *thd)
{ {
DBUG_ENTER("sp_head::restore_thd_mem_root"); DBUG_ENTER("sp_head::restore_thd_mem_root");
Item *flist= free_list; // The old list Item *flist= free_list; // The old list
set_item_arena(thd); // Get new free_list and mem_root set_query_arena(thd); // Get new free_list and mem_root
state= INITIALIZED_FOR_SP; state= INITIALIZED_FOR_SP;
DBUG_PRINT("info", ("mem_root 0x%lx returned from thd mem root 0x%lx", DBUG_PRINT("info", ("mem_root 0x%lx returned from thd mem root 0x%lx",
@ -2359,20 +2359,18 @@ sp_instr_hreturn::opt_mark(sp_head *sp)
int int
sp_instr_cpush::execute(THD *thd, uint *nextp) sp_instr_cpush::execute(THD *thd, uint *nextp)
{ {
Query_arena backup_current_arena; Query_arena backup_arena;
DBUG_ENTER("sp_instr_cpush::execute"); DBUG_ENTER("sp_instr_cpush::execute");
/* /*
We should create cursors in the callers arena, as We should create cursors in the callers arena, as
it could be (and usually is) used in several instructions. it could be (and usually is) used in several instructions.
*/ */
thd->set_n_backup_item_arena(thd->spcont->callers_arena, thd->set_n_backup_active_arena(thd->spcont->callers_arena, &backup_arena);
&backup_current_arena);
thd->spcont->push_cursor(&m_lex_keeper, this); thd->spcont->push_cursor(&m_lex_keeper, this);
thd->restore_backup_item_arena(thd->spcont->callers_arena, thd->restore_active_arena(thd->spcont->callers_arena, &backup_arena);
&backup_current_arena);
*nextp= m_ip+1; *nextp= m_ip+1;
@ -2439,19 +2437,19 @@ sp_instr_copen::execute(THD *thd, uint *nextp)
} }
else else
{ {
Query_arena *old_arena= thd->current_arena; Query_arena *old_arena= thd->stmt_arena;
/* /*
Get the Query_arena from the cpush instruction, which contains Get the Query_arena from the cpush instruction, which contains
the free_list of the query, so new items (if any) are stored in the free_list of the query, so new items (if any) are stored in
the right free_list, and we can cleanup after each open. the right free_list, and we can cleanup after each open.
*/ */
thd->current_arena= c->get_instr(); thd->stmt_arena= c->get_instr();
res= lex_keeper->reset_lex_and_exec_core(thd, nextp, FALSE, this); res= lex_keeper->reset_lex_and_exec_core(thd, nextp, FALSE, this);
/* Cleanup the query's items */ /* Cleanup the query's items */
if (thd->current_arena->free_list) if (thd->stmt_arena->free_list)
cleanup_items(thd->current_arena->free_list); cleanup_items(thd->stmt_arena->free_list);
thd->current_arena= old_arena; thd->stmt_arena= old_arena;
/* /*
Work around the fact that errors in selects are not returned properly Work around the fact that errors in selects are not returned properly
(but instead converted into a warning), so if a condition handler (but instead converted into a warning), so if a condition handler
@ -2526,18 +2524,16 @@ sp_instr_cfetch::execute(THD *thd, uint *nextp)
{ {
sp_cursor *c= thd->spcont->get_cursor(m_cursor); sp_cursor *c= thd->spcont->get_cursor(m_cursor);
int res; int res;
Query_arena backup_current_arena; Query_arena backup_arena;
DBUG_ENTER("sp_instr_cfetch::execute"); DBUG_ENTER("sp_instr_cfetch::execute");
if (! c) if (! c)
res= -1; res= -1;
else else
{ {
thd->set_n_backup_item_arena(thd->spcont->callers_arena, thd->set_n_backup_active_arena(thd->spcont->callers_arena, &backup_arena);
&backup_current_arena);
res= c->fetch(thd, &m_varlist); res= c->fetch(thd, &m_varlist);
thd->restore_backup_item_arena(thd->spcont->callers_arena, thd->restore_active_arena(thd->spcont->callers_arena, &backup_arena);
&backup_current_arena);
} }
*nextp= m_ip+1; *nextp= m_ip+1;
@ -2790,7 +2786,7 @@ sp_head::add_used_tables_to_table_list(THD *thd,
/* /*
Use persistent arena for table list allocation to be PS friendly. Use persistent arena for table list allocation to be PS friendly.
*/ */
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
for (i=0 ; i < m_sptabs.records ; i++) for (i=0 ; i < m_sptabs.records ; i++)
{ {
@ -2835,7 +2831,7 @@ sp_head::add_used_tables_to_table_list(THD *thd,
} }
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
DBUG_RETURN(result); DBUG_RETURN(result);
} }

View File

@ -3422,7 +3422,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
table_ref_1->alias, table_ref_2->alias)); table_ref_1->alias, table_ref_2->alias));
*found_using_fields= 0; *found_using_fields= 0;
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
/* /*
TABLE_LIST::join_columns could be allocated by the previous call to TABLE_LIST::join_columns could be allocated by the previous call to
@ -3585,7 +3585,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
err: err:
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
DBUG_RETURN(result); DBUG_RETURN(result);
} }
@ -3643,7 +3643,7 @@ store_natural_using_join_columns(THD *thd, TABLE_LIST *natural_using_join,
DBUG_ASSERT(!natural_using_join->join_columns); DBUG_ASSERT(!natural_using_join->join_columns);
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
if (!(non_join_columns= new List<Natural_join_column>) || if (!(non_join_columns= new List<Natural_join_column>) ||
!(natural_using_join->join_columns= new List<Natural_join_column>)) !(natural_using_join->join_columns= new List<Natural_join_column>))
@ -3728,7 +3728,7 @@ store_natural_using_join_columns(THD *thd, TABLE_LIST *natural_using_join,
err: err:
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
DBUG_RETURN(result); DBUG_RETURN(result);
} }
@ -3773,7 +3773,7 @@ store_top_level_join_columns(THD *thd, TABLE_LIST *table_ref,
DBUG_ENTER("store_top_level_join_columns"); DBUG_ENTER("store_top_level_join_columns");
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
/* Call the procedure recursively for each nested table reference. */ /* Call the procedure recursively for each nested table reference. */
if (table_ref->nested_join) if (table_ref->nested_join)
@ -3886,7 +3886,7 @@ store_top_level_join_columns(THD *thd, TABLE_LIST *table_ref,
err: err:
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
DBUG_RETURN(result); DBUG_RETURN(result);
} }
@ -3985,7 +3985,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
Don't use arena if we are not in prepared statements or stored procedures Don't use arena if we are not in prepared statements or stored procedures
For PS/SP we have to use arena to remember the changes For PS/SP we have to use arena to remember the changes
*/ */
arena= thd->change_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
while (wild_num && (item= it++)) while (wild_num && (item= it++))
{ {
@ -4013,7 +4013,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
any_privileges)) any_privileges))
{ {
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
if (sum_func_list) if (sum_func_list)
@ -4035,7 +4035,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
select_lex->with_wild= 0; select_lex->with_wild= 0;
select_lex->item_list= fields; select_lex->item_list= fields;
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@ -4213,15 +4213,15 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
if (table_list->ancestor) if (table_list->ancestor)
{ {
DBUG_ASSERT(table_list->view); DBUG_ASSERT(table_list->view);
Query_arena *arena= thd->current_arena, backup; Query_arena *arena= thd->stmt_arena, backup;
bool res; bool res;
if (arena->is_conventional()) if (arena->is_conventional())
arena= 0; // For easier test arena= 0; // For easier test
else else
thd->set_n_backup_item_arena(arena, &backup); thd->set_n_backup_active_arena(arena, &backup);
res= table_list->setup_ancestor(thd); res= table_list->setup_ancestor(thd);
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
if (res) if (res)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
@ -4302,7 +4302,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
bool found; bool found;
char name_buff[NAME_LEN+1]; char name_buff[NAME_LEN+1];
DBUG_ENTER("insert_fields"); DBUG_ENTER("insert_fields");
DBUG_PRINT("arena", ("current arena: 0x%lx", (ulong)thd->current_arena)); DBUG_PRINT("arena", ("stmt arena: 0x%lx", (ulong)thd->stmt_arena));
if (db_name && lower_case_table_names) if (db_name && lower_case_table_names)
{ {
@ -4508,7 +4508,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
COND **conds) COND **conds)
{ {
SELECT_LEX *select_lex= thd->lex->current_select; SELECT_LEX *select_lex= thd->lex->current_select;
Query_arena *arena= thd->current_arena, backup; Query_arena *arena= thd->stmt_arena, backup;
TABLE_LIST *table= NULL; // For HP compilers TABLE_LIST *table= NULL; // For HP compilers
/* /*
it_is_update set to TRUE when tables of primary SELECT_LEX (SELECT_LEX it_is_update set to TRUE when tables of primary SELECT_LEX (SELECT_LEX
@ -4584,7 +4584,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
} }
} }
if (!thd->current_arena->is_conventional()) if (!thd->stmt_arena->is_conventional())
{ {
/* /*
We are in prepared statement preparation code => we should store We are in prepared statement preparation code => we should store
@ -4599,7 +4599,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
err: err:
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
err_no_arena: err_no_arena:
DBUG_RETURN(1); DBUG_RETURN(1);
} }

View File

@ -180,7 +180,7 @@ THD::THD()
in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE), in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE),
spcont(NULL) spcont(NULL)
{ {
current_arena= this; stmt_arena= this;
host= user= priv_user= db= ip= 0; host= user= priv_user= db= ip= 0;
catalog= (char*)"std"; // the only catalog we have for now catalog= (char*)"std"; // the only catalog we have for now
host_or_ip= "connecting host"; host_or_ip= "connecting host";
@ -794,7 +794,7 @@ struct Item_change_record: public ilink
/* /*
Register an item tree tree transformation, performed by the query Register an item tree tree transformation, performed by the query
optimizer. We need a pointer to runtime_memroot because it may be != optimizer. We need a pointer to runtime_memroot because it may be !=
thd->mem_root (due to possible set_n_backup_item_arena called for thd). thd->mem_root (due to possible set_n_backup_active_arena called for thd).
*/ */
void THD::nocheck_register_item_tree_change(Item **place, Item *old_value, void THD::nocheck_register_item_tree_change(Item **place, Item *old_value,
@ -1602,13 +1602,13 @@ void THD::end_statement()
} }
void Query_arena::set_n_backup_item_arena(Query_arena *set, Query_arena *backup) void THD::set_n_backup_active_arena(Query_arena *set, Query_arena *backup)
{ {
DBUG_ENTER("Query_arena::set_n_backup_item_arena"); DBUG_ENTER("THD::set_n_backup_active_arena");
DBUG_ASSERT(backup->is_backup_arena == FALSE); DBUG_ASSERT(backup->is_backup_arena == FALSE);
backup->set_item_arena(this); backup->set_query_arena(this);
set_item_arena(set); set_query_arena(set);
#ifndef DBUG_OFF #ifndef DBUG_OFF
backup->is_backup_arena= TRUE; backup->is_backup_arena= TRUE;
#endif #endif
@ -1616,19 +1616,19 @@ void Query_arena::set_n_backup_item_arena(Query_arena *set, Query_arena *backup)
} }
void Query_arena::restore_backup_item_arena(Query_arena *set, Query_arena *backup) void THD::restore_active_arena(Query_arena *set, Query_arena *backup)
{ {
DBUG_ENTER("Query_arena::restore_backup_item_arena"); DBUG_ENTER("THD::restore_active_arena");
DBUG_ASSERT(backup->is_backup_arena); DBUG_ASSERT(backup->is_backup_arena);
set->set_item_arena(this); set->set_query_arena(this);
set_item_arena(backup); set_query_arena(backup);
#ifndef DBUG_OFF #ifndef DBUG_OFF
backup->is_backup_arena= FALSE; backup->is_backup_arena= FALSE;
#endif #endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
void Query_arena::set_item_arena(Query_arena *set) void Query_arena::set_query_arena(Query_arena *set)
{ {
mem_root= set->mem_root; mem_root= set->mem_root;
free_list= set->free_list; free_list= set->free_list;

View File

@ -733,9 +733,7 @@ public:
return ptr; return ptr;
} }
void set_n_backup_item_arena(Query_arena *set, Query_arena *backup); void set_query_arena(Query_arena *set);
void restore_backup_item_arena(Query_arena *set, Query_arena *backup);
void set_item_arena(Query_arena *set);
void free_items(); void free_items();
}; };
@ -1230,16 +1228,16 @@ public:
/* /*
A permanent memory area of the statement. For conventional A permanent memory area of the statement. For conventional
execution, the parsed tree and execution runtime reside in the same execution, the parsed tree and execution runtime reside in the same
memory root. In this case current_arena points to THD. In case of memory root. In this case stmt_arena points to THD. In case of
a prepared statement or a stored procedure statement, thd->mem_root a prepared statement or a stored procedure statement, thd->mem_root
conventionally points to runtime memory, and thd->current_arena conventionally points to runtime memory, and thd->stmt_arena
points to the memory of the PS/SP, where the parsed tree of the points to the memory of the PS/SP, where the parsed tree of the
statement resides. Whenever you need to perform a permanent statement resides. Whenever you need to perform a permanent
transformation of a parsed tree, you should allocate new memory in transformation of a parsed tree, you should allocate new memory in
current_arena, to allow correct re-execution of PS/SP. stmt_arena, to allow correct re-execution of PS/SP.
Note: in the parser, current_arena == thd, even for PS/SP. Note: in the parser, stmt_arena == thd, even for PS/SP.
*/ */
Query_arena *current_arena; Query_arena *stmt_arena;
/* /*
next_insert_id is set on SET INSERT_ID= #. This is used as the next next_insert_id is set on SET INSERT_ID= #. This is used as the next
generated auto_increment value in handler.cc generated auto_increment value in handler.cc
@ -1467,7 +1465,7 @@ public:
} }
inline bool fill_derived_tables() inline bool fill_derived_tables()
{ {
return !current_arena->is_stmt_prepare() && !lex->only_view_structure(); return !stmt_arena->is_stmt_prepare() && !lex->only_view_structure();
} }
inline gptr trans_alloc(unsigned int size) inline gptr trans_alloc(unsigned int size)
{ {
@ -1506,17 +1504,16 @@ public:
inline CHARSET_INFO *charset() { return variables.character_set_client; } inline CHARSET_INFO *charset() { return variables.character_set_client; }
void update_charset(); void update_charset();
inline Query_arena *change_arena_if_needed(Query_arena *backup) inline Query_arena *activate_stmt_arena_if_needed(Query_arena *backup)
{ {
/* /*
use new arena if we are in a prepared statements and we have not Use the persistent arena if we are in a prepared statement or a stored
already changed to use this arena. procedure statement and we have not already changed to use this arena.
*/ */
if (!current_arena->is_conventional() && if (!stmt_arena->is_conventional() && mem_root != stmt_arena->mem_root)
mem_root != current_arena->mem_root)
{ {
set_n_backup_item_arena(current_arena, backup); set_n_backup_active_arena(stmt_arena, backup);
return current_arena; return stmt_arena;
} }
return 0; return 0;
} }
@ -1524,7 +1521,7 @@ public:
void change_item_tree(Item **place, Item *new_value) void change_item_tree(Item **place, Item *new_value)
{ {
/* TODO: check for OOM condition here */ /* TODO: check for OOM condition here */
if (!current_arena->is_conventional()) if (!stmt_arena->is_conventional())
nocheck_register_item_tree_change(place, *place, mem_root); nocheck_register_item_tree_change(place, *place, mem_root);
*place= new_value; *place= new_value;
} }
@ -1556,11 +1553,13 @@ public:
} }
void set_status_var_init(); void set_status_var_init();
bool is_context_analysis_only() bool is_context_analysis_only()
{ return current_arena->is_stmt_prepare() || lex->view_prepare_mode; } { return stmt_arena->is_stmt_prepare() || lex->view_prepare_mode; }
void reset_n_backup_open_tables_state(Open_tables_state *backup); void reset_n_backup_open_tables_state(Open_tables_state *backup);
void restore_backup_open_tables_state(Open_tables_state *backup); void restore_backup_open_tables_state(Open_tables_state *backup);
void reset_sub_statement_state(Sub_statement_state *backup, uint new_state); void reset_sub_statement_state(Sub_statement_state *backup, uint new_state);
void restore_sub_statement_state(Sub_statement_state *backup); void restore_sub_statement_state(Sub_statement_state *backup);
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
void restore_active_arena(Query_arena *set, Query_arena *backup);
}; };

View File

@ -1504,7 +1504,7 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
We have to create array in prepared statement memory if it is We have to create array in prepared statement memory if it is
prepared statement prepared statement
*/ */
Query_arena *arena= thd->current_arena; Query_arena *arena= thd->stmt_arena;
return (ref_pointer_array= return (ref_pointer_array=
(Item **)arena->alloc(sizeof(Item*) * (Item **)arena->alloc(sizeof(Item*) *
(item_list.elements + (item_list.elements +
@ -1826,7 +1826,7 @@ void st_select_lex_unit::set_limit(SELECT_LEX *sl)
{ {
ha_rows select_limit_val; ha_rows select_limit_val;
DBUG_ASSERT(! thd->current_arena->is_stmt_prepare()); DBUG_ASSERT(! thd->stmt_arena->is_stmt_prepare());
select_limit_val= (ha_rows)(sl->select_limit ? sl->select_limit->val_uint() : select_limit_val= (ha_rows)(sl->select_limit ? sl->select_limit->val_uint() :
HA_POS_ERROR); HA_POS_ERROR);
offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() : offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
@ -2038,7 +2038,7 @@ void st_lex::cleanup_after_one_table_open()
void st_select_lex::fix_prepare_information(THD *thd, Item **conds) void st_select_lex::fix_prepare_information(THD *thd, Item **conds)
{ {
if (!thd->current_arena->is_conventional() && first_execution) if (!thd->stmt_arena->is_conventional() && first_execution)
{ {
first_execution= 0; first_execution= 0;
if (*conds) if (*conds)

View File

@ -5275,7 +5275,7 @@ mysql_new_select(LEX *lex, bool move_down)
it's a constant one. The flag is switched off in the end of it's a constant one. The flag is switched off in the end of
mysql_stmt_prepare. mysql_stmt_prepare.
*/ */
if (thd->current_arena->is_stmt_prepare()) if (thd->stmt_arena->is_stmt_prepare())
select_lex->uncacheable|= UNCACHEABLE_PREPARE; select_lex->uncacheable|= UNCACHEABLE_PREPARE;
if (move_down) if (move_down)
{ {
@ -6081,7 +6081,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
ptr->db= empty_c_string; ptr->db= empty_c_string;
ptr->db_length= 0; ptr->db_length= 0;
} }
if (thd->current_arena->is_stmt_prepare_or_first_sp_execute()) if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
ptr->db= thd->strdup(ptr->db); ptr->db= thd->strdup(ptr->db);
ptr->alias= alias_str; ptr->alias= alias_str;
@ -7301,7 +7301,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
against the opened tables to ensure we don't use a table that is part against the opened tables to ensure we don't use a table that is part
of the view (which can only be done after the table has been opened). of the view (which can only be done after the table has been opened).
*/ */
if (thd->current_arena->is_stmt_prepare_or_first_sp_execute()) if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
{ {
/* /*
For temporary tables we don't have to check if the created table exists For temporary tables we don't have to check if the created table exists

View File

@ -1767,12 +1767,12 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
both of backup_statement() and backup_item_area() here. both of backup_statement() and backup_item_area() here.
*/ */
thd->set_n_backup_statement(stmt, &stmt_backup); thd->set_n_backup_statement(stmt, &stmt_backup);
thd->set_n_backup_item_arena(stmt, &stmt_backup); thd->set_n_backup_active_arena(stmt, &stmt_backup);
if (alloc_query(thd, packet, packet_length)) if (alloc_query(thd, packet, packet_length))
{ {
thd->restore_backup_statement(stmt, &stmt_backup); thd->restore_backup_statement(stmt, &stmt_backup);
thd->restore_backup_item_arena(stmt, &stmt_backup); thd->restore_active_arena(stmt, &stmt_backup);
/* Statement map deletes statement on erase */ /* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt); thd->stmt_map.erase(stmt);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
@ -1780,7 +1780,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
mysql_log.write(thd, thd->command, "[%lu] %s", stmt->id, packet); mysql_log.write(thd, thd->command, "[%lu] %s", stmt->id, packet);
thd->current_arena= stmt; thd->stmt_arena= stmt;
mysql_init_query(thd, (uchar *) thd->query, thd->query_length); mysql_init_query(thd, (uchar *) thd->query, thd->query_length);
/* Reset warnings from previous command */ /* Reset warnings from previous command */
mysql_reset_errors(thd, 0); mysql_reset_errors(thd, 0);
@ -1800,7 +1800,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
transformation can be reused on execute, we set again thd->mem_root from transformation can be reused on execute, we set again thd->mem_root from
stmt->mem_root (see setup_wild for one place where we do that). stmt->mem_root (see setup_wild for one place where we do that).
*/ */
thd->restore_backup_item_arena(stmt, &stmt_backup); thd->restore_active_arena(stmt, &stmt_backup);
if (!error) if (!error)
error= check_prepared_statement(stmt, test(name)); error= check_prepared_statement(stmt, test(name));
@ -1817,7 +1817,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
close_thread_tables(thd); close_thread_tables(thd);
cleanup_stmt_and_thd_after_use(stmt, thd); cleanup_stmt_and_thd_after_use(stmt, thd);
thd->restore_backup_statement(stmt, &stmt_backup); thd->restore_backup_statement(stmt, &stmt_backup);
thd->current_arena= thd; thd->stmt_arena= thd;
if (error) if (error)
{ {
@ -2063,7 +2063,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
goto set_params_data_err; goto set_params_data_err;
#endif #endif
thd->set_n_backup_statement(stmt, &stmt_backup); thd->set_n_backup_statement(stmt, &stmt_backup);
thd->current_arena= stmt; thd->stmt_arena= stmt;
reinit_stmt_before_use(thd, stmt->lex); reinit_stmt_before_use(thd, stmt->lex);
/* From now cursors assume that thd->mem_root is clean */ /* From now cursors assume that thd->mem_root is clean */
if (expanded_query.length() && if (expanded_query.length() &&
@ -2110,7 +2110,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
thd->set_statement(&stmt_backup); thd->set_statement(&stmt_backup);
thd->lock_id= &thd->main_lock_id; thd->lock_id= &thd->main_lock_id;
thd->current_arena= thd; thd->stmt_arena= thd;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
set_params_data_err: set_params_data_err:
@ -2205,7 +2205,7 @@ static void execute_stmt(THD *thd, Prepared_statement *stmt,
transformations of the query tree (i.e. negations elimination). transformations of the query tree (i.e. negations elimination).
This should be done permanently on the parse tree of this statement. This should be done permanently on the parse tree of this statement.
*/ */
thd->current_arena= stmt; thd->stmt_arena= stmt;
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR); my_pthread_setprio(pthread_self(),QUERY_PRIOR);
@ -2224,7 +2224,7 @@ static void execute_stmt(THD *thd, Prepared_statement *stmt,
close_thread_tables(thd); // to close derived tables close_thread_tables(thd); // to close derived tables
cleanup_stmt_and_thd_after_use(stmt, thd); cleanup_stmt_and_thd_after_use(stmt, thd);
reset_stmt_params(stmt); reset_stmt_params(stmt);
thd->current_arena= thd; thd->stmt_arena= thd;
if (stmt->state == Query_arena::PREPARED) if (stmt->state == Query_arena::PREPARED)
stmt->state= Query_arena::EXECUTED; stmt->state= Query_arena::EXECUTED;
@ -2263,7 +2263,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
thd->current_arena= stmt; thd->stmt_arena= stmt;
thd->set_n_backup_statement(stmt, &stmt_backup); thd->set_n_backup_statement(stmt, &stmt_backup);
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
@ -2291,7 +2291,7 @@ void mysql_stmt_fetch(THD *thd, char *packet, uint packet_length)
} }
thd->restore_backup_statement(stmt, &stmt_backup); thd->restore_backup_statement(stmt, &stmt_backup);
thd->current_arena= thd; thd->stmt_arena= thd;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }

View File

@ -581,11 +581,11 @@ JOIN::optimize()
MEMROOT for prepared statements and stored procedures. MEMROOT for prepared statements and stored procedures.
*/ */
Query_arena *arena= thd->current_arena, backup; Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional()) if (arena->is_conventional())
arena= 0; // For easier test arena= 0; // For easier test
else else
thd->set_n_backup_item_arena(arena, &backup); thd->set_n_backup_active_arena(arena, &backup);
sel->first_cond_optimization= 0; sel->first_cond_optimization= 0;
@ -595,7 +595,7 @@ JOIN::optimize()
sel->prep_where= conds ? conds->copy_andor_structure(thd) : 0; sel->prep_where= conds ? conds->copy_andor_structure(thd) : 0;
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
} }
conds= optimize_cond(this, conds, join_list, &cond_value); conds= optimize_cond(this, conds, join_list, &cond_value);
@ -1744,7 +1744,7 @@ Cursor::init_from_thd(THD *thd)
things that are already allocated in thd->mem_root for Cursor::fetch() things that are already allocated in thd->mem_root for Cursor::fetch()
*/ */
main_mem_root= *thd->mem_root; main_mem_root= *thd->mem_root;
state= thd->current_arena->state; state= thd->stmt_arena->state;
/* Allocate new memory root for thd */ /* Allocate new memory root for thd */
init_sql_alloc(thd->mem_root, init_sql_alloc(thd->mem_root,
thd->variables.query_alloc_block_size, thd->variables.query_alloc_block_size,
@ -1871,7 +1871,7 @@ Cursor::fetch(ulong num_rows)
thd->query_id= query_id; thd->query_id= query_id;
thd->change_list= change_list; thd->change_list= change_list;
/* save references to memory, allocated during fetch */ /* save references to memory, allocated during fetch */
thd->set_n_backup_item_arena(this, &backup_arena); thd->set_n_backup_active_arena(this, &backup_arena);
for (info= ht_info; info->read_view ; info++) for (info= ht_info; info->read_view ; info++)
(info->ht->set_cursor_read_view)(info->read_view); (info->ht->set_cursor_read_view)(info->read_view);
@ -1890,7 +1890,7 @@ Cursor::fetch(ulong num_rows)
ha_release_temporary_latches(thd); ha_release_temporary_latches(thd);
#endif #endif
/* Grab free_list here to correctly free it in close */ /* Grab free_list here to correctly free it in close */
thd->restore_backup_item_arena(this, &backup_arena); thd->restore_active_arena(this, &backup_arena);
for (info= ht_info; info->read_view; info++) for (info= ht_info; info->read_view; info++)
(info->ht->set_cursor_read_view)(0); (info->ht->set_cursor_read_view)(0);

View File

@ -3610,7 +3610,7 @@ int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
} }
List_iterator_fast<Item> it(sel->item_list); List_iterator_fast<Item> it(sel->item_list);
if (!(transl= if (!(transl=
(Field_translator*)(thd->current_arena-> (Field_translator*)(thd->stmt_arena->
alloc(sel->item_list.elements * alloc(sel->item_list.elements *
sizeof(Field_translator))))) sizeof(Field_translator)))))
{ {

View File

@ -287,7 +287,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
all collations together for UNION. all collations together for UNION.
*/ */
List_iterator_fast<Item> tp(types); List_iterator_fast<Item> tp(types);
Query_arena *arena= thd->current_arena; Query_arena *arena= thd->stmt_arena;
Item *type; Item *type;
ulonglong create_options; ulonglong create_options;
@ -332,7 +332,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{ {
Field **field; Field **field;
Query_arena *tmp_arena,backup; Query_arena *tmp_arena,backup;
tmp_arena= thd->change_arena_if_needed(&backup); tmp_arena= thd->activate_stmt_arena_if_needed(&backup);
for (field= table->field; *field; field++) for (field= table->field; *field; field++)
{ {
@ -340,12 +340,12 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
if (!item || item_list.push_back(item)) if (!item || item_list.push_back(item))
{ {
if (tmp_arena) if (tmp_arena)
thd->restore_backup_item_arena(tmp_arena, &backup); thd->restore_active_arena(tmp_arena, &backup);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
} }
if (tmp_arena) if (tmp_arena)
thd->restore_backup_item_arena(tmp_arena, &backup); thd->restore_active_arena(tmp_arena, &backup);
if (arena->is_stmt_prepare_or_first_sp_execute()) if (arena->is_stmt_prepare_or_first_sp_execute())
{ {
/* prepare fake select to initialize it correctly */ /* prepare fake select to initialize it correctly */

View File

@ -700,11 +700,11 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
For now we assume that tables will not be changed during PS life (it For now we assume that tables will not be changed during PS life (it
will be TRUE as far as we make new table cache). will be TRUE as far as we make new table cache).
*/ */
Query_arena *arena= thd->current_arena, backup; Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional()) if (arena->is_conventional())
arena= 0; arena= 0;
else else
thd->set_n_backup_item_arena(arena, &backup); thd->set_n_backup_active_arena(arena, &backup);
/* init timestamp */ /* init timestamp */
if (!table->timestamp.str) if (!table->timestamp.str)
@ -997,13 +997,13 @@ ok:
ok2: ok2:
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
thd->lex= old_lex; thd->lex= old_lex;
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
delete table->view; delete table->view;
table->view= 0; // now it is not VIEW placeholder table->view= 0; // now it is not VIEW placeholder
thd->lex= old_lex; thd->lex= old_lex;

View File

@ -1780,7 +1780,7 @@ bool st_table_list::setup_ancestor(THD *thd)
/* Create view fields translation table */ /* Create view fields translation table */
if (!(transl= if (!(transl=
(Field_translator*)(thd->current_arena-> (Field_translator*)(thd->stmt_arena->
alloc(select->item_list.elements * alloc(select->item_list.elements *
sizeof(Field_translator))))) sizeof(Field_translator)))))
{ {
@ -1856,8 +1856,8 @@ bool st_table_list::prep_where(THD *thd, Item **conds,
if (!no_where_clause && !where_processed) if (!no_where_clause && !where_processed)
{ {
TABLE_LIST *tbl= this; TABLE_LIST *tbl= this;
Query_arena *arena= thd->current_arena, backup; Query_arena *arena= thd->stmt_arena, backup;
arena= thd->change_arena_if_needed(&backup); // For easier test arena= thd->activate_stmt_arena_if_needed(&backup); // For easier test
/* Go up to join tree and try to find left join */ /* Go up to join tree and try to find left join */
for (; tbl; tbl= tbl->embedding) for (; tbl; tbl= tbl->embedding)
@ -1877,7 +1877,7 @@ bool st_table_list::prep_where(THD *thd, Item **conds,
if (tbl == 0) if (tbl == 0)
*conds= and_conds(*conds, where); *conds= and_conds(*conds, where);
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
where_processed= TRUE; where_processed= TRUE;
} }
} }