37
37
char internal_table_name[2]= "*";
38
38
char empty_c_string[1]= {0}; /* used for not defined db */
40
const char * const THD::DEFAULT_WHERE= "field list";
40
const char * const Session::DEFAULT_WHERE= "field list";
43
43
/*****************************************************************************
86
86
Construct an (almost) deep copy of this key. Only those
87
87
elements that are known to never change are not copied.
88
88
If out of memory, a partial copy is returned and an error is set
92
92
Key::Key(const Key &rhs, MEM_ROOT *mem_root)
103
103
Construct an (almost) deep copy of this foreign key. Only those
104
104
elements that are known to never change are not copied.
105
105
If out of memory, a partial copy is returned and an error is set
109
109
Foreign_key::Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root)
268
int thd_in_lock_tables(const THD *thd)
268
int thd_in_lock_tables(const Session *thd)
270
270
return test(thd->in_lock_tables);
275
int thd_tablespace_op(const THD *thd)
275
int thd_tablespace_op(const Session *thd)
277
277
return test(thd->tablespace_op);
282
Set the process info field of the THD structure.
282
Set the process info field of the Session structure.
284
284
This function is used by plug-ins. Internally, the
285
THD::set_proc_info() function should be used.
285
Session::set_proc_info() function should be used.
287
@see THD::set_proc_info
287
@see Session::set_proc_info
290
set_thd_proc_info(THD *thd, const char *info)
290
set_thd_proc_info(Session *thd, const char *info)
292
292
thd->set_proc_info(info);
296
const char *get_thd_proc_info(THD *thd)
296
const char *get_thd_proc_info(Session *thd)
298
298
return thd->get_proc_info();
302
void **thd_ha_data(const THD *thd, const struct handlerton *hton)
302
void **thd_ha_data(const Session *thd, const struct handlerton *hton)
304
304
return (void **) &thd->ha_data[hton->slot].ha_ptr;
308
int64_t thd_test_options(const THD *thd, int64_t test_options)
308
int64_t thd_test_options(const Session *thd, int64_t test_options)
310
310
return thd->options & test_options;
314
int thd_sql_command(const THD *thd)
314
int thd_sql_command(const Session *thd)
316
316
return (int) thd->lex->sql_command;
320
int thd_tx_isolation(const THD *thd)
320
int thd_tx_isolation(const Session *thd)
322
322
return (int) thd->variables.tx_isolation;
326
void thd_inc_row_count(THD *thd)
326
void thd_inc_row_count(Session *thd)
328
328
thd->row_count++;
360
Diagnostics_area::set_ok_status(THD *thd, ha_rows affected_rows_arg,
360
Diagnostics_area::set_ok_status(Session *thd, ha_rows affected_rows_arg,
361
361
uint64_t last_insert_id_arg,
362
362
const char *message_arg)
519
519
memset(ha_data, 0, sizeof(ha_data));
521
521
binlog_evt_union.do_union= false;
522
dbug_sentry=THD_SENTRY_MAGIC;
522
dbug_sentry=Session_SENTRY_MAGIC;
524
524
client_capabilities= 0; // minimalistic client
525
525
system_thread= NON_SYSTEM_THREAD;
570
void THD::push_internal_handler(Internal_error_handler *handler)
570
void Session::push_internal_handler(Internal_error_handler *handler)
573
573
TODO: The current implementation is limited to 1 handler at a time only.
574
THD and sp_rcontext need to be modified to use a common handler stack.
574
Session and sp_rcontext need to be modified to use a common handler stack.
576
576
assert(m_internal_handler == NULL);
577
577
m_internal_handler= handler;
581
bool THD::handle_error(uint32_t sql_errno, const char *message,
581
bool Session::handle_error(uint32_t sql_errno, const char *message,
582
582
DRIZZLE_ERROR::enum_warning_level level)
584
584
if (m_internal_handler)
593
void THD::pop_internal_handler()
593
void Session::pop_internal_handler()
595
595
assert(m_internal_handler != NULL);
596
596
m_internal_handler= NULL;
600
void *thd_alloc(THD *thd, unsigned int size)
600
void *thd_alloc(Session *thd, unsigned int size)
602
602
return thd->alloc(size);
606
void *thd_calloc(THD *thd, unsigned int size)
606
void *thd_calloc(Session *thd, unsigned int size)
608
608
return thd->calloc(size);
612
char *thd_strdup(THD *thd, const char *str)
612
char *thd_strdup(Session *thd, const char *str)
614
614
return thd->strdup(str);
618
char *thd_strmake(THD *thd, const char *str, unsigned int size)
618
char *thd_strmake(Session *thd, const char *str, unsigned int size)
620
620
return thd->strmake(str, size);
624
LEX_STRING *thd_make_lex_string(THD *thd, LEX_STRING *lex_str,
624
LEX_STRING *thd_make_lex_string(Session *thd, LEX_STRING *lex_str,
625
625
const char *str, unsigned int size,
626
626
int allocate_lex_string)
633
void *thd_memdup(THD *thd, const void* str, unsigned int size)
633
void *thd_memdup(Session *thd, const void* str, unsigned int size)
635
635
return thd->memdup(str, size);
639
void thd_get_xid(const THD *thd, DRIZZLE_XID *xid)
639
void thd_get_xid(const Session *thd, DRIZZLE_XID *xid)
641
641
*xid = *(DRIZZLE_XID *) &thd->transaction.xid_state.xid;
645
645
Init common variables that has to be reset on start and on change_user
648
void Session::init(void)
650
650
pthread_mutex_lock(&LOCK_global_system_variables);
651
651
plugin_thdvar_init(this);
652
variables.time_format= date_time_format_copy((THD*) 0,
652
variables.time_format= date_time_format_copy((Session*) 0,
653
653
variables.time_format);
654
variables.date_format= date_time_format_copy((THD*) 0,
654
variables.date_format= date_time_format_copy((Session*) 0,
655
655
variables.date_format);
656
variables.datetime_format= date_time_format_copy((THD*) 0,
656
variables.datetime_format= date_time_format_copy((Session*) 0,
657
657
variables.datetime_format);
659
659
variables= global_system_variables above has reset
689
Init THD for query processing.
689
Init Session for query processing.
690
690
This has to be called once before we call mysql_parse.
691
691
See also comments in sql_class.h.
694
void THD::init_for_queries()
694
void Session::init_for_queries()
697
697
ha_enable_transaction(this,true);
748
THD_CHECK_SENTRY(this);
749
/* Ensure that no one is using THD */
748
Session_CHECK_SENTRY(this);
749
/* Ensure that no one is using Session */
750
750
pthread_mutex_lock(&LOCK_delete);
751
751
pthread_mutex_unlock(&LOCK_delete);
752
752
add_to_status(&global_status_var, &status_var);
773
773
free_root(&transaction.mem_root,MYF(0));
774
774
mysys_var=0; // Safety (shouldn't be needed)
775
775
pthread_mutex_destroy(&LOCK_delete);
776
dbug_sentry= THD_SENTRY_GONE;
776
dbug_sentry= Session_SENTRY_GONE;
839
void THD::awake(THD::killed_state state_to_set)
839
void Session::awake(Session::killed_state state_to_set)
841
THD_CHECK_SENTRY(this);
841
Session_CHECK_SENTRY(this);
842
842
safe_mutex_assert_owner(&LOCK_delete);
844
844
killed= state_to_set;
845
if (state_to_set != THD::KILL_QUERY)
845
if (state_to_set != Session::KILL_QUERY)
847
847
thr_alarm_kill(thread_id);
848
848
if (!slave_thread)
897
897
assert(thread_stack);
899
if (pthread_setspecific(THR_THD, this) ||
899
if (pthread_setspecific(THR_Session, this) ||
900
900
pthread_setspecific(THR_MALLOC, &mem_root))
902
902
mysys_var=my_thread_var;
904
904
Let mysqld define the thread id (not mysys)
905
This allows us to move THD to different threads if needed.
905
This allows us to move Session to different threads if needed.
907
907
mysys_var->id= thread_id;
908
908
real_id= pthread_self(); // For debugging
911
We have to call thr_lock_info_init() again here as THD may have been
911
We have to call thr_lock_info_init() again here as Session may have been
912
912
created in another thread
914
914
thr_lock_info_init(&lock_info);
970
970
instead of using lex_str value
971
971
@return NULL on failure, or pointer to the LEX_STRING object
973
LEX_STRING *THD::make_lex_string(LEX_STRING *lex_str,
973
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
974
974
const char* str, uint32_t length,
975
975
bool allocate_lex_string)
1004
1004
In this case to->str will point to 0 and to->length will be 0.
1007
bool THD::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1007
bool Session::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1008
1008
const char *from, uint32_t from_length,
1009
1009
const CHARSET_INFO * const from_cs)
1037
1037
!0 out of memory
1040
bool THD::convert_string(String *s, const CHARSET_INFO * const from_cs,
1040
bool Session::convert_string(String *s, const CHARSET_INFO * const from_cs,
1041
1041
const CHARSET_INFO * const to_cs)
1043
1043
uint32_t dummy_errors;
1058
1058
Update some cache variables when character set changes
1061
void THD::update_charset()
1061
void Session::update_charset()
1063
1063
uint32_t not_used;
1064
1064
charset_is_system_charset= !String::needs_conversion(0,charset(),
1089
1089
/* add table to list of changed in transaction tables */
1091
void THD::add_changed_table(Table *table)
1091
void Session::add_changed_table(Table *table)
1093
1093
assert((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
1094
1094
table->file->has_transactions());
1101
void THD::add_changed_table(const char *key, long key_length)
1101
void Session::add_changed_table(const char *key, long key_length)
1103
1103
CHANGED_TableList **prev_changed = &transaction.changed_tables;
1104
1104
CHANGED_TableList *curr = transaction.changed_tables;
1133
CHANGED_TableList* THD::changed_table_dup(const char *key, long key_length)
1133
CHANGED_TableList* Session::changed_table_dup(const char *key, long key_length)
1135
1135
CHANGED_TableList* new_table =
1136
1136
(CHANGED_TableList*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TableList))+
1214
1214
thd->mem_root (this may no longer be a true statement)
1217
void THD::nocheck_register_item_tree_change(Item **place, Item *old_value,
1217
void Session::nocheck_register_item_tree_change(Item **place, Item *old_value,
1218
1218
MEM_ROOT *runtime_memroot)
1220
1220
Item_change_record *change;
1474
static File create_file(THD *thd, char *path, sql_exchange *exchange,
1474
static File create_file(Session *thd, char *path, sql_exchange *exchange,
1475
1475
IO_CACHE *cache)
2048
2048
Don't free mem_root, as mem_root is freed in the end of dispatch_command
2049
2049
(once for any command).
2051
void THD::end_statement()
2051
void Session::end_statement()
2053
2053
/* Cleanup SQL processing state to reuse this statement in next query. */
2058
bool THD::copy_db_to(char **p_db, size_t *p_db_length)
2058
bool Session::copy_db_to(char **p_db, size_t *p_db_length)
2060
2060
if (db == NULL)
2149
2149
current_thd->status_var.net_big_packet_count+= length;
2152
void THD::send_kill_message() const
2152
void Session::send_kill_message() const
2154
2154
int err= killed_errno();
2156
2156
my_message(err, ER(err), MYF(0));
2159
void THD::set_status_var_init()
2159
void Session::set_status_var_init()
2161
2161
memset(&status_var, 0, sizeof(status_var));
2198
2198
access to mysql.proc table to find definitions of stored routines.
2199
2199
****************************************************************************/
2201
void THD::reset_n_backup_open_tables_state(Open_tables_state *backup)
2201
void Session::reset_n_backup_open_tables_state(Open_tables_state *backup)
2203
2203
backup->set_open_tables_state(this);
2204
2204
reset_open_tables_state();
2236
2236
@param thd user thread
2237
2237
@return thread id
2239
extern "C" unsigned long thd_get_thread_id(const THD *thd)
2239
extern "C" unsigned long thd_get_thread_id(const Session *thd)
2241
2241
return((unsigned long)thd->thread_id);
2245
2245
#ifdef INNODB_COMPATIBILITY_HOOKS
2246
extern "C" const struct charset_info_st *thd_charset(THD *thd)
2246
extern "C" const struct charset_info_st *thd_charset(Session *thd)
2248
2248
return(thd->charset());
2251
extern "C" char **thd_query(THD *thd)
2251
extern "C" char **thd_query(Session *thd)
2253
2253
return(&thd->query);
2256
extern "C" int thd_slave_thread(const THD *thd)
2256
extern "C" int thd_slave_thread(const Session *thd)
2258
2258
return(thd->slave_thread);
2261
extern "C" int thd_non_transactional_update(const THD *thd)
2261
extern "C" int thd_non_transactional_update(const Session *thd)
2263
2263
return(thd->transaction.all.modified_non_trans_table);
2266
extern "C" int thd_binlog_format(const THD *thd)
2266
extern "C" int thd_binlog_format(const Session *thd)
2268
2268
return (int) thd->variables.binlog_format;
2271
extern "C" void thd_mark_transaction_to_rollback(THD *thd, bool all)
2271
extern "C" void thd_mark_transaction_to_rollback(Session *thd, bool all)
2273
2273
mark_transaction_to_rollback(thd, all);
2408
2408
template <class RowsEventT> Rows_log_event*
2409
THD::binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
2409
Session::binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
2411
2411
bool is_transactional,
2412
2412
RowsEventT *hint __attribute__((unused)))
2482
2482
compiling option.
2484
2484
template Rows_log_event*
2485
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2485
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2486
2486
Write_rows_log_event*);
2488
2488
template Rows_log_event*
2489
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2489
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2490
2490
Delete_rows_log_event *);
2492
2492
template Rows_log_event*
2493
THD::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2493
Session::binlog_prepare_pending_rows_event(Table*, uint32_t, size_t, bool,
2494
2494
Update_rows_log_event *);
2611
int THD::binlog_write_row(Table* table, bool is_trans,
2611
int Session::binlog_write_row(Table* table, bool is_trans,
2612
2612
unsigned char const *record)
2614
2614
assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2635
2635
return ev->add_row_data(row_data, len);
2638
int THD::binlog_update_row(Table* table, bool is_trans,
2638
int Session::binlog_update_row(Table* table, bool is_trans,
2639
2639
const unsigned char *before_record,
2640
2640
const unsigned char *after_record)
2669
2669
ev->add_row_data(after_row, after_size);
2672
int THD::binlog_delete_row(Table* table, bool is_trans,
2672
int Session::binlog_delete_row(Table* table, bool is_trans,
2673
2673
unsigned char const *record)
2675
2675
assert(current_stmt_binlog_row_based && mysql_bin_log.is_open());
2752
2752
Error code, or 0 if no error.
2754
int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
2754
int Session::binlog_query(Session::enum_binlog_query_type qtype, char const *query_arg,
2755
2755
ulong query_len, bool is_trans, bool suppress_use,
2756
THD::killed_state killed_status_arg)
2756
Session::killed_state killed_status_arg)
2758
2758
assert(query_arg && mysql_bin_log.is_open());
2784
2784
switch (qtype) {
2785
case THD::ROW_QUERY_TYPE:
2785
case Session::ROW_QUERY_TYPE:
2786
2786
if (current_stmt_binlog_row_based)
2788
2788
/* Otherwise, we fall through */
2789
case THD::DRIZZLE_QUERY_TYPE:
2789
case Session::DRIZZLE_QUERY_TYPE:
2791
2791
Using this query type is a conveniece hack, since we have been
2792
2792
moving back and forth between using RBR for replication of
2795
2795
Make sure to change in check_table_binlog_row_based() according
2796
2796
to how you treat this.
2798
case THD::STMT_QUERY_TYPE:
2798
case Session::STMT_QUERY_TYPE:
2800
2800
The DRIZZLE_LOG::write() function will set the STMT_END_F flag and
2801
2801
flush the pending rows event if necessary.