diff options
author | unknown <bell@sanja.is.com.ua> | 2004-02-17 11:12:55 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2004-02-17 11:12:55 +0200 |
commit | 952f99d4c604475217b8f096dc5bab94af8e04db (patch) | |
tree | 7656414131e3abbff86bae92c090d0209cd07663 /sql/sql_prepare.cc | |
parent | 62cc89aad50b00c0ab1ef3e94c5a3467eb78eb70 (diff) | |
parent | 6826a55b1da73770ce067972efafc00f9d2f6670 (diff) | |
download | mariadb-git-952f99d4c604475217b8f096dc5bab94af8e04db.tar.gz |
merge
mysql-test/r/derived.result:
Auto merged
mysql-test/t/derived.test:
Auto merged
sql/item.cc:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/item_sum.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sql_acl.cc:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_lex.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_union.cc:
Auto merged
sql/sql_update.cc:
Auto merged
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r-- | sql/sql_prepare.cc | 108 |
1 files changed, 80 insertions, 28 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 3e51844e8cf..55ba6abc06b 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -622,7 +622,12 @@ static bool mysql_test_insert_fields(Prepared_statement *stmt, DBUG_RETURN(1); #endif if (open_and_lock_tables(thd, table_list)) - DBUG_RETURN(1); + { + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); + DBUG_RETURN(1); + } + table= table_list->table; if ((values= its++)) @@ -631,7 +636,12 @@ static bool mysql_test_insert_fields(Prepared_statement *stmt, ulong counter= 0; if (check_insert_fields(thd,table,fields,*values,1)) + { + thd->ps_setup_free_memory(); DBUG_RETURN(1); + } + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); value_count= values->elements; its.rewind(); @@ -648,6 +658,11 @@ static bool mysql_test_insert_fields(Prepared_statement *stmt, } } } + else + { + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); + } if (send_prep_stmt(stmt, 0)) DBUG_RETURN(1); DBUG_RETURN(0); @@ -678,11 +693,20 @@ static bool mysql_test_upd_fields(Prepared_statement *stmt, DBUG_RETURN(1); #endif if (open_and_lock_tables(thd, table_list)) + { + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); DBUG_RETURN(1); if (setup_tables(table_list) || - setup_fields(thd, 0, table_list, fields, 1, 0, 0) || - setup_conds(thd, table_list, &conds) || thd->net.report_error) + setup_fields(thd, 0, table_list, fields, 1, 0, 0) || + setup_conds(thd, table_list, &conds) || thd->net.report_error) + { + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); DBUG_RETURN(1); + } + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); /* Currently return only column list info only, and we are not @@ -737,39 +761,50 @@ static bool mysql_test_select_fields(Prepared_statement *stmt, DBUG_RETURN(1); if (open_and_lock_tables(thd, tables)) + { + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); DBUG_RETURN(1); + } if (lex->describe) { if (send_prep_stmt(stmt, 0)) - DBUG_RETURN(1); + goto err; } else { if (!result && !(result= new select_send())) { send_error(thd, ER_OUT_OF_RESOURCES); - DBUG_RETURN(1); + goto err; } - JOIN *join= new JOIN(thd, fields, select_options, result); thd->used_tables= 0; // Updated by setup_fields - if (join->prepare(&select_lex->ref_pointer_array, - (TABLE_LIST*)select_lex->get_table_list(), - wild_num, conds, og_num, order, group, having, proc, - select_lex, unit)) - DBUG_RETURN(1); + if (unit->prepare(thd, result, 0)) + goto err_prep; + if (send_prep_stmt(stmt, fields.elements) || thd->protocol_simple.send_fields(&fields, 0) #ifndef EMBEDDED_LIBRARY - || net_flush(&thd->net) + || net_flush(&thd->net) #endif - ) - DBUG_RETURN(1); - join->cleanup(); + ) + goto err_prep; + + unit->cleanup(); } - DBUG_RETURN(0); + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); + DBUG_RETURN(0); + +err_prep: + unit->cleanup(); +err: + // this memory pool was opened in open_and_lock_tables + thd->ps_setup_free_memory(); + DBUG_RETURN(1); } @@ -898,6 +933,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) thd->stmt_backup.set_statement(thd); thd->set_statement(stmt); + thd->current_statement= stmt; if (alloc_query(thd, packet, packet_length)) goto alloc_query_err; @@ -925,9 +961,9 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) sl->prep_where= sl->where; } - cleanup_items(thd->free_list); stmt->set_statement(thd); thd->set_statement(&thd->stmt_backup); + thd->current_statement= 0; if (init_param_items(stmt)) goto init_param_err; @@ -944,8 +980,10 @@ init_param_err: alloc_query_err: /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); + thd->current_statement= 0; DBUG_RETURN(1); insert_stmt_err: + thd->current_statement= 0; delete stmt; DBUG_RETURN(1); } @@ -1010,24 +1048,36 @@ void mysql_stmt_execute(THD *thd, char *packet) /* Fix ORDER list */ for (order=(ORDER *)sl->order_list.first ; order ; order=order->next) order->item= (Item **)(order+1); + + /* + TODO: When the new table structure is ready, then have a status bit + to indicate the table is altered, and re-do the setup_* + and open the tables back. + */ + for (TABLE_LIST *tables= (TABLE_LIST*) sl->table_list.first; + tables; + tables= tables->next) + { + tables->table= 0; // safety - nasty init + tables->table_list= 0; + } + + { + SELECT_LEX_UNIT *unit= sl->master_unit(); + unit->unclean(); + unit->types.empty(); + // for derived tables & PS (which can't be reset bu Item_subquery) + unit->reinit_exec_mechanism(); + } } - /* - TODO: When the new table structure is ready, then have a status bit - to indicate the table is altered, and re-do the setup_* - and open the tables back. - */ - for (TABLE_LIST *tables= (TABLE_LIST*) stmt->lex->select_lex.table_list.first; - tables; - tables= tables->next) - tables->table= 0; // safety - nasty init #ifndef EMBEDDED_LIBRARY if (stmt->param_count && setup_params_data(stmt)) - DBUG_VOID_RETURN; + goto end; #else if (stmt->param_count && (*stmt->setup_params_data)(stmt)) - DBUG_VOID_RETURN; + goto end; #endif if (!(specialflag & SPECIAL_NO_PRIOR)) @@ -1048,8 +1098,10 @@ void mysql_stmt_execute(THD *thd, char *packet) free_items(thd->free_list); cleanup_items(stmt->free_list); + close_thread_tables(thd); // to close derived tables free_root(&thd->mem_root, MYF(0)); thd->set_statement(&thd->stmt_backup); +end: DBUG_VOID_RETURN; } |