1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

PS and SP made compatible in mechanism used for preparing query for rexecutions (Bug #2266)

mysql-test/r/sp.result:
  test suite for Bug #2266
mysql-test/t/sp.test:
  test suite for Bug #2266
sql/item_subselect.cc:
  made ancestor for Statement (Item_arena)
sql/item_subselect.h:
  made ancestor for Statement (Item_arena)
sql/item_sum.cc:
  made ancestor for Statement (Item_arena)
sql/item_sum.h:
  made ancestor for Statement (Item_arena)
sql/mysql_priv.h:
  reset_stmt_for_execute use PS and SP
sql/sp_head.cc:
  sp_head use Item_arena as ancestor to be PS cleunup compatible
  SP use PS storing/restoring/cleanup mechanisms
  cleanup() of SP Items added
  Items created in temporary memory pool during SP execution saved for normal freeing after SP execution
sql/sp_head.h:
  sp_head use Item_arena
sql/sql_base.cc:
  made ancestor for Statement (Item_arena)
  results of wild_setup made permanent
  setup_conds make natural joins expanding only once and store results in PS/SP memory
sql/sql_class.cc:
  made ancestor for Statement (Item_arena)
sql/sql_class.h:
  made ancestor for Statement (Item_arena)
  method to detect PS preparation added
sql/sql_delete.cc:
  storing where for DELETE and mark first execution
sql/sql_derived.cc:
  use method
sql/sql_insert.cc:
  mark first execution for INSERT
sql/sql_lex.cc:
  flags to correctly make transformations of query and storing them in memory of PS/SP
  made ancestor for Statement (Item_arena)
sql/sql_lex.h:
  reved variable od SP ol saving data
  flags to correctly make transformations of query and storing them in memory of PS/SP
sql/sql_parse.cc:
  cleunup unit for any query
sql/sql_prepare.cc:
  made ancestor for Statement (Item_arena)
  storing where moved to preparation
  changed interface of reset_stmt_for_execute to use it is SP
  do not restore where/order by/group by before first execution (but tables and unit can be chenged without execution and should be prepared (subqueries executes on demand))
sql/sql_select.cc:
  storing where for SELECT/multi-DELETE/... and mark first execution
sql/sql_union.cc:
  made ancestor for Statement (Item_arena)
sql/sql_update.cc:
  storing where for UPDATE and mark first execution
This commit is contained in:
unknown
2004-05-20 02:02:49 +03:00
parent 8d18ae3986
commit 16227c28e6
22 changed files with 306 additions and 275 deletions

View File

@ -434,6 +434,48 @@ struct system_variables
void free_tmp_table(THD *thd, TABLE *entry);
class Item_arena
{
public:
/*
List of items created in the parser for this query. Every item puts
itself to the list on creation (see Item::Item() for details))
*/
Item *free_list;
MEM_ROOT mem_root;
Item_arena(THD *thd);
Item_arena();
Item_arena(bool init_mem_root);
~Item_arena();
inline gptr alloc(unsigned int size) { return alloc_root(&mem_root,size); }
inline gptr calloc(unsigned int size)
{
gptr ptr;
if ((ptr=alloc_root(&mem_root,size)))
bzero((char*) ptr,size);
return ptr;
}
inline char *strdup(const char *str)
{ return strdup_root(&mem_root,str); }
inline char *strmake(const char *str, uint size)
{ return strmake_root(&mem_root,str,size); }
inline char *memdup(const char *str, uint size)
{ return memdup_root(&mem_root,str,size); }
inline char *memdup_w_gap(const char *str, uint size, uint gap)
{
gptr ptr;
if ((ptr=alloc_root(&mem_root,size+gap)))
memcpy(ptr,str,size);
return ptr;
}
void set_n_backup_item_arena(Item_arena *set, Item_arena *backup);
void restore_backup_item_arena(Item_arena *set, Item_arena *backup);
void set_item_arena(Item_arena *set);
};
/*
State of a single command executed against this connection.
One connection can contain a lot of simultaneously running statements,
@ -448,7 +490,7 @@ void free_tmp_table(THD *thd, TABLE *entry);
be used explicitly.
*/
class Statement
class Statement: public Item_arena
{
Statement(const Statement &rhs); /* not implemented: */
Statement &operator=(const Statement &rhs); /* non-copyable */
@ -489,12 +531,6 @@ public:
*/
char *query;
uint32 query_length; // current query length
/*
List of items created in the parser for this query. Every item puts
itself to the list on creation (see Item::Item() for details))
*/
Item *free_list;
MEM_ROOT mem_root;
public:
/* We build without RTTI, so dynamic_cast can't be used. */
@ -518,31 +554,6 @@ public:
/* return class type */
virtual Type type() const;
inline gptr alloc(unsigned int size) { return alloc_root(&mem_root,size); }
inline gptr calloc(unsigned int size)
{
gptr ptr;
if ((ptr=alloc_root(&mem_root,size)))
bzero((char*) ptr,size);
return ptr;
}
inline char *strdup(const char *str)
{ return strdup_root(&mem_root,str); }
inline char *strmake(const char *str, uint size)
{ return strmake_root(&mem_root,str,size); }
inline char *memdup(const char *str, uint size)
{ return memdup_root(&mem_root,str,size); }
inline char *memdup_w_gap(const char *str, uint size, uint gap)
{
gptr ptr;
if ((ptr=alloc_root(&mem_root,size+gap)))
memcpy(ptr,str,size);
return ptr;
}
void set_n_backup_item_arena(Statement *set, Statement *backup);
void restore_backup_item_arena(Statement *set, Statement *backup);
void set_item_arena(Statement *set);
};
@ -746,9 +757,9 @@ public:
Vio* active_vio;
#endif
/*
Current prepared Statement if there one, or 0
Current prepared Item_arena if there one, or 0
*/
Statement *current_statement;
Item_arena *current_arena;
/*
next_insert_id is set on SET INSERT_ID= #. This is used as the next
generated auto_increment value in handler.cc
@ -969,7 +980,7 @@ public:
inline void allocate_temporary_memory_pool_for_ps_preparing()
{
DBUG_ASSERT(current_statement!=0);
DBUG_ASSERT(current_arena!=0);
/*
We do not want to have in PS memory all that junk,
which will be created by preparation => substitute memory
@ -978,7 +989,7 @@ public:
We know that PS memory pool is now copied to THD, we move it back
to allow some code use it.
*/
current_statement->set_item_arena(this);
current_arena->set_item_arena(this);
init_sql_alloc(&mem_root,
variables.query_alloc_block_size,
variables.query_prealloc_size);
@ -986,12 +997,16 @@ public:
}
inline void free_temporary_memory_pool_for_ps_preparing()
{
DBUG_ASSERT(current_statement!=0);
cleanup_items(current_statement->free_list);
DBUG_ASSERT(current_arena!=0);
cleanup_items(current_arena->free_list);
free_items(free_list);
close_thread_tables(this); // to close derived tables
free_root(&mem_root, MYF(0));
set_item_arena(current_statement);
set_item_arena(current_arena);
}
inline bool only_prepare()
{
return command == COM_PREPARE;
}
};