21
#ifndef DRIZZLED_SESSION_H
22
#define DRIZZLED_SESSION_H
21
24
/* Classes in mysql */
22
26
#include <drizzled/global.h>
24
#include "rpl_tblmap.h"
28
class Query_log_event;
30
class Slave_log_event;
27
#include <drizzled/protocol.h>
28
#include <libdrizzleclient/password.h> // rand_struct
29
#include <drizzled/sql_locale.h>
30
#include <drizzled/ha_trx_info.h>
31
#include <mysys/my_tree.h>
32
#include <drizzled/handler.h>
33
#include <drizzled/current_session.h>
34
#include <drizzled/sql_error.h>
35
#include <drizzled/query_arena.h>
36
#include <drizzled/file_exchange.h>
37
#include <drizzled/select_result_interceptor.h>
31
41
class Lex_input_stream;
34
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
35
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
36
enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
37
enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
38
DELAY_KEY_WRITE_ALL };
39
enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
40
SLAVE_EXEC_MODE_IDEMPOTENT,
41
SLAVE_EXEC_MODE_LAST_BIT};
42
enum enum_mark_columns
43
{ MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE};
44
enum enum_filetype { FILETYPE_CSV, FILETYPE_XML };
46
47
extern char internal_table_name[2];
47
48
extern char empty_c_string[1];
48
49
extern const char **errmesg;
50
#define TC_LOG_PAGE_SIZE 8192
51
#define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE)
53
51
#define TC_HEURISTIC_RECOVER_COMMIT 1
54
52
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
55
53
extern uint32_t tc_heuristic_recover;
57
typedef struct st_user_var_events
59
user_var_entry *user_var_event;
63
uint32_t charset_number;
64
} BINLOG_USER_VAR_EVENT;
66
#define RP_LOCK_LOG_IS_ALREADY_LOCKED 1
67
#define RP_FORCE_ROTATE 2
70
56
The COPY_INFO structure is used by INSERT/REPLACE code.
71
57
The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
98
class Key_part_spec :public Sql_alloc {
100
LEX_STRING field_name;
102
Key_part_spec(const LEX_STRING &name, uint32_t len)
103
: field_name(name), length(len)
105
Key_part_spec(const char *name, const size_t name_len, uint32_t len)
107
{ field_name.str= (char *)name; field_name.length= name_len; }
108
bool operator==(const Key_part_spec& other) const;
110
Construct a copy of this Key_part_spec. field_name is copied
111
by-pointer as it is known to never change. At the same time
112
'length' may be reset in mysql_prepare_create_table, and this
113
is why we supply it with a copy.
115
@return If out of memory, 0 is returned and an error is set in
118
Key_part_spec *clone(MEM_ROOT *mem_root) const
119
{ return new (mem_root) Key_part_spec(*this); }
123
class Alter_drop :public Sql_alloc {
125
enum drop_type {KEY, COLUMN };
128
Alter_drop(enum drop_type par_type,const char *par_name)
129
:name(par_name), type(par_type) {}
131
Used to make a clone of this object for ALTER/CREATE TABLE
132
@sa comment for Key_part_spec::clone
134
Alter_drop *clone(MEM_ROOT *mem_root) const
135
{ return new (mem_root) Alter_drop(*this); }
139
class Alter_column :public Sql_alloc {
143
Alter_column(const char *par_name,Item *literal)
144
:name(par_name), def(literal) {}
146
Used to make a clone of this object for ALTER/CREATE TABLE
147
@sa comment for Key_part_spec::clone
149
Alter_column *clone(MEM_ROOT *mem_root) const
150
{ return new (mem_root) Alter_column(*this); }
154
class Key :public Sql_alloc {
156
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
158
KEY_CREATE_INFO key_create_info;
159
List<Key_part_spec> columns;
163
Key(enum Keytype type_par, const LEX_STRING &name_arg,
164
KEY_CREATE_INFO *key_info_arg,
165
bool generated_arg, List<Key_part_spec> &cols)
166
:type(type_par), key_create_info(*key_info_arg), columns(cols),
167
name(name_arg), generated(generated_arg)
169
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
170
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
171
List<Key_part_spec> &cols)
172
:type(type_par), key_create_info(*key_info_arg), columns(cols),
173
generated(generated_arg)
175
name.str= (char *)name_arg;
176
name.length= name_len_arg;
178
Key(const Key &rhs, MEM_ROOT *mem_root);
180
/* Equality comparison of keys (ignoring name) */
181
friend bool foreign_key_prefix(Key *a, Key *b);
183
Used to make a clone of this object for ALTER/CREATE TABLE
184
@sa comment for Key_part_spec::clone
186
virtual Key *clone(MEM_ROOT *mem_root) const
187
{ return new (mem_root) Key(*this, mem_root); }
192
class Foreign_key: public Key {
194
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
195
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
196
enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
197
FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
199
Table_ident *ref_table;
200
List<Key_part_spec> ref_columns;
201
uint32_t delete_opt, update_opt, match_opt;
202
Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
203
Table_ident *table, List<Key_part_spec> &ref_cols,
204
uint32_t delete_opt_arg, uint32_t update_opt_arg, uint32_t match_opt_arg)
205
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
206
ref_table(table), ref_columns(ref_cols),
207
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
208
match_opt(match_opt_arg)
210
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
212
Used to make a clone of this object for ALTER/CREATE TABLE
213
@sa comment for Key_part_spec::clone
215
virtual Key *clone(MEM_ROOT *mem_root) const
216
{ return new (mem_root) Foreign_key(*this, mem_root); }
219
87
typedef struct st_mysql_lock
235
103
class select_result;
238
#define THD_SENTRY_MAGIC 0xfeedd1ff
239
#define THD_SENTRY_GONE 0xdeadbeef
106
#define Session_SENTRY_MAGIC 0xfeedd1ff
107
#define Session_SENTRY_GONE 0xdeadbeef
241
#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
109
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
243
111
struct system_variables
246
114
How dynamically allocated system variables are handled:
248
116
The global_system_variables and max_system_variables are "authoritative"
249
117
They both should have the same 'version' and 'size'.
250
118
When attempting to access a dynamic variable, if the session version
251
119
is out of date, then the session version is updated and realloced if
252
120
neccessary and bytes copied from global to make up for missing data.
254
122
ulong dynamic_variables_version;
255
123
char* dynamic_variables_ptr;
256
124
uint32_t dynamic_variables_head; /* largest valid variable offset */
257
125
uint32_t dynamic_variables_size; /* how many bytes are in use */
259
127
uint64_t myisam_max_extra_sort_file_size;
260
uint64_t myisam_max_sort_file_size;
261
128
uint64_t max_heap_table_size;
262
129
uint64_t tmp_table_size;
263
uint64_t long_query_time;
264
130
ha_rows select_limit;
265
131
ha_rows max_join_size;
266
ulong auto_increment_increment, auto_increment_offset;
267
ulong bulk_insert_buff_size;
268
ulong join_buff_size;
269
ulong max_allowed_packet;
270
ulong max_error_count;
271
ulong max_length_for_sort_data;
272
ulong max_sort_length;
273
ulong max_tmp_tables;
274
ulong min_examined_row_limit;
275
ulong myisam_repair_threads;
276
ulong myisam_sort_buff_size;
277
ulong myisam_stats_method;
278
ulong net_buffer_length;
279
ulong net_interactive_timeout;
280
ulong net_read_timeout;
281
ulong net_retry_count;
282
ulong net_wait_timeout;
283
ulong net_write_timeout;
284
ulong optimizer_prune_level;
285
ulong optimizer_search_depth;
132
uint64_t auto_increment_increment;
133
uint64_t auto_increment_offset;
134
uint64_t bulk_insert_buff_size;
135
uint64_t join_buff_size;
136
uint32_t max_allowed_packet;
137
uint64_t max_error_count;
138
uint64_t max_length_for_sort_data;
139
uint64_t max_sort_length;
140
uint64_t max_tmp_tables;
141
uint64_t min_examined_row_limit;
142
uint32_t myisam_stats_method;
143
uint32_t net_buffer_length;
144
uint32_t net_interactive_timeout;
145
uint32_t net_read_timeout;
146
uint32_t net_retry_count;
147
uint32_t net_wait_timeout;
148
uint32_t net_write_timeout;
149
bool optimizer_prune_level;
150
uint32_t optimizer_search_depth;
287
152
Controls use of Engine-MRR:
288
153
0 - auto, based on cost
289
154
1 - force MRR when the storage engine is capable of doing it
292
ulong optimizer_use_mrr;
157
uint32_t optimizer_use_mrr;
293
158
/* A bitmap for switching optimizations on/off */
294
ulong optimizer_switch;
295
ulong preload_buff_size;
296
ulong profiling_history_size;
297
ulong query_cache_type;
298
ulong read_buff_size;
299
ulong read_rnd_buff_size;
300
ulong div_precincrement;
302
ulong thread_handling;
304
ulong completion_type;
159
uint32_t optimizer_switch;
160
uint64_t preload_buff_size;
161
uint32_t read_buff_size;
162
uint32_t read_rnd_buff_size;
163
uint32_t div_precincrement;
164
size_t sortbuff_size;
165
uint32_t thread_handling;
166
uint32_t tx_isolation;
167
uint32_t completion_type;
305
168
/* Determines which non-standard SQL behaviour should be enabled */
307
ulong default_week_format;
308
ulong max_seeks_for_key;
309
ulong range_alloc_block_size;
310
ulong query_alloc_block_size;
311
ulong query_prealloc_size;
312
ulong trans_alloc_block_size;
313
ulong trans_prealloc_size;
315
ulong group_concat_max_len;
316
ulong binlog_format; // binlog format for this thd (see enum_binlog_format)
318
In slave thread we need to know in behalf of which
319
thread the query is being run to replicate temp tables properly
321
my_thread_id pseudo_thread_id;
170
uint64_t max_seeks_for_key;
171
size_t range_alloc_block_size;
172
uint32_t query_alloc_block_size;
173
uint32_t query_prealloc_size;
174
uint32_t trans_alloc_block_size;
175
uint32_t trans_prealloc_size;
177
uint64_t group_concat_max_len;
178
/* TODO: change this to my_thread_id - but have to fix set_var first */
179
uint64_t pseudo_thread_id;
323
181
bool low_priority_updates;
326
184
compatibility option:
327
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
185
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
330
188
bool engine_condition_pushdown;
441
295
#define last_system_status_var questions
443
void mark_transaction_to_rollback(THD *thd, bool all);
445
#ifdef DRIZZLE_SERVER
451
List of items created in the parser for this query. Every item puts
452
itself to the list on creation (see Item::Item() for details))
455
MEM_ROOT *mem_root; // Pointer to current memroot
457
Query_arena(MEM_ROOT *mem_root_arg) :
458
free_list(0), mem_root(mem_root_arg)
461
This constructor is used only when Query_arena is created as
462
backup storage for another instance of Query_arena.
466
virtual ~Query_arena() {};
468
inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
469
inline void* calloc(size_t size)
472
if ((ptr=alloc_root(mem_root,size)))
473
memset(ptr, 0, size);
476
inline char *strdup(const char *str)
477
{ return strdup_root(mem_root,str); }
478
inline char *strmake(const char *str, size_t size)
479
{ return strmake_root(mem_root,str,size); }
480
inline void *memdup(const void *str, size_t size)
481
{ return memdup_root(mem_root,str,size); }
482
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
485
if ((ptr= alloc_root(mem_root,size+gap)))
486
memcpy(ptr,str,size);
297
void mark_transaction_to_rollback(Session *session, bool all);
539
344
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
540
345
non-NULL value if its previous value is NULL. We do not need to protect
541
346
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:
347
know that session->query cannot change at the moment, one should print
348
session->query like this:
544
349
(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
350
(2) check if session->query is NULL;
351
(3) if not NULL, then print at most session->query_length characters from
547
352
it. We will see the query_length field as either 0, or the right value
549
354
Assuming that the write and read of an n-bit memory field in an n-bit
550
computer is atomic, we can avoid races in the above way.
355
computer is atomic, we can avoid races in the above way.
551
356
This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
769
572
from the anticipated conditions trapped during runtime.
771
574
This mechanism is similar to C++ try/throw/catch:
772
- 'try' correspond to <code>THD::push_internal_handler()</code>,
575
- 'try' correspond to <code>Session::push_internal_handler()</code>,
773
576
- 'throw' correspond to <code>my_error()</code>,
774
577
which invokes <code>my_message_sql()</code>,
775
578
- 'catch' correspond to checking how/if an internal handler was invoked,
776
579
before removing it from the exception stack with
777
<code>THD::pop_internal_handler()</code>.
580
<code>Session::pop_internal_handler()</code>.
779
582
@param sql_errno the error number
780
583
@param level the error level
781
@param thd the calling thread
584
@param session the calling thread
782
585
@return true if the error is handled
784
587
virtual bool handle_error(uint32_t sql_errno,
785
588
const char *message,
786
589
DRIZZLE_ERROR::enum_warning_level level,
590
Session *session) = 0;
869
672
uint32_t m_sql_errno;
872
Copied from thd->server_status when the diagnostics area is assigned.
675
Copied from session->server_status when the diagnostics area is assigned.
873
676
We need this member as some places in the code use the following pattern:
874
thd->server_status|= ...
876
thd->server_status&= ~...
677
session->server_status|= ...
679
session->server_status&= ~...
877
680
Assigned by OK, EOF or ERROR.
879
682
uint32_t m_server_status;
881
684
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
685
semantically close to session->row_count_func, but has a different
686
life cycle. session->row_count_func stores the value returned by
884
687
function ROW_COUNT() and is cleared only by statements that
885
688
update its value, such as INSERT, UPDATE, DELETE and few others.
886
689
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
691
We could possibly merge the two, but life cycle of session->row_count_func
889
692
can not be changed.
891
694
ha_rows m_affected_rows;
893
696
Similarly to the previous member, this is a replacement of
894
thd->first_successful_insert_id_in_prev_stmt, which is used
697
session->first_successful_insert_id_in_prev_stmt, which is used
895
698
to implement LAST_INSERT_ID().
897
700
uint64_t m_last_insert_id;
1038
837
time_t start_time, user_time;
1039
838
uint64_t connect_utime, thr_create_utime; // track down slow pthread_create
1040
839
uint64_t start_utime, utime_after_lock;
1042
841
thr_lock_type update_lock_default;
1044
/* <> 0 if we are inside of trigger or stored function. */
1045
uint32_t in_sub_stmt;
844
Both of the following container points in session will be converted to an API.
1047
847
/* container for handler's private per-connection data */
1048
848
Ha_data ha_data[MAX_HA];
850
/* container for replication data */
851
void *replication_data;
852
inline void setReplicationData (void *data) { replication_data= data; }
853
inline void *getReplicationData () { return replication_data; }
1050
855
/* Place to store various things */
1052
int binlog_setup_trx_data();
1055
Public interface to write RBR events to the binlog
1057
void binlog_start_trans_and_stmt();
1058
void binlog_set_stmt_begin();
1059
int binlog_write_table_map(Table *table, bool is_transactional);
1060
int binlog_write_row(Table* table, bool is_transactional,
1061
const unsigned char *new_data);
1062
int binlog_delete_row(Table* table, bool is_transactional,
1063
const unsigned char *old_data);
1064
int binlog_update_row(Table* table, bool is_transactional,
1065
const unsigned char *old_data, const unsigned char *new_data);
856
void *session_marker;
1067
858
void set_server_id(uint32_t sid) { server_id = sid; }
1070
Member functions to handle pending event for row-level logging.
1072
template <class RowsEventT> Rows_log_event*
1073
binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
1075
bool is_transactional,
1077
Rows_log_event* binlog_get_pending_rows_event() const;
1078
void binlog_set_pending_rows_event(Rows_log_event* ev);
1079
int binlog_flush_pending_rows_event(bool stmt_end);
1082
uint32_t binlog_table_maps; // Number of table maps currently in the binlog
1084
enum enum_binlog_flag {
1085
BINLOG_FLAG_UNSAFE_STMT_PRINTED,
1090
Flags with per-thread information regarding the status of the
1093
uint32_t binlog_flags;
1095
uint32_t get_binlog_table_maps() const {
1096
return binlog_table_maps;
1098
void clear_binlog_table_maps() {
1099
binlog_table_maps= 0;
1104
862
struct st_transactions {
1105
863
SAVEPOINT *savepoints;
1106
THD_TRANS all; // Trans since BEGIN WORK
1107
THD_TRANS stmt; // Trans for current statement
864
Session_TRANS all; // Trans since BEGIN WORK
865
Session_TRANS stmt; // Trans for current statement
1108
866
bool on; // see ha_enable_transaction()
1109
867
XID_STATE xid_state;
1110
Rows_log_event *m_pending_rows_event;
1113
870
Tables changed in transaction (that must be invalidated in query cache).
1186
936
first_successful_insert_id_in_cur_stmt.
1189
stmt_depends_on_first_successful_insert_id_in_prev_stmt is set when
1190
LAST_INSERT_ID() is used by a statement.
1191
If it is set, first_successful_insert_id_in_prev_stmt_for_binlog will be
1192
stored in the statement-based binlog.
1193
This variable is CUMULATIVE along the execution of a stored function or
1194
trigger: if one substatement sets it to 1 it will stay 1 until the
1195
function/trigger ends, thus making sure that
1196
first_successful_insert_id_in_prev_stmt_for_binlog does not change anymore
1197
and is propagated to the caller for binlogging.
1199
bool stmt_depends_on_first_successful_insert_id_in_prev_stmt;
1201
939
List of auto_increment intervals reserved by the thread so far, for
1202
940
storage in the statement-based binlog.
1203
941
Note that its minimum is not first_successful_insert_id_in_cur_stmt:
1390
1115
Reset to false when we leave the sub-statement mode.
1392
1117
bool is_fatal_sub_stmt_error;
1393
bool query_start_used, rand_used, time_zone_used;
1394
1118
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
1395
1119
bool substitute_null_with_insert_id;
1396
1120
bool in_lock_tables;
1398
True if a slave error. Causes the slave to stop. Not the same
1399
as the statement execution error (is_error()), since
1400
a statement may be expected to return an error, e.g. because
1401
it returned an error on master, and this is OK on the slave.
1403
bool is_slave_error;
1404
bool bootstrap, cleanup_done;
1406
1123
/** is set if some thread specific value(s) used in a statement. */
1407
1124
bool thread_specific_used;
1408
1125
bool charset_is_system_charset, charset_is_collation_connection;
1409
1126
bool charset_is_character_set_filesystem;
1410
bool enable_slow_log; /* enable slow log for current statement */
1411
1127
bool abort_on_warning;
1412
1128
bool got_warning; /* Set on call to push_warning() */
1413
1129
bool no_warnings_for_error; /* no warnings on call to my_error() */
1430
1139
ulong ulong_value;
1431
1140
uint64_t uint64_t_value;
1436
If true, mysql_bin_log::write(Log_event) call will not write events to
1437
binlog, and maintain 2 below variables instead (use
1438
mysql_bin_log.start_union_events to turn this on)
1442
If true, at least one mysql_bin_log::write(Log_event) call has been
1443
made after last mysql_bin_log.start_union_events() call.
1445
bool unioned_events;
1447
If true, at least one mysql_bin_log::write(Log_event e), where
1448
e.cache_stmt == true call has been made after last
1449
mysql_bin_log.start_union_events() call.
1451
bool unioned_events_trans;
1454
'queries' (actually SP statements) that run under inside this binlog
1455
union have thd->query_id >= first_query_id.
1457
query_id_t first_query_id;
1461
1144
Character input stream consumed by the lexical analyser,
1467
1150
Lex_input_stream *m_lip;
1472
1155
void init(void);
1474
1157
Initialize memory roots necessary for query processing and (!)
1475
pre-allocate memory for it. We can't do that in THD constructor because
1158
pre-allocate memory for it. We can't do that in Session constructor because
1476
1159
there are use cases (acl_init, watcher threads,
1477
1160
killing mysqld) where it's vital to not allocate excessive and not used
1478
1161
memory. Note, that we still don't return error from init_for_queries():
1479
1162
if preallocation fails, we should notice that at the first call to
1482
1165
void init_for_queries();
1483
void change_user(void);
1484
1166
void cleanup(void);
1485
1167
void cleanup_after_query();
1486
1168
bool store_globals();
1487
void awake(THD::killed_state state_to_set);
1489
enum enum_binlog_query_type {
1491
The query can be logged row-based or statement-based
1496
The query has to be logged statement-based
1501
The query represents a change to a table in the "mysql"
1502
database and is currently mapped to ROW_QUERY_TYPE.
1508
int binlog_query(enum_binlog_query_type qtype,
1509
char const *query, ulong query_len,
1510
bool is_trans, bool suppress_use,
1511
THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
1169
void awake(Session::killed_state state_to_set);
1514
1172
For enter_cond() / exit_cond() to work the mutex must be got before
1515
1173
enter_cond(); this mutex is then released by exit_cond().
1516
1174
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
1518
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
1176
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
1521
1178
const char* old_msg = get_proc_info();
1522
1179
safe_mutex_assert_owner(mutex);
1523
1180
mysys_var->current_mutex = mutex;
1524
1181
mysys_var->current_cond = cond;
1525
thd_proc_info(this, msg);
1182
this->set_proc_info(msg);
1526
1183
return old_msg;
1528
1185
inline void exit_cond(const char* old_msg)
1661
1317
void reset_n_backup_open_tables_state(Open_tables_state *backup);
1662
1318
void restore_backup_open_tables_state(Open_tables_state *backup);
1664
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) &&
1677
current_stmt_binlog_row_based= true;
1679
inline void set_current_stmt_binlog_row_based()
1681
current_stmt_binlog_row_based= true;
1683
inline void clear_current_stmt_binlog_row_based()
1685
current_stmt_binlog_row_based= false;
1687
inline void reset_current_stmt_binlog_row_based()
1690
If there are temporary tables, don't reset back to
1691
statement-based. Indeed it could be that:
1692
CREATE TEMPORARY TABLE t SELECT UUID(); # row-based
1693
# and row-based does not store updates to temp tables
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
Don't reset binlog format for NDB binlog injector thread.
1706
if ((temporary_tables == NULL) && (in_sub_stmt == 0))
1708
current_stmt_binlog_row_based=
1709
test(variables.binlog_format == BINLOG_FORMAT_ROW);
1714
1321
Set the current database; use deep copy of C-string.
1815
1418
tree itself is reused between executions and thus is stored elsewhere.
1817
1420
MEM_ROOT main_mem_root;
1821
/** A short cut for thd->main_da.set_ok_status(). */
1824
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
1825
const char *message= NULL)
1827
thd->main_da.set_ok_status(thd, affected_rows, id, message);
1831
/** A short cut for thd->main_da.set_eof_status(). */
1836
thd->main_da.set_eof_status(thd);
1839
#define tmp_disable_binlog(A) \
1840
{uint64_t tmp_disable_binlog__save_options= (A)->options; \
1841
(A)->options&= ~OPTION_BIN_LOG
1843
#define reenable_binlog(A) (A)->options= tmp_disable_binlog__save_options;}
1847
Used to hold information about file and file structure in exchange
1848
via non-DB file (...INTO OUTFILE..., ...LOAD DATA...)
1849
XXX: We never call destructor for objects of this class.
1852
class sql_exchange :public Sql_alloc
1855
enum enum_filetype filetype; /* load XML, Added by Arnold & Erik */
1857
String *field_term,*enclosed,*line_term,*line_start,*escaped;
1861
const CHARSET_INFO *cs;
1862
sql_exchange(char *name, bool dumpfile_flag,
1863
enum_filetype filetype_arg= FILETYPE_CSV);
1423
/** A short cut for session->main_da.set_ok_status(). */
1424
inline void my_ok(ha_rows affected_rows= 0, uint64_t passed_id= 0, const char *message= NULL)
1426
main_da.set_ok_status(this, affected_rows, passed_id, message);
1430
/** A short cut for session->main_da.set_eof_status(). */
1432
inline void my_eof()
1434
main_da.set_eof_status(this);
1866
#include "log_event.h"
1869
1439
This is used to get result from a select
1874
class select_result :public Sql_alloc {
1877
SELECT_LEX_UNIT *unit;
1880
virtual ~select_result() {};
1881
virtual int prepare(List<Item> &list __attribute__((unused)),
1887
virtual int prepare2(void) { return 0; }
1889
Because of peculiarities of prepared statements protocol
1890
we need to know number of columns in the result set (if
1891
there is a result set) apart from sending columns metadata.
1893
virtual uint32_t field_count(List<Item> &fields) const
1894
{ return fields.elements; }
1895
virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
1896
virtual bool send_data(List<Item> &items)=0;
1897
virtual bool initialize_tables (JOIN __attribute__((unused)) *join=0)
1899
virtual void send_error(uint32_t errcode,const char *err);
1900
virtual bool send_eof()=0;
1902
Check if this query returns a result set and therefore is allowed in
1903
cursors and set an error message if it is not the case.
1905
@retval false success
1906
@retval true error, an error message is set
1908
virtual bool check_simple_select() const;
1909
virtual void abort() {}
1911
Cleanup instance of this class for next execution of a prepared
1912
statement/stored procedure.
1914
virtual void cleanup();
1915
void set_thd(THD *thd_arg) { thd= thd_arg; }
1916
void begin_dataset() {}
1921
Base class for select_result descendands which intercept and
1922
transform result set rows. As the rows are not sent to the client,
1923
sending of result set metadata should be suppressed as well.
1926
class select_result_interceptor: public select_result
1929
select_result_interceptor() {} /* Remove gcc warning */
1930
uint32_t field_count(List<Item> &fields __attribute__((unused))) const
1932
bool send_fields(List<Item> &fields __attribute__((unused)),
1933
uint32_t flag __attribute__((unused))) { return false; }
1937
class select_send :public select_result {
1939
True if we have sent result set metadata to the client.
1940
In this case the client always expects us to end the result
1941
set with an eof or error packet
1943
bool is_result_set_started;
1945
select_send() :is_result_set_started(false) {}
1946
bool send_fields(List<Item> &list, uint32_t flags);
1947
bool send_data(List<Item> &items);
1949
virtual bool check_simple_select() const { return false; }
1951
virtual void cleanup();
1955
1445
class select_to_file :public select_result_interceptor {
1957
sql_exchange *exchange;
1447
file_exchange *exchange;
1959
1449
IO_CACHE cache;
1960
1450
ha_rows row_count;
1961
1451
char path[FN_REFLEN];
1964
select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1454
select_to_file(file_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1966
1456
~select_to_file();
1967
1457
void send_error(uint32_t errcode,const char *err);
2071
1561
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2073
void binlog_show_create_table(Table **tables, uint32_t count);
2074
1563
void store_values(List<Item> &values);
2075
1564
void send_error(uint32_t errcode,const char *err);
2076
1565
bool send_eof();
2078
1567
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; }
1569
// Needed for access from local class MY_HOOKS in prepare(), since session is proteted.
1570
const Session *get_session(void) { return session; }
2082
1571
const HA_CREATE_INFO *get_create_info() { return create_info; };
2083
1572
int prepare2(void) { return 0; }
2086
1575
#include <storage/myisam/myisam.h>
2089
Param to create temporary tables when doing SELECT:s
1578
Param to create temporary tables when doing SELECT:s
2091
1580
This structure is copied using memcpy as a part of JOIN.
2336
1818
bool get(Table *table);
2337
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
2338
uint64_t max_in_memory_size);
2339
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
2340
uint64_t max_in_memory_size)
1819
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
1820
size_t max_in_memory_size);
1821
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
1822
size_t max_in_memory_size)
2342
register uint64_t max_elems_in_tree=
1824
register size_t max_elems_in_tree=
2343
1825
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
2344
1826
return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
2447
1929
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2448
1930
bool send_data(List<Item> &items);
2449
1931
bool send_eof();
2450
virtual bool check_simple_select() const;
2451
1932
void cleanup();
2454
1935
/* Bits in sql_command_flags */
2456
#define CF_CHANGES_DATA 1
2457
#define CF_HAS_ROW_COUNT 2
2458
#define CF_STATUS_COMMAND 4
2459
#define CF_SHOW_TABLE_COMMAND 8
2460
#define CF_WRITE_LOGS_COMMAND 16
1937
enum sql_command_flag_bits {
1938
CF_BIT_CHANGES_DATA,
1939
CF_BIT_HAS_ROW_COUNT,
1940
CF_BIT_STATUS_COMMAND,
1941
CF_BIT_SHOW_TABLE_COMMAND,
1942
CF_BIT_WRITE_LOGS_COMMAND,
1946
static const std::bitset<CF_BIT_SIZE> CF_CHANGES_DATA(1 << CF_BIT_CHANGES_DATA);
1947
static const std::bitset<CF_BIT_SIZE> CF_HAS_ROW_COUNT(1 << CF_BIT_HAS_ROW_COUNT);
1948
static const std::bitset<CF_BIT_SIZE> CF_STATUS_COMMAND(1 << CF_BIT_STATUS_COMMAND);
1949
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1950
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
2462
1952
/* Functions in sql_class.cc */
2466
1956
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2467
1957
STATUS_VAR *dec_var);
2469
#endif /* DRIZZLE_SERVER */
1959
/* Some inline functions for more speed */
1961
inline bool add_item_to_list(Session *session, Item *item)
1963
return session->lex->current_select->add_item_to_list(session, item);
1966
inline bool add_value_to_list(Session *session, Item *value)
1968
return session->lex->value_list.push_back(value);
1971
inline bool add_order_to_list(Session *session, Item *item, bool asc)
1973
return session->lex->current_select->add_order_to_list(session, item, asc);
1976
inline bool add_group_to_list(Session *session, Item *item, bool asc)
1978
return session->lex->current_select->add_group_to_list(session, item, asc);
1981
#endif /* DRIZZLED_SQL_CLASS_H */