mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Prepared_statement deployed instead of PREP_STMT.
This commit is contained in:
140
sql/sql_class.cc
140
sql/sql_class.cc
@ -88,21 +88,20 @@ THD::THD():user_time(0), is_fatal_error(0),
|
||||
insert_id_used(0), rand_used(0), in_lock_tables(0),
|
||||
global_read_lock(0), bootstrap(0)
|
||||
{
|
||||
host=user=priv_user=db=query=ip=0;
|
||||
lex= &main_lex;
|
||||
host= user= priv_user= db= ip=0;
|
||||
host_or_ip= "connecting host";
|
||||
locked=killed=some_tables_deleted=no_errors=password= 0;
|
||||
query_start_used= 0;
|
||||
count_cuted_fields= CHECK_FIELD_IGNORE;
|
||||
db_length=query_length=col_access=0;
|
||||
db_length= col_access= 0;
|
||||
query_error= tmp_table_used= 0;
|
||||
next_insert_id=last_insert_id=0;
|
||||
open_tables= temporary_tables= handler_tables= derived_tables= 0;
|
||||
handler_items=0;
|
||||
tmp_table=0;
|
||||
lock=locked_tables=0;
|
||||
used_tables=0;
|
||||
cuted_fields= sent_row_count= current_stmt_id= 0L;
|
||||
cuted_fields= sent_row_count= 0L;
|
||||
statement_id_counter= 0UL;
|
||||
// Must be reset to handle error with THD's created for init of mysqld
|
||||
lex->current_select= 0;
|
||||
start_time=(time_t) 0;
|
||||
@ -138,7 +137,6 @@ THD::THD():user_time(0), is_fatal_error(0),
|
||||
server_id = ::server_id;
|
||||
slave_net = 0;
|
||||
command=COM_CONNECT;
|
||||
set_query_id=1;
|
||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||
db_access=NO_ACCESS;
|
||||
#endif
|
||||
@ -146,10 +144,11 @@ THD::THD():user_time(0), is_fatal_error(0),
|
||||
*scramble= '\0';
|
||||
|
||||
init();
|
||||
init_sql_alloc(&mem_root, // must be after init()
|
||||
variables.query_alloc_block_size,
|
||||
variables.query_prealloc_size);
|
||||
/* Initialize sub structures */
|
||||
bzero((char*) &mem_root,sizeof(mem_root));
|
||||
bzero((char*) &transaction.mem_root,sizeof(transaction.mem_root));
|
||||
bzero((char*) &con_root,sizeof(con_root));
|
||||
bzero((char*) &warn_root,sizeof(warn_root));
|
||||
init_alloc_root(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE);
|
||||
user_connect=(USER_CONN *)0;
|
||||
@ -166,12 +165,6 @@ THD::THD():user_time(0), is_fatal_error(0),
|
||||
else
|
||||
bzero((char*) &user_var_events, sizeof(user_var_events));
|
||||
|
||||
/* Prepared statements */
|
||||
last_prepared_stmt= 0;
|
||||
init_tree(&prepared_statements, 0, 0, sizeof(PREP_STMT),
|
||||
(qsort_cmp2) compare_prep_stmt, 1,
|
||||
(tree_element_free) free_prep_stmt, 0);
|
||||
|
||||
/* Protocol */
|
||||
protocol= &protocol_simple; // Default protocol
|
||||
protocol_simple.init(this);
|
||||
@ -189,7 +182,9 @@ THD::THD():user_time(0), is_fatal_error(0),
|
||||
transaction.trans_log.end_of_file= max_binlog_cache_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
init_sql_alloc(&transaction.mem_root,
|
||||
variables.trans_alloc_block_size,
|
||||
variables.trans_prealloc_size);
|
||||
/*
|
||||
We need good random number initialization for new thread
|
||||
Just coping global one will not work
|
||||
@ -232,22 +227,6 @@ void THD::init(void)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Init THD for query processing
|
||||
|
||||
This has to be called once before we call mysql_parse()
|
||||
*/
|
||||
|
||||
void THD::init_for_queries()
|
||||
{
|
||||
init_sql_alloc(&mem_root, variables.query_alloc_block_size,
|
||||
variables.query_prealloc_size);
|
||||
init_sql_alloc(&transaction.mem_root,
|
||||
variables.trans_alloc_block_size,
|
||||
variables.trans_prealloc_size);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Do what's needed when one invokes change user
|
||||
|
||||
@ -276,7 +255,6 @@ void THD::cleanup(void)
|
||||
{
|
||||
DBUG_ENTER("THD::cleanup");
|
||||
ha_rollback(this);
|
||||
delete_tree(&prepared_statements);
|
||||
if (locked_tables)
|
||||
{
|
||||
lock=locked_tables; locked_tables=0;
|
||||
@ -340,8 +318,6 @@ THD::~THD()
|
||||
safeFree(user);
|
||||
safeFree(db);
|
||||
safeFree(ip);
|
||||
free_root(&mem_root,MYF(0));
|
||||
free_root(&con_root,MYF(0));
|
||||
free_root(&warn_root,MYF(0));
|
||||
free_root(&transaction.mem_root,MYF(0));
|
||||
mysys_var=0; // Safety (shouldn't be needed)
|
||||
@ -1193,6 +1169,102 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Statement functions
|
||||
*/
|
||||
|
||||
Statement::Statement(THD *thd)
|
||||
:id(++thd->statement_id_counter),
|
||||
query_id(thd->query_id),
|
||||
set_query_id(1),
|
||||
allow_sum_func(0),
|
||||
command(thd->command),
|
||||
lex(&main_lex),
|
||||
query(0),
|
||||
query_length(0),
|
||||
free_list(0)
|
||||
{
|
||||
init_sql_alloc(&mem_root,
|
||||
thd->variables.query_alloc_block_size,
|
||||
thd->variables.query_prealloc_size);
|
||||
}
|
||||
|
||||
/*
|
||||
This constructor is called when statement is a subobject of THD:
|
||||
Some variables are initialized in THD::init due to locking problems
|
||||
This statement object will be used to
|
||||
*/
|
||||
|
||||
Statement::Statement()
|
||||
:id(0),
|
||||
query_id(0), /* initialized later */
|
||||
set_query_id(1),
|
||||
allow_sum_func(0), /* initialized later */
|
||||
command(COM_SLEEP), /* initialized later */
|
||||
lex(&main_lex),
|
||||
query(0), /* these two are set */
|
||||
query_length(0), /* in alloc_query() */
|
||||
free_list(0)
|
||||
{
|
||||
bzero((char *) &mem_root, sizeof(mem_root));
|
||||
}
|
||||
|
||||
|
||||
Statement::Type Statement::type() const
|
||||
{
|
||||
return STATEMENT;
|
||||
}
|
||||
|
||||
|
||||
void Statement::set_statement(Statement *stmt)
|
||||
{
|
||||
id= stmt->id;
|
||||
query_id= stmt->query_id;
|
||||
set_query_id= stmt->set_query_id;
|
||||
allow_sum_func= stmt->allow_sum_func;
|
||||
command= stmt->command;
|
||||
lex= stmt->lex;
|
||||
query= stmt->query;
|
||||
query_length= stmt->query_length;
|
||||
free_list= stmt->free_list;
|
||||
mem_root= stmt->mem_root;
|
||||
}
|
||||
|
||||
|
||||
Statement::~Statement()
|
||||
{
|
||||
free_root(&mem_root, MYF(0));
|
||||
}
|
||||
|
||||
C_MODE_START
|
||||
|
||||
static byte *
|
||||
get_statement_id_as_hash_key(const byte *record, uint *key_length,
|
||||
my_bool not_used __attribute__((unused)))
|
||||
{
|
||||
const Statement *statement= (const Statement *) record;
|
||||
*key_length= sizeof(statement->id);
|
||||
return (byte *) &((const Statement *) statement)->id;
|
||||
}
|
||||
|
||||
static void delete_statement_as_hash_key(void *key)
|
||||
{
|
||||
delete (Statement *) key;
|
||||
}
|
||||
|
||||
C_MODE_END
|
||||
|
||||
Statement_map::Statement_map() :
|
||||
last_found_statement(0)
|
||||
{
|
||||
enum { START_HASH_SIZE = 16 };
|
||||
hash_init(&st_hash, default_charset_info, START_HASH_SIZE, 0, 0,
|
||||
get_statement_id_as_hash_key,
|
||||
delete_statement_as_hash_key, MYF(0));
|
||||
}
|
||||
|
||||
bool select_dumpvar::send_data(List<Item> &items)
|
||||
{
|
||||
List_iterator_fast<Item_func_set_user_var> li(vars);
|
||||
|
Reference in New Issue
Block a user