1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-21 06:21:35 +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

@@ -2158,14 +2158,14 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
{
if (!wild_num)
return 0;
Statement *stmt= thd->current_statement, backup;
Item_arena *arena= thd->current_arena, backup;
/*
If we are in preparing prepared statement phase then we have change
temporary mem_root to statement mem root to save changes of SELECT list
*/
if (stmt)
thd->set_n_backup_item_arena(stmt, &backup);
if (arena)
thd->set_n_backup_item_arena(arena, &backup);
reg2 Item *item;
List_iterator<Item> it(fields);
while ( wild_num && (item= it++))
@@ -2178,8 +2178,8 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
if (insert_fields(thd,tables,((Item_field*) item)->db_name,
((Item_field*) item)->table_name, &it))
{
if (stmt)
thd->restore_backup_item_arena(stmt, &backup);
if (arena)
thd->restore_backup_item_arena(arena, &backup);
return (-1);
}
if (sum_func_list)
@@ -2194,8 +2194,15 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
wild_num--;
}
}
if (stmt)
thd->restore_backup_item_arena(stmt, &backup);
if (arena)
{
/* make * substituting permanent */
SELECT_LEX *select_lex= thd->lex->current_select;
select_lex->with_wild= 0;
select_lex->item_list= fields;
thd->restore_backup_item_arena(arena, &backup);
}
return 0;
}
@@ -2408,12 +2415,17 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
{
table_map not_null_tables= 0;
Statement *stmt= thd->current_statement, backup;
SELECT_LEX *select_lex= thd->lex->current_select;
Item_arena *arena= ((thd->current_arena &&
!select_lex->conds_processed_with_permanent_arena) ?
thd->current_arena :
0);
Item_arena backup;
DBUG_ENTER("setup_conds");
thd->set_query_id=1;
thd->lex->current_select->cond_count= 0;
select_lex->cond_count= 0;
if (*conds)
{
thd->where="where clause";
@@ -2436,7 +2448,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
table->on_expr->fix_fields(thd, tables, &table->on_expr) ||
table->on_expr->check_cols(1))
DBUG_RETURN(1);
thd->lex->current_select->cond_count++;
select_lex->cond_count++;
/*
If it's a normal join or a LEFT JOIN which can be optimized away
@@ -2447,12 +2459,12 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
!(specialflag & SPECIAL_NO_NEW_FUNC)))
{
table->outer_join= 0;
if (stmt)
thd->set_n_backup_item_arena(stmt, &backup);
if (arena)
thd->set_n_backup_item_arena(arena, &backup);
*conds= and_conds(*conds, table->on_expr);
table->on_expr=0;
if (stmt)
thd->restore_backup_item_arena(stmt, &backup);
if (arena)
thd->restore_backup_item_arena(arena, &backup);
if ((*conds) && !(*conds)->fixed &&
(*conds)->fix_fields(thd, tables, conds))
DBUG_RETURN(1);
@@ -2460,8 +2472,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
}
if (table->natural_join)
{
if (stmt)
thd->set_n_backup_item_arena(stmt, &backup);
if (arena)
thd->set_n_backup_item_arena(arena, &backup);
/* Make a join of all fields with have the same name */
TABLE *t1= table->table;
TABLE *t2= table->natural_join->table;
@@ -2491,7 +2503,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
t2->used_keys.intersect(t2_field->part_of_key);
}
}
thd->lex->current_select->cond_count+= cond_and->list.elements;
select_lex->cond_count+= cond_and->list.elements;
// to prevent natural join processing during PS re-execution
table->natural_join= 0;
@@ -2500,8 +2512,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
{
*conds= and_conds(*conds, cond_and);
// fix_fields() should be made with temporary memory pool
if (stmt)
thd->restore_backup_item_arena(stmt, &backup);
if (arena)
thd->restore_backup_item_arena(arena, &backup);
if (*conds && !(*conds)->fixed)
{
if ((*conds)->fix_fields(thd, tables, conds))
@@ -2512,8 +2524,8 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
{
table->on_expr= and_conds(table->on_expr, cond_and);
// fix_fields() should be made with temporary memory pool
if (stmt)
thd->restore_backup_item_arena(stmt, &backup);
if (arena)
thd->restore_backup_item_arena(arena, &backup);
if (table->on_expr && !table->on_expr->fixed)
{
if (table->on_expr->fix_fields(thd, tables, &table->on_expr))
@@ -2523,21 +2535,22 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
}
}
if (stmt)
if (arena)
{
/*
We are in prepared statement preparation code => we should store
WHERE clause changing for next executions.
We do this ON -> WHERE transformation only once per PS statement.
We do this ON -> WHERE transformation only once per PS/SP statement.
*/
thd->lex->current_select->where= *conds;
select_lex->where= *conds;
select_lex->conds_processed_with_permanent_arena= 1;
}
DBUG_RETURN(test(thd->net.report_error));
err:
if (stmt)
thd->restore_backup_item_arena(stmt, &backup);
if (arena)
thd->restore_backup_item_arena(arena, &backup);
DBUG_RETURN(1);
}