113
113
is why we supply it with a copy.
115
115
@return If out of memory, 0 is returned and an error is set in
118
118
Key_part_spec *clone(MEM_ROOT *mem_root) const
119
119
{ return new (mem_root) Key_part_spec(*this); }
237
237
class select_result;
240
#define THD_SENTRY_MAGIC 0xfeedd1ff
241
#define THD_SENTRY_GONE 0xdeadbeef
240
#define Session_SENTRY_MAGIC 0xfeedd1ff
241
#define Session_SENTRY_GONE 0xdeadbeef
243
#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
243
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
245
245
struct system_variables
312
312
ulong trans_prealloc_size;
313
313
ulong log_warnings;
314
314
ulong group_concat_max_len;
315
ulong binlog_format; // binlog format for this thd (see enum_binlog_format)
315
ulong binlog_format; // binlog format for this session (see enum_binlog_format)
317
317
In slave thread we need to know in behalf of which
318
318
thread the query is being run to replicate temp tables properly
497
497
One connection can contain a lot of simultaneously running statements,
498
498
some of which could be:
499
499
- prepared, that is, contain placeholders,
500
To perform some action with statement we reset THD part to the state of
501
that statement, do the action, and then save back modified state from THD
500
To perform some action with statement we reset Session part to the state of
501
that statement, do the action, and then save back modified state from Session
502
502
to the statement. It will be changed in near future, and Statement will
503
503
be used explicitly.
519
519
handler of fields used is set
520
520
MARK_COLUMNS_READ: Means a bit in read set is set to inform handler
521
521
that the field is to be read. If field list contains
522
duplicates, then thd->dup_field is set to point
522
duplicates, then session->dup_field is set to point
523
523
to the last found duplicate.
524
524
MARK_COLUMNS_WRITE: Means a bit is set in write set to inform handler
525
525
that it needs to update this field in write_row
538
538
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
539
539
non-NULL value if its previous value is NULL. We do not need to protect
540
540
operation (B) with any mutex. To avoid crashes in races, if we do not
541
know that thd->query cannot change at the moment, one should print
542
thd->query like this:
541
know that session->query cannot change at the moment, one should print
542
session->query like this:
543
543
(1) reserve the LOCK_thread_count mutex;
544
(2) check if thd->query is NULL;
545
(3) if not NULL, then print at most thd->query_length characters from
544
(2) check if session->query is NULL;
545
(3) if not NULL, then print at most session->query_length characters from
546
546
it. We will see the query_length field as either 0, or the right value
548
548
Assuming that the write and read of an n-bit memory field in an n-bit
562
562
valid database name.
564
564
@note this attribute is set and alloced by the slave SQL thread (for
565
the THD of that thread); that thread is (and must remain, for now) the
565
the Session of that thread); that thread is (and must remain, for now) the
566
566
only responsible for freeing this member.
592
592
/* For now, this is only used to catch duplicated external xids */
593
593
XID xid; // transaction identifier
594
594
enum xa_states xa_state; // used by external XA only
598
598
extern pthread_mutex_t LOCK_xid_cache;
689
689
Tables that were locked with explicit or implicit LOCK TABLES.
690
690
(Implicit LOCK TABLES happens when we are prelocking tables for
691
691
execution of statement which uses stored routines. See description
692
THD::prelocked_mode for more info.)
692
Session::prelocked_mode for more info.)
694
694
DRIZZLE_LOCK *locked_tables;
768
768
from the anticipated conditions trapped during runtime.
770
770
This mechanism is similar to C++ try/throw/catch:
771
- 'try' correspond to <code>THD::push_internal_handler()</code>,
771
- 'try' correspond to <code>Session::push_internal_handler()</code>,
772
772
- 'throw' correspond to <code>my_error()</code>,
773
773
which invokes <code>my_message_sql()</code>,
774
774
- 'catch' correspond to checking how/if an internal handler was invoked,
775
775
before removing it from the exception stack with
776
<code>THD::pop_internal_handler()</code>.
776
<code>Session::pop_internal_handler()</code>.
778
778
@param sql_errno the error number
779
779
@param level the error level
780
@param thd the calling thread
780
@param session the calling thread
781
781
@return true if the error is handled
783
783
virtual bool handle_error(uint32_t sql_errno,
784
784
const char *message,
785
785
DRIZZLE_ERROR::enum_warning_level level,
786
Session *session) = 0;
815
815
/** Set to make set_error_status after set_{ok,eof}_status possible. */
816
816
bool can_overwrite_status;
818
void set_ok_status(THD *thd, ha_rows affected_rows_arg,
818
void set_ok_status(Session *session, ha_rows affected_rows_arg,
819
819
uint64_t last_insert_id_arg,
820
820
const char *message);
821
void set_eof_status(THD *thd);
822
void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
821
void set_eof_status(Session *session);
822
void set_error_status(Session *session, uint32_t sql_errno_arg, const char *message_arg);
824
824
void disable_status();
868
868
uint32_t m_sql_errno;
871
Copied from thd->server_status when the diagnostics area is assigned.
871
Copied from session->server_status when the diagnostics area is assigned.
872
872
We need this member as some places in the code use the following pattern:
873
thd->server_status|= ...
875
thd->server_status&= ~...
873
session->server_status|= ...
875
session->server_status&= ~...
876
876
Assigned by OK, EOF or ERROR.
878
878
uint32_t m_server_status;
880
880
The number of rows affected by the last statement. This is
881
semantically close to thd->row_count_func, but has a different
882
life cycle. thd->row_count_func stores the value returned by
881
semantically close to session->row_count_func, but has a different
882
life cycle. session->row_count_func stores the value returned by
883
883
function ROW_COUNT() and is cleared only by statements that
884
884
update its value, such as INSERT, UPDATE, DELETE and few others.
885
885
This member is cleared at the beginning of the next statement.
887
We could possibly merge the two, but life cycle of thd->row_count_func
887
We could possibly merge the two, but life cycle of session->row_count_func
888
888
can not be changed.
890
890
ha_rows m_affected_rows;
892
892
Similarly to the previous member, this is a replacement of
893
thd->first_successful_insert_id_in_prev_stmt, which is used
893
session->first_successful_insert_id_in_prev_stmt, which is used
894
894
to implement LAST_INSERT_ID().
896
896
uint64_t m_last_insert_id;
936
For each client connection we create a separate thread with THD serving as
936
For each client connection we create a separate thread with Session serving as
937
937
a thread/connection descriptor
940
class THD :public Statement,
940
class Session :public Statement,
941
941
public Open_tables_state
945
945
Relay_log_info* rli_fake;
948
Constant for THD::where initialization in the beginning of every query.
948
Constant for Session::where initialization in the beginning of every query.
950
It's needed because we do not save/restore THD::where normally during
950
It's needed because we do not save/restore Session::where normally during
951
951
primary (non subselect) query execution.
953
953
static const char * const DEFAULT_WHERE;
967
967
THR_LOCK_OWNER main_lock_id; // To use for conventional queries
968
968
THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to
969
969
// the lock_id of a cursor.
970
pthread_mutex_t LOCK_delete; // Locked before thd is deleted
970
pthread_mutex_t LOCK_delete; // Locked before session is deleted
972
972
A pointer to the stack frame of handle_one_connection(),
973
973
which is called first in the thread for handling a client
984
Some members of THD (currently 'Statement::db',
984
Some members of Session (currently 'Statement::db',
985
985
'catalog' and 'query') are set and alloced by the slave SQL thread
986
(for the THD of that thread); that thread is (and must remain, for now)
986
(for the Session of that thread); that thread is (and must remain, for now)
987
987
the only responsible for freeing these 3 members. If you add members
988
988
here, and you add code to set them in replication, don't forget to
989
989
free_them_and_set_them_to_0 in replication properly. For details see
999
999
Points to info-string that we show in SHOW PROCESSLIST
1000
You are supposed to call THD_SET_PROC_INFO only if you have coded
1000
You are supposed to call Session_SET_PROC_INFO only if you have coded
1001
1001
a time-consuming piece that MySQL can get stuck in for a long time.
1003
Set it using the thd_proc_info(THD *thread, const char *message)
1003
Set it using the session_proc_info(Session *thread, const char *message)
1004
1004
macro/function.
1006
1006
void set_proc_info(const char *info) { proc_info= info; }
1100
1100
struct st_transactions {
1101
1101
SAVEPOINT *savepoints;
1102
THD_TRANS all; // Trans since BEGIN WORK
1103
THD_TRANS stmt; // Trans for current statement
1102
Session_TRANS all; // Trans since BEGIN WORK
1103
Session_TRANS stmt; // Trans for current statement
1104
1104
bool on; // see ha_enable_transaction()
1105
1105
XID_STATE xid_state;
1106
1106
Rows_log_event *m_pending_rows_event;
1131
1131
This is to track items changed during execution of a prepared
1132
1132
statement/stored procedure. It's created by
1133
register_item_tree_change() in memory root of THD, and freed in
1133
register_item_tree_change() in memory root of Session, and freed in
1134
1134
rollback_item_tree_changes(). For conventional execution it's always
1290
1290
The set of those tables whose fields are referenced in all subqueries
1292
TODO: possibly this it is incorrect to have used tables in THD because
1292
TODO: possibly this it is incorrect to have used tables in Session because
1293
1293
with more than one subquery, it is not clear what does the field mean.
1295
1295
table_map used_tables;
1365
1365
can not continue. In particular, disables activation of
1366
1366
CONTINUE or EXIT handlers of stored routines.
1367
1367
Reset in the end of processing of the current user request, in
1368
@see mysql_reset_thd_for_next_command().
1368
@see mysql_reset_session_for_next_command().
1370
1370
bool is_fatal_error;
1462
1462
Lex_input_stream *m_lip;
1467
1467
void init(void);
1469
1469
Initialize memory roots necessary for query processing and (!)
1470
pre-allocate memory for it. We can't do that in THD constructor because
1470
pre-allocate memory for it. We can't do that in Session constructor because
1471
1471
there are use cases (acl_init, watcher threads,
1472
1472
killing mysqld) where it's vital to not allocate excessive and not used
1473
1473
memory. Note, that we still don't return error from init_for_queries():
1503
1503
int binlog_query(enum_binlog_query_type qtype,
1504
1504
char const *query, ulong query_len,
1505
1505
bool is_trans, bool suppress_use,
1506
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1506
Session::killed_state killed_err_arg= Session::KILLED_NO_VALUE);
1509
1509
For enter_cond() / exit_cond() to work the mutex must be got before
1526
1526
Putting the mutex unlock in exit_cond() ensures that
1527
1527
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
1528
1528
locked (if that would not be the case, you'll get a deadlock if someone
1529
does a THD::awake() on you).
1529
does a Session::awake() on you).
1531
1531
pthread_mutex_unlock(mysys_var->current_mutex);
1532
1532
pthread_mutex_lock(&mysys_var->mutex);
1798
/** A short cut for thd->main_da.set_ok_status(). */
1798
/** A short cut for session->main_da.set_ok_status(). */
1801
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
1801
my_ok(Session *session, ha_rows affected_rows= 0, uint64_t id= 0,
1802
1802
const char *message= NULL)
1804
thd->main_da.set_ok_status(thd, affected_rows, id, message);
1804
session->main_da.set_ok_status(session, affected_rows, id, message);
1808
/** A short cut for thd->main_da.set_eof_status(). */
1808
/** A short cut for session->main_da.set_eof_status(). */
1811
my_eof(Session *session)
1813
thd->main_da.set_eof_status(thd);
1813
session->main_da.set_eof_status(session);
1816
1816
#define tmp_disable_binlog(A) \
2031
2031
/* lock data for tmp table */
2032
2032
DRIZZLE_LOCK *m_lock;
2033
/* m_lock or thd->extra_lock */
2033
/* m_lock or session->extra_lock */
2034
2034
DRIZZLE_LOCK **m_plock;
2036
2036
select_create (TableList *table_arg,
2055
2055
virtual bool can_rollback_data() { return 1; }
2057
// Needed for access from local class MY_HOOKS in prepare(), since thd is proteted.
2058
const THD *get_thd(void) { return thd; }
2057
// Needed for access from local class MY_HOOKS in prepare(), since session is proteted.
2058
const Session *get_session(void) { return session; }
2059
2059
const HA_CREATE_INFO *get_create_info() { return create_info; };
2060
2060
int prepare2(void) { return 0; }
2142
2142
bool send_eof();
2144
2144
void cleanup();
2145
bool create_result_table(THD *thd, List<Item> *column_types,
2145
bool create_result_table(Session *session, List<Item> *column_types,
2146
2146
bool is_distinct, uint64_t options,
2147
2147
const char *alias, bool bit_fields_as_long);
2225
2225
LEX_STRING table;
2226
2226
SELECT_LEX_UNIT *sel;
2227
inline Table_ident(THD *thd, LEX_STRING db_arg, LEX_STRING table_arg,
2227
inline Table_ident(Session *session, LEX_STRING db_arg, LEX_STRING table_arg,
2229
2229
:table(table_arg), sel((SELECT_LEX_UNIT *)0)
2231
if (!force && (thd->client_capabilities & CLIENT_NO_SCHEMA))
2231
if (!force && (session->client_capabilities & CLIENT_NO_SCHEMA))