35
36
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
36
37
enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
37
38
enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
38
DELAY_KEY_WRITE_ALL };
39
DELAY_KEY_WRITE_ALL };
39
40
enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
40
41
SLAVE_EXEC_MODE_IDEMPOTENT,
41
42
SLAVE_EXEC_MODE_LAST_BIT};
98
99
class Key_part_spec :public Sql_alloc {
100
LEX_STRING field_name;
101
const LEX_STRING field_name;
102
103
Key_part_spec(const LEX_STRING &name, uint32_t len)
103
104
: field_name(name), length(len)
113
114
is why we supply it with a copy.
115
116
@return If out of memory, 0 is returned and an error is set in
118
119
Key_part_spec *clone(MEM_ROOT *mem_root) const
119
120
{ return new (mem_root) Key_part_spec(*this); }
215
216
virtual Key *clone(MEM_ROOT *mem_root) const
216
217
{ return new (mem_root) Foreign_key(*this, mem_root); }
218
/* Used to validate foreign key options */
219
bool validate(List<Create_field> &table_fields);
219
222
typedef struct st_mysql_lock
235
238
class select_result;
238
#define THD_SENTRY_MAGIC 0xfeedd1ff
239
#define THD_SENTRY_GONE 0xdeadbeef
241
#define Session_SENTRY_MAGIC 0xfeedd1ff
242
#define Session_SENTRY_GONE 0xdeadbeef
241
#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
244
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
243
246
struct system_variables
260
263
uint64_t myisam_max_sort_file_size;
261
264
uint64_t max_heap_table_size;
262
265
uint64_t tmp_table_size;
263
uint64_t long_query_time;
264
266
ha_rows select_limit;
265
267
ha_rows max_join_size;
266
268
ulong auto_increment_increment, auto_increment_offset;
313
313
ulong trans_prealloc_size;
314
314
ulong log_warnings;
315
315
ulong group_concat_max_len;
316
ulong binlog_format; // binlog format for this thd (see enum_binlog_format)
316
ulong binlog_format; // binlog format for this session (see enum_binlog_format)
318
318
In slave thread we need to know in behalf of which
319
319
thread the query is being run to replicate temp tables properly
498
498
One connection can contain a lot of simultaneously running statements,
499
499
some of which could be:
500
500
- prepared, that is, contain placeholders,
501
To perform some action with statement we reset THD part to the state of
502
that statement, do the action, and then save back modified state from THD
501
To perform some action with statement we reset Session part to the state of
502
that statement, do the action, and then save back modified state from Session
503
503
to the statement. It will be changed in near future, and Statement will
504
504
be used explicitly.
520
520
handler of fields used is set
521
521
MARK_COLUMNS_READ: Means a bit in read set is set to inform handler
522
522
that the field is to be read. If field list contains
523
duplicates, then thd->dup_field is set to point
523
duplicates, then session->dup_field is set to point
524
524
to the last found duplicate.
525
525
MARK_COLUMNS_WRITE: Means a bit is set in write set to inform handler
526
526
that it needs to update this field in write_row
539
539
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
540
540
non-NULL value if its previous value is NULL. We do not need to protect
541
541
operation (B) with any mutex. To avoid crashes in races, if we do not
542
know that thd->query cannot change at the moment, one should print
543
thd->query like this:
542
know that session->query cannot change at the moment, one should print
543
session->query like this:
544
544
(1) reserve the LOCK_thread_count mutex;
545
(2) check if thd->query is NULL;
546
(3) if not NULL, then print at most thd->query_length characters from
545
(2) check if session->query is NULL;
546
(3) if not NULL, then print at most session->query_length characters from
547
547
it. We will see the query_length field as either 0, or the right value
549
549
Assuming that the write and read of an n-bit memory field in an n-bit
563
563
valid database name.
565
565
@note this attribute is set and alloced by the slave SQL thread (for
566
the THD of that thread); that thread is (and must remain, for now) the
566
the Session of that thread); that thread is (and must remain, for now) the
567
567
only responsible for freeing this member.
593
593
/* For now, this is only used to catch duplicated external xids */
594
594
XID xid; // transaction identifier
595
595
enum xa_states xa_state; // used by external XA only
599
599
extern pthread_mutex_t LOCK_xid_cache;
690
690
Tables that were locked with explicit or implicit LOCK TABLES.
691
691
(Implicit LOCK TABLES happens when we are prelocking tables for
692
692
execution of statement which uses stored routines. See description
693
THD::prelocked_mode for more info.)
693
Session::prelocked_mode for more info.)
695
695
DRIZZLE_LOCK *locked_tables;
769
769
from the anticipated conditions trapped during runtime.
771
771
This mechanism is similar to C++ try/throw/catch:
772
- 'try' correspond to <code>THD::push_internal_handler()</code>,
772
- 'try' correspond to <code>Session::push_internal_handler()</code>,
773
773
- 'throw' correspond to <code>my_error()</code>,
774
774
which invokes <code>my_message_sql()</code>,
775
775
- 'catch' correspond to checking how/if an internal handler was invoked,
776
776
before removing it from the exception stack with
777
<code>THD::pop_internal_handler()</code>.
777
<code>Session::pop_internal_handler()</code>.
779
779
@param sql_errno the error number
780
780
@param level the error level
781
@param thd the calling thread
781
@param session the calling thread
782
782
@return true if the error is handled
784
784
virtual bool handle_error(uint32_t sql_errno,
785
785
const char *message,
786
786
DRIZZLE_ERROR::enum_warning_level level,
787
Session *session) = 0;
816
816
/** Set to make set_error_status after set_{ok,eof}_status possible. */
817
817
bool can_overwrite_status;
819
void set_ok_status(THD *thd, ha_rows affected_rows_arg,
819
void set_ok_status(Session *session, ha_rows affected_rows_arg,
820
820
uint64_t last_insert_id_arg,
821
821
const char *message);
822
void set_eof_status(THD *thd);
823
void set_error_status(THD *thd, uint32_t sql_errno_arg, const char *message_arg);
822
void set_eof_status(Session *session);
823
void set_error_status(Session *session, uint32_t sql_errno_arg, const char *message_arg);
825
825
void disable_status();
869
869
uint32_t m_sql_errno;
872
Copied from thd->server_status when the diagnostics area is assigned.
872
Copied from session->server_status when the diagnostics area is assigned.
873
873
We need this member as some places in the code use the following pattern:
874
thd->server_status|= ...
876
thd->server_status&= ~...
874
session->server_status|= ...
876
session->server_status&= ~...
877
877
Assigned by OK, EOF or ERROR.
879
879
uint32_t m_server_status;
881
881
The number of rows affected by the last statement. This is
882
semantically close to thd->row_count_func, but has a different
883
life cycle. thd->row_count_func stores the value returned by
882
semantically close to session->row_count_func, but has a different
883
life cycle. session->row_count_func stores the value returned by
884
884
function ROW_COUNT() and is cleared only by statements that
885
885
update its value, such as INSERT, UPDATE, DELETE and few others.
886
886
This member is cleared at the beginning of the next statement.
888
We could possibly merge the two, but life cycle of thd->row_count_func
888
We could possibly merge the two, but life cycle of session->row_count_func
889
889
can not be changed.
891
891
ha_rows m_affected_rows;
893
893
Similarly to the previous member, this is a replacement of
894
thd->first_successful_insert_id_in_prev_stmt, which is used
894
session->first_successful_insert_id_in_prev_stmt, which is used
895
895
to implement LAST_INSERT_ID().
897
897
uint64_t m_last_insert_id;
937
For each client connection we create a separate thread with THD serving as
937
For each client connection we create a separate thread with Session serving as
938
938
a thread/connection descriptor
941
class THD :public Statement,
941
class Session :public Statement,
942
942
public Open_tables_state
946
946
Relay_log_info* rli_fake;
949
Constant for THD::where initialization in the beginning of every query.
949
Constant for Session::where initialization in the beginning of every query.
951
It's needed because we do not save/restore THD::where normally during
951
It's needed because we do not save/restore Session::where normally during
952
952
primary (non subselect) query execution.
954
954
static const char * const DEFAULT_WHERE;
968
968
THR_LOCK_OWNER main_lock_id; // To use for conventional queries
969
969
THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to
970
970
// the lock_id of a cursor.
971
pthread_mutex_t LOCK_delete; // Locked before thd is deleted
971
pthread_mutex_t LOCK_delete; // Locked before session is deleted
973
973
A pointer to the stack frame of handle_one_connection(),
974
974
which is called first in the thread for handling a client
985
Some members of THD (currently 'Statement::db',
985
Some members of Session (currently 'Statement::db',
986
986
'catalog' and 'query') are set and alloced by the slave SQL thread
987
(for the THD of that thread); that thread is (and must remain, for now)
987
(for the Session of that thread); that thread is (and must remain, for now)
988
988
the only responsible for freeing these 3 members. If you add members
989
989
here, and you add code to set them in replication, don't forget to
990
990
free_them_and_set_them_to_0 in replication properly. For details see
1000
1000
Points to info-string that we show in SHOW PROCESSLIST
1001
You are supposed to call THD_SET_PROC_INFO only if you have coded
1001
You are supposed to call Session_SET_PROC_INFO only if you have coded
1002
1002
a time-consuming piece that MySQL can get stuck in for a long time.
1004
Set it using the thd_proc_info(THD *thread, const char *message)
1004
Set it using the session_proc_info(Session *thread, const char *message)
1005
1005
macro/function.
1007
1007
void set_proc_info(const char *info) { proc_info= info; }
1042
1042
thr_lock_type update_lock_default;
1044
/* <> 0 if we are inside of trigger or stored function. */
1045
uint32_t in_sub_stmt;
1047
1044
/* container for handler's private per-connection data */
1048
1045
Ha_data ha_data[MAX_HA];
1050
1047
/* Place to store various things */
1048
void *session_marker;
1052
1049
int binlog_setup_trx_data();
1104
1101
struct st_transactions {
1105
1102
SAVEPOINT *savepoints;
1106
THD_TRANS all; // Trans since BEGIN WORK
1107
THD_TRANS stmt; // Trans for current statement
1103
Session_TRANS all; // Trans since BEGIN WORK
1104
Session_TRANS stmt; // Trans for current statement
1108
1105
bool on; // see ha_enable_transaction()
1109
1106
XID_STATE xid_state;
1110
1107
Rows_log_event *m_pending_rows_event;
1135
1132
This is to track items changed during execution of a prepared
1136
1133
statement/stored procedure. It's created by
1137
register_item_tree_change() in memory root of THD, and freed in
1134
register_item_tree_change() in memory root of Session, and freed in
1138
1135
rollback_item_tree_changes(). For conventional execution it's always
1294
1291
The set of those tables whose fields are referenced in all subqueries
1296
TODO: possibly this it is incorrect to have used tables in THD because
1293
TODO: possibly this it is incorrect to have used tables in Session because
1297
1294
with more than one subquery, it is not clear what does the field mean.
1299
1296
table_map used_tables;
1369
1366
can not continue. In particular, disables activation of
1370
1367
CONTINUE or EXIT handlers of stored routines.
1371
1368
Reset in the end of processing of the current user request, in
1372
@see mysql_reset_thd_for_next_command().
1369
@see mysql_reset_session_for_next_command().
1374
1371
bool is_fatal_error;
1401
1398
it returned an error on master, and this is OK on the slave.
1403
1400
bool is_slave_error;
1404
bool bootstrap, cleanup_done;
1406
1403
/** is set if some thread specific value(s) used in a statement. */
1407
1404
bool thread_specific_used;
1408
1405
bool charset_is_system_charset, charset_is_collation_connection;
1409
1406
bool charset_is_character_set_filesystem;
1410
bool enable_slow_log; /* enable slow log for current statement */
1411
1407
bool abort_on_warning;
1412
1408
bool got_warning; /* Set on call to push_warning() */
1413
1409
bool no_warnings_for_error; /* no warnings on call to my_error() */
1467
1463
Lex_input_stream *m_lip;
1472
1468
void init(void);
1474
1470
Initialize memory roots necessary for query processing and (!)
1475
pre-allocate memory for it. We can't do that in THD constructor because
1471
pre-allocate memory for it. We can't do that in Session constructor because
1476
1472
there are use cases (acl_init, watcher threads,
1477
1473
killing mysqld) where it's vital to not allocate excessive and not used
1478
1474
memory. Note, that we still don't return error from init_for_queries():
1508
1504
int binlog_query(enum_binlog_query_type qtype,
1509
1505
char const *query, ulong query_len,
1510
1506
bool is_trans, bool suppress_use,
1511
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1507
Session::killed_state killed_err_arg= Session::KILLED_NO_VALUE);
1514
1510
For enter_cond() / exit_cond() to work the mutex must be got before
1522
1518
safe_mutex_assert_owner(mutex);
1523
1519
mysys_var->current_mutex = mutex;
1524
1520
mysys_var->current_cond = cond;
1525
thd_proc_info(this, msg);
1521
this->set_proc_info(msg);
1526
1522
return old_msg;
1528
1524
inline void exit_cond(const char* old_msg)
1531
1527
Putting the mutex unlock in exit_cond() ensures that
1532
1528
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
1533
1529
locked (if that would not be the case, you'll get a deadlock if someone
1534
does a THD::awake() on you).
1530
does a Session::awake() on you).
1536
1532
pthread_mutex_unlock(mysys_var->current_mutex);
1537
1533
pthread_mutex_lock(&mysys_var->mutex);
1538
1534
mysys_var->current_mutex = 0;
1539
1535
mysys_var->current_cond = 0;
1540
thd_proc_info(this, old_msg);
1536
this->set_proc_info(old_msg);
1541
1537
pthread_mutex_unlock(&mysys_var->mutex);
1543
1539
inline time_t query_start() { query_start_used=1; return start_time; }
1664
1660
inline void set_current_stmt_binlog_row_based_if_mixed()
1667
If in a stored/function trigger, the caller should already have done the
1668
change. We test in_sub_stmt to prevent introducing bugs where people
1669
wouldn't ensure that, and would switch to row-based mode in the middle
1670
of executing a stored function/trigger (which is too late, see also
1671
reset_current_stmt_binlog_row_based()); this condition will make their
1672
tests fail and so force them to propagate the
1673
lex->binlog_row_based_if_mixed upwards to the caller.
1675
if ((variables.binlog_format == BINLOG_FORMAT_MIXED) &&
1662
if (variables.binlog_format == BINLOG_FORMAT_MIXED)
1677
1663
current_stmt_binlog_row_based= true;
1679
1665
inline void set_current_stmt_binlog_row_based()
1692
1678
CREATE TEMPORARY TABLE t SELECT UUID(); # row-based
1693
1679
# and row-based does not store updates to temp tables
1694
1680
# in the binlog.
1695
INSERT INTO u SELECT * FROM t; # stmt-based
1696
and then the INSERT will fail as data inserted into t was not logged.
1697
So we continue with row-based until the temp table is dropped.
1698
If we are in a stored function or trigger, we mustn't reset in the
1699
middle of its execution (as the binary logging way of a stored function
1700
or trigger is decided when it starts executing, depending for example on
1701
the caller (for a stored function: if caller is SELECT or
1702
INSERT/UPDATE/DELETE...).
1704
1682
Don't reset binlog format for NDB binlog injector thread.
1706
if ((temporary_tables == NULL) && (in_sub_stmt == 0))
1684
if (temporary_tables == NULL)
1708
1686
current_stmt_binlog_row_based=
1709
1687
test(variables.binlog_format == BINLOG_FORMAT_ROW);
1821
/** A short cut for thd->main_da.set_ok_status(). */
1799
/** A short cut for session->main_da.set_ok_status(). */
1824
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
1802
my_ok(Session *session, ha_rows affected_rows= 0, uint64_t id= 0,
1825
1803
const char *message= NULL)
1827
thd->main_da.set_ok_status(thd, affected_rows, id, message);
1805
session->main_da.set_ok_status(session, affected_rows, id, message);
1831
/** A short cut for thd->main_da.set_eof_status(). */
1809
/** A short cut for session->main_da.set_eof_status(). */
1812
my_eof(Session *session)
1836
thd->main_da.set_eof_status(thd);
1814
session->main_da.set_eof_status(session);
1839
1817
#define tmp_disable_binlog(A) \
2054
2032
/* lock data for tmp table */
2055
2033
DRIZZLE_LOCK *m_lock;
2056
/* m_lock or thd->extra_lock */
2034
/* m_lock or session->extra_lock */
2057
2035
DRIZZLE_LOCK **m_plock;
2059
2037
select_create (TableList *table_arg,
2078
2056
virtual bool can_rollback_data() { return 1; }
2080
// Needed for access from local class MY_HOOKS in prepare(), since thd is proteted.
2081
const THD *get_thd(void) { return thd; }
2058
// Needed for access from local class MY_HOOKS in prepare(), since session is proteted.
2059
const Session *get_session(void) { return session; }
2082
2060
const HA_CREATE_INFO *get_create_info() { return create_info; };
2083
2061
int prepare2(void) { return 0; }
2165
2143
bool send_eof();
2167
2145
void cleanup();
2168
bool create_result_table(THD *thd, List<Item> *column_types,
2146
bool create_result_table(Session *session, List<Item> *column_types,
2169
2147
bool is_distinct, uint64_t options,
2170
2148
const char *alias, bool bit_fields_as_long);
2248
2226
LEX_STRING table;
2249
2227
SELECT_LEX_UNIT *sel;
2250
inline Table_ident(THD *thd, LEX_STRING db_arg, LEX_STRING table_arg,
2228
inline Table_ident(Session *session, LEX_STRING db_arg, LEX_STRING table_arg,
2252
2230
:table(table_arg), sel((SELECT_LEX_UNIT *)0)
2254
if (!force && (thd->client_capabilities & CLIENT_NO_SCHEMA))
2232
if (!force && (session->client_capabilities & CLIENT_NO_SCHEMA))