1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +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

@ -1357,7 +1357,7 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
mysql_log.write(thd, COM_PREPARE, "%s", packet);
thd->current_statement= stmt;
thd->current_arena= stmt;
lex= lex_start(thd, (uchar *) thd->query, thd->query_length);
mysql_init_query(thd);
lex->safe_to_cache_query= 0;
@ -1381,7 +1381,7 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
stmt->set_item_arena(thd);
thd->set_statement(&thd->stmt_backup);
thd->set_item_arena(&thd->stmt_backup);
thd->current_statement= 0;
thd->current_arena= 0;
if (error)
{
@ -1389,43 +1389,33 @@ void mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
thd->stmt_map.erase(stmt);
/* error is sent inside yyparse/send_prepare_results */
}
else
{
SELECT_LEX *sl= stmt->lex->all_selects_list;
/*
Save WHERE clause pointers, because they may be changed during query
optimisation.
*/
for (; sl; sl= sl->next_select_in_list())
{
sl->prep_where= sl->where;
}
}
DBUG_VOID_RETURN;
}
/* Reinit statement before execution */
static void reset_stmt_for_execute(Prepared_statement *stmt)
void reset_stmt_for_execute(THD *thd, LEX *lex)
{
THD *thd= stmt->thd;
SELECT_LEX *sl= stmt->lex->all_selects_list;
SELECT_LEX *sl= lex->all_selects_list;
for (; sl; sl= sl->next_select_in_list())
{
/*
Copy WHERE clause pointers to avoid damaging they by optimisation
*/
if (sl->prep_where)
sl->where= sl->prep_where->copy_andor_structure(thd);
DBUG_ASSERT(sl->join == 0);
ORDER *order;
/* Fix GROUP list */
for (order= (ORDER *)sl->group_list.first; order; order= order->next)
order->item= &order->item_ptr;
/* Fix ORDER list */
for (order= (ORDER *)sl->order_list.first; order; order= order->next)
order->item= &order->item_ptr;
if (!sl->first_execution)
{
/*
Copy WHERE clause pointers to avoid damaging they by optimisation
*/
if (sl->prep_where)
sl->where= sl->prep_where->copy_andor_structure(thd);
DBUG_ASSERT(sl->join == 0);
ORDER *order;
/* Fix GROUP list */
for (order= (ORDER *)sl->group_list.first; order; order= order->next)
order->item= &order->item_ptr;
/* Fix ORDER list */
for (order= (ORDER *)sl->order_list.first; order; order= order->next)
order->item= &order->item_ptr;
}
/*
TODO: When the new table structure is ready, then have a status bit
@ -1443,7 +1433,6 @@ static void reset_stmt_for_execute(Prepared_statement *stmt)
tables->table= 0;
tables->table_list= 0;
}
{
SELECT_LEX_UNIT *unit= sl->master_unit();
unit->unclean();
@ -1506,7 +1495,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
thd->stmt_backup.set_statement(thd);
thd->set_statement(stmt);
reset_stmt_for_execute(stmt);
reset_stmt_for_execute(thd, stmt->lex);
#ifndef EMBEDDED_LIBRARY
if (stmt->param_count)
{