1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef DRIZZLED_SESSION_H
22
#define DRIZZLED_SESSION_H
17
24
/* Classes in mysql */
18
26
#include <drizzled/global.h>
20
#include "rpl_tblmap.h"
27
#include <drizzled/log.h>
28
#include <drizzled/replication/tblmap.h>
29
#include <drizzled/protocol.h>
30
#include <libdrizzle/password.h> // rand_struct
31
#include <drizzled/sql_locale.h>
32
#include <drizzled/scheduler.h>
33
#include <drizzled/ha_trx_info.h>
34
#include <mysys/my_tree.h>
35
#include <drizzled/handler.h>
36
#include <drizzled/current_session.h>
37
#include <drizzled/sql_error.h>
38
#include <drizzled/query_arena.h>
22
42
class Relay_log_info;
26
46
class Slave_log_event;
27
47
class Lex_input_stream;
28
48
class Rows_log_event;
30
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
31
enum enum_ha_read_modes { RFIRST, RNEXT, RPREV, RLAST, RKEY, RNEXT_SAME };
32
enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
33
enum enum_delay_key_write { DELAY_KEY_WRITE_NONE, DELAY_KEY_WRITE_ON,
34
DELAY_KEY_WRITE_ALL };
35
enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT,
36
SLAVE_EXEC_MODE_IDEMPOTENT,
37
SLAVE_EXEC_MODE_LAST_BIT};
38
enum enum_mark_columns
39
{ MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE};
40
enum enum_filetype { FILETYPE_CSV, FILETYPE_XML };
42
54
extern char internal_table_name[2];
43
55
extern char empty_c_string[1];
94
class Key_part_spec :public Sql_alloc {
96
LEX_STRING field_name;
98
Key_part_spec(const LEX_STRING &name, uint len)
99
: field_name(name), length(len)
101
Key_part_spec(const char *name, const size_t name_len, uint len)
103
{ field_name.str= (char *)name; field_name.length= name_len; }
104
bool operator==(const Key_part_spec& other) const;
106
Construct a copy of this Key_part_spec. field_name is copied
107
by-pointer as it is known to never change. At the same time
108
'length' may be reset in mysql_prepare_create_table, and this
109
is why we supply it with a copy.
111
@return If out of memory, 0 is returned and an error is set in
114
Key_part_spec *clone(MEM_ROOT *mem_root) const
115
{ return new (mem_root) Key_part_spec(*this); }
119
class Alter_drop :public Sql_alloc {
121
enum drop_type {KEY, COLUMN };
124
Alter_drop(enum drop_type par_type,const char *par_name)
125
:name(par_name), type(par_type) {}
127
Used to make a clone of this object for ALTER/CREATE TABLE
128
@sa comment for Key_part_spec::clone
130
Alter_drop *clone(MEM_ROOT *mem_root) const
131
{ return new (mem_root) Alter_drop(*this); }
135
class Alter_column :public Sql_alloc {
139
Alter_column(const char *par_name,Item *literal)
140
:name(par_name), def(literal) {}
142
Used to make a clone of this object for ALTER/CREATE TABLE
143
@sa comment for Key_part_spec::clone
145
Alter_column *clone(MEM_ROOT *mem_root) const
146
{ return new (mem_root) Alter_column(*this); }
150
class Key :public Sql_alloc {
152
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
154
KEY_CREATE_INFO key_create_info;
155
List<Key_part_spec> columns;
159
Key(enum Keytype type_par, const LEX_STRING &name_arg,
160
KEY_CREATE_INFO *key_info_arg,
161
bool generated_arg, List<Key_part_spec> &cols)
162
:type(type_par), key_create_info(*key_info_arg), columns(cols),
163
name(name_arg), generated(generated_arg)
165
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
166
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
167
List<Key_part_spec> &cols)
168
:type(type_par), key_create_info(*key_info_arg), columns(cols),
169
generated(generated_arg)
171
name.str= (char *)name_arg;
172
name.length= name_len_arg;
174
Key(const Key &rhs, MEM_ROOT *mem_root);
176
/* Equality comparison of keys (ignoring name) */
177
friend bool foreign_key_prefix(Key *a, Key *b);
179
Used to make a clone of this object for ALTER/CREATE TABLE
180
@sa comment for Key_part_spec::clone
182
virtual Key *clone(MEM_ROOT *mem_root) const
183
{ return new (mem_root) Key(*this, mem_root); }
188
class Foreign_key: public Key {
190
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
191
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
192
enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
193
FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
195
Table_ident *ref_table;
196
List<Key_part_spec> ref_columns;
197
uint delete_opt, update_opt, match_opt;
198
Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
199
Table_ident *table, List<Key_part_spec> &ref_cols,
200
uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg)
201
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
202
ref_table(table), ref_columns(ref_cols),
203
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
204
match_opt(match_opt_arg)
206
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
208
Used to make a clone of this object for ALTER/CREATE TABLE
209
@sa comment for Key_part_spec::clone
211
virtual Key *clone(MEM_ROOT *mem_root) const
212
{ return new (mem_root) Foreign_key(*this, mem_root); }
215
109
typedef struct st_mysql_lock
218
uint table_count,lock_count;
112
uint32_t table_count,lock_count;
219
113
THR_LOCK_DATA **locks;
228
122
LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {}
231
#include "sql_lex.h" /* Must be here */
233
125
class select_result;
236
#define THD_SENTRY_MAGIC 0xfeedd1ff
237
#define THD_SENTRY_GONE 0xdeadbeef
128
#define Session_SENTRY_MAGIC 0xfeedd1ff
129
#define Session_SENTRY_GONE 0xdeadbeef
239
#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
131
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
241
133
struct system_variables
244
136
How dynamically allocated system variables are handled:
246
138
The global_system_variables and max_system_variables are "authoritative"
247
139
They both should have the same 'version' and 'size'.
248
140
When attempting to access a dynamic variable, if the session version
249
141
is out of date, then the session version is updated and realloced if
250
142
neccessary and bytes copied from global to make up for missing data.
252
144
ulong dynamic_variables_version;
253
145
char* dynamic_variables_ptr;
254
uint dynamic_variables_head; /* largest valid variable offset */
255
uint dynamic_variables_size; /* how many bytes are in use */
146
uint32_t dynamic_variables_head; /* largest valid variable offset */
147
uint32_t dynamic_variables_size; /* how many bytes are in use */
257
149
uint64_t myisam_max_extra_sort_file_size;
258
150
uint64_t myisam_max_sort_file_size;
259
151
uint64_t max_heap_table_size;
260
152
uint64_t tmp_table_size;
261
uint64_t long_query_time;
262
153
ha_rows select_limit;
263
154
ha_rows max_join_size;
264
ulong auto_increment_increment, auto_increment_offset;
265
ulong bulk_insert_buff_size;
266
ulong join_buff_size;
267
ulong max_allowed_packet;
268
ulong max_error_count;
269
ulong max_length_for_sort_data;
270
ulong max_sort_length;
271
ulong max_tmp_tables;
272
ulong min_examined_row_limit;
273
ulong myisam_repair_threads;
274
ulong myisam_sort_buff_size;
275
ulong myisam_stats_method;
276
ulong net_buffer_length;
277
ulong net_interactive_timeout;
278
ulong net_read_timeout;
279
ulong net_retry_count;
280
ulong net_wait_timeout;
281
ulong net_write_timeout;
282
ulong optimizer_prune_level;
283
ulong optimizer_search_depth;
155
uint32_t auto_increment_increment;
156
uint32_t auto_increment_offset;
157
uint64_t bulk_insert_buff_size;
158
uint64_t join_buff_size;
159
uint32_t max_allowed_packet;
160
uint64_t max_error_count;
161
uint64_t max_length_for_sort_data;
162
uint64_t max_sort_length;
163
uint64_t max_tmp_tables;
164
uint64_t min_examined_row_limit;
165
uint32_t myisam_repair_threads;
166
size_t myisam_sort_buff_size;
167
uint32_t myisam_stats_method;
168
uint32_t net_buffer_length;
169
uint32_t net_interactive_timeout;
170
uint32_t net_read_timeout;
171
uint32_t net_retry_count;
172
uint32_t net_wait_timeout;
173
uint32_t net_write_timeout;
174
bool optimizer_prune_level;
175
uint32_t optimizer_search_depth;
285
177
Controls use of Engine-MRR:
286
178
0 - auto, based on cost
287
179
1 - force MRR when the storage engine is capable of doing it
290
ulong optimizer_use_mrr;
182
uint32_t optimizer_use_mrr;
291
183
/* A bitmap for switching optimizations on/off */
292
ulong optimizer_switch;
293
ulong preload_buff_size;
294
ulong profiling_history_size;
295
ulong query_cache_type;
296
ulong read_buff_size;
297
ulong read_rnd_buff_size;
298
ulong div_precincrement;
300
ulong thread_handling;
302
ulong completion_type;
184
uint32_t optimizer_switch;
185
uint64_t preload_buff_size;
186
uint32_t read_buff_size;
187
uint32_t read_rnd_buff_size;
188
uint32_t div_precincrement;
189
size_t sortbuff_size;
190
uint32_t thread_handling;
191
uint32_t tx_isolation;
192
uint32_t completion_type;
303
193
/* Determines which non-standard SQL behaviour should be enabled */
305
ulong default_week_format;
306
ulong max_seeks_for_key;
307
ulong range_alloc_block_size;
308
ulong query_alloc_block_size;
309
ulong query_prealloc_size;
310
ulong trans_alloc_block_size;
311
ulong trans_prealloc_size;
313
ulong group_concat_max_len;
314
ulong binlog_format; // binlog format for this thd (see enum_binlog_format)
195
uint32_t default_week_format;
196
uint64_t max_seeks_for_key;
197
size_t range_alloc_block_size;
198
uint32_t query_alloc_block_size;
199
uint32_t query_prealloc_size;
200
uint32_t trans_alloc_block_size;
201
uint32_t trans_prealloc_size;
203
uint64_t group_concat_max_len;
316
205
In slave thread we need to know in behalf of which
317
206
thread the query is being run to replicate temp tables properly
319
my_thread_id pseudo_thread_id;
208
/* TODO: change this to my_thread_id - but have to fix set_var first */
209
uint64_t pseudo_thread_id;
321
211
bool low_priority_updates;
324
214
compatibility option:
325
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
215
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
328
218
bool engine_condition_pushdown;
438
330
#define last_system_status_var questions
440
void mark_transaction_to_rollback(THD *thd, bool all);
332
void mark_transaction_to_rollback(Session *session, bool all);
442
334
#ifdef DRIZZLE_SERVER
444
#define INIT_ARENA_DBUG_INFO is_backup_arena= 0
450
List of items created in the parser for this query. Every item puts
451
itself to the list on creation (see Item::Item() for details))
454
MEM_ROOT *mem_root; // Pointer to current memroot
455
bool is_backup_arena; /* True if this arena is used for backup. */
458
The states relfects three diffrent life cycles for three
459
different types of statements:
460
Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
461
Stored procedure: INITIALIZED_FOR_SP -> EXECUTED.
462
Other statements: CONVENTIONAL_EXECUTION never changes.
467
CONVENTIONAL_EXECUTION= 3, EXECUTED= 4, ERROR= -1
472
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg) :
473
free_list(0), mem_root(mem_root_arg), state(state_arg)
474
{ INIT_ARENA_DBUG_INFO; }
476
This constructor is used only when Query_arena is created as
477
backup storage for another instance of Query_arena.
479
Query_arena() { INIT_ARENA_DBUG_INFO; }
481
virtual ~Query_arena() {};
483
inline bool is_conventional() const
484
{ assert(state == CONVENTIONAL_EXECUTION); return state == CONVENTIONAL_EXECUTION; }
486
inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
487
inline void* calloc(size_t size)
490
if ((ptr=alloc_root(mem_root,size)))
491
memset(ptr, 0, size);
494
inline char *strdup(const char *str)
495
{ return strdup_root(mem_root,str); }
496
inline char *strmake(const char *str, size_t size)
497
{ return strmake_root(mem_root,str,size); }
498
inline void *memdup(const void *str, size_t size)
499
{ return memdup_root(mem_root,str,size); }
500
inline void *memdup_w_gap(const void *str, size_t size, uint gap)
503
if ((ptr= alloc_root(mem_root,size+gap)))
504
memcpy(ptr,str,size);
508
void set_query_arena(Query_arena *set);
511
/* Close the active state associated with execution of this statement */
512
virtual void cleanup_stmt();
518
338
@brief State of a single command executed against this connection.
562
381
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
563
382
non-NULL value if its previous value is NULL. We do not need to protect
564
383
operation (B) with any mutex. To avoid crashes in races, if we do not
565
know that thd->query cannot change at the moment, one should print
566
thd->query like this:
384
know that session->query cannot change at the moment, one should print
385
session->query like this:
567
386
(1) reserve the LOCK_thread_count mutex;
568
(2) check if thd->query is NULL;
569
(3) if not NULL, then print at most thd->query_length characters from
387
(2) check if session->query is NULL;
388
(3) if not NULL, then print at most session->query_length characters from
570
389
it. We will see the query_length field as either 0, or the right value
572
391
Assuming that the write and read of an n-bit memory field in an n-bit
573
computer is atomic, we can avoid races in the above way.
392
computer is atomic, we can avoid races in the above way.
574
393
This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
586
405
valid database name.
588
407
@note this attribute is set and alloced by the slave SQL thread (for
589
the THD of that thread); that thread is (and must remain, for now) the
408
the Session of that thread); that thread is (and must remain, for now) the
590
409
only responsible for freeing this member.
598
417
/* This constructor is called for backup statements */
601
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
602
enum enum_state state_arg, ulong id_arg);
420
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
605
/* Assign execution context (note: not all members) of given stmt to self */
606
void set_statement(Statement *stmt);
607
void set_n_backup_statement(Statement *stmt, Statement *backup);
608
void restore_backup_statement(Statement *stmt, Statement *backup);
611
424
struct st_savepoint {
612
425
struct st_savepoint *prev;
615
428
Ha_trx_info *ha_list;
767
@class Sub_statement_state
768
@brief Used to save context when executing a function or trigger
771
/* Defines used for Sub_statement_state::in_sub_stmt */
773
#define SUB_STMT_TRIGGER 1
774
#define SUB_STMT_FUNCTION 2
777
class Sub_statement_state
781
uint64_t first_successful_insert_id_in_prev_stmt;
782
uint64_t first_successful_insert_id_in_cur_stmt, insert_id_for_cur_row;
783
Discrete_interval auto_inc_interval_for_cur_row;
784
Discrete_intervals_list auto_inc_intervals_forced;
785
uint64_t limit_found_rows;
786
ha_rows cuted_fields, sent_row_count, examined_row_count;
787
ulong client_capabilities;
789
bool enable_slow_log;
790
bool last_insert_id_used;
791
SAVEPOINT *savepoints;
795
/* Flags for the THD::system_thread variable */
578
/* Flags for the Session::system_thread variable */
796
579
enum enum_thread_type
798
581
NON_SYSTEM_THREAD,
826
609
from the anticipated conditions trapped during runtime.
828
611
This mechanism is similar to C++ try/throw/catch:
829
- 'try' correspond to <code>THD::push_internal_handler()</code>,
612
- 'try' correspond to <code>Session::push_internal_handler()</code>,
830
613
- 'throw' correspond to <code>my_error()</code>,
831
614
which invokes <code>my_message_sql()</code>,
832
615
- 'catch' correspond to checking how/if an internal handler was invoked,
833
616
before removing it from the exception stack with
834
<code>THD::pop_internal_handler()</code>.
617
<code>Session::pop_internal_handler()</code>.
836
619
@param sql_errno the error number
837
620
@param level the error level
838
@param thd the calling thread
621
@param session the calling thread
839
622
@return true if the error is handled
841
virtual bool handle_error(uint sql_errno,
624
virtual bool handle_error(uint32_t sql_errno,
842
625
const char *message,
843
626
DRIZZLE_ERROR::enum_warning_level level,
627
Session *session) = 0;
923
706
SQL error number. One of ER_ codes from share/errmsg.txt.
924
707
Set by set_error_status.
709
uint32_t m_sql_errno;
929
Copied from thd->server_status when the diagnostics area is assigned.
712
Copied from session->server_status when the diagnostics area is assigned.
930
713
We need this member as some places in the code use the following pattern:
931
thd->server_status|= ...
933
thd->server_status&= ~...
714
session->server_status|= ...
716
session->server_status&= ~...
934
717
Assigned by OK, EOF or ERROR.
936
uint m_server_status;
719
uint32_t m_server_status;
938
721
The number of rows affected by the last statement. This is
939
semantically close to thd->row_count_func, but has a different
940
life cycle. thd->row_count_func stores the value returned by
722
semantically close to session->row_count_func, but has a different
723
life cycle. session->row_count_func stores the value returned by
941
724
function ROW_COUNT() and is cleared only by statements that
942
725
update its value, such as INSERT, UPDATE, DELETE and few others.
943
726
This member is cleared at the beginning of the next statement.
945
We could possibly merge the two, but life cycle of thd->row_count_func
728
We could possibly merge the two, but life cycle of session->row_count_func
946
729
can not be changed.
948
731
ha_rows m_affected_rows;
950
733
Similarly to the previous member, this is a replacement of
951
thd->first_successful_insert_id_in_prev_stmt, which is used
734
session->first_successful_insert_id_in_prev_stmt, which is used
952
735
to implement LAST_INSERT_ID().
954
737
uint64_t m_last_insert_id;
1095
877
time_t start_time, user_time;
1096
878
uint64_t connect_utime, thr_create_utime; // track down slow pthread_create
1097
879
uint64_t start_utime, utime_after_lock;
1099
881
thr_lock_type update_lock_default;
1101
/* <> 0 if we are inside of trigger or stored function. */
884
Both of the following container points in session will be converted to an API.
1104
887
/* container for handler's private per-connection data */
1105
888
Ha_data ha_data[MAX_HA];
890
/* container for replication data */
891
void *replication_data;
892
inline void setReplicationData (void *data) { replication_data= data; }
893
inline void *getReplicationData () { return replication_data; }
1107
895
/* Place to store various things */
1109
#ifndef DRIZZLE_CLIENT
1110
int binlog_setup_trx_data();
1113
Public interface to write RBR events to the binlog
1115
void binlog_start_trans_and_stmt();
1116
void binlog_set_stmt_begin();
1117
int binlog_write_table_map(Table *table, bool is_transactional);
1118
int binlog_write_row(Table* table, bool is_transactional,
1119
const uchar *new_data);
1120
int binlog_delete_row(Table* table, bool is_transactional,
1121
const uchar *old_data);
1122
int binlog_update_row(Table* table, bool is_transactional,
1123
const uchar *old_data, const uchar *new_data);
896
void *session_marker;
1125
898
void set_server_id(uint32_t sid) { server_id = sid; }
1128
Member functions to handle pending event for row-level logging.
1130
template <class RowsEventT> Rows_log_event*
1131
binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
1133
bool is_transactional,
1135
Rows_log_event* binlog_get_pending_rows_event() const;
1136
void binlog_set_pending_rows_event(Rows_log_event* ev);
1137
int binlog_flush_pending_rows_event(bool stmt_end);
1140
uint binlog_table_maps; // Number of table maps currently in the binlog
1142
enum enum_binlog_flag {
1143
BINLOG_FLAG_UNSAFE_STMT_PRINTED,
901
uint32_t binlog_table_maps; // Number of table maps currently in the binlog
1148
904
Flags with per-thread information regarding the status of the
1191
946
Field *dup_field;
1192
947
sigset_t signals;
1193
#ifdef SIGNAL_WITH_VIO_CLOSE
1197
949
This is to track items changed during execution of a prepared
1198
950
statement/stored procedure. It's created by
1199
register_item_tree_change() in memory root of THD, and freed in
951
register_item_tree_change() in memory root of Session, and freed in
1200
952
rollback_item_tree_changes(). For conventional execution it's always
1203
955
Item_change_list change_list;
1206
A permanent memory area of the statement. For conventional
1207
execution, the parsed tree and execution runtime reside in the same
1208
memory root. In this case stmt_arena points to THD. In case of
1209
a prepared statement or a stored procedure statement, thd->mem_root
1210
conventionally points to runtime memory, and thd->stmt_arena
1211
points to the memory of the PS/SP, where the parsed tree of the
1212
statement resides. Whenever you need to perform a permanent
1213
transformation of a parsed tree, you should allocate new memory in
1214
stmt_arena, to allow correct re-execution of PS/SP.
1215
Note: in the parser, stmt_arena == thd, even for PS/SP.
1217
Query_arena *stmt_arena;
1218
957
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
1219
958
bool arg_of_last_insert_id_function;
1505
1215
ulong ulong_value;
1506
1216
uint64_t uint64_t_value;
1511
If true, mysql_bin_log::write(Log_event) call will not write events to
1221
If true, drizzle_bin_log::write(Log_event) call will not write events to
1512
1222
binlog, and maintain 2 below variables instead (use
1513
mysql_bin_log.start_union_events to turn this on)
1223
drizzle_bin_log.start_union_events to turn this on)
1517
If true, at least one mysql_bin_log::write(Log_event) call has been
1518
made after last mysql_bin_log.start_union_events() call.
1227
If true, at least one drizzle_bin_log::write(Log_event) call has been
1228
made after last drizzle_bin_log.start_union_events() call.
1520
1230
bool unioned_events;
1522
If true, at least one mysql_bin_log::write(Log_event e), where
1523
e.cache_stmt == true call has been made after last
1524
mysql_bin_log.start_union_events() call.
1232
If true, at least one drizzle_bin_log::write(Log_event e), where
1233
e.cache_stmt == true call has been made after last
1234
drizzle_bin_log.start_union_events() call.
1526
1236
bool unioned_events_trans;
1529
1239
'queries' (actually SP statements) that run under inside this binlog
1530
union have thd->query_id >= first_query_id.
1240
union have session->query_id >= first_query_id.
1532
1242
query_id_t first_query_id;
1533
1243
} binlog_evt_union;
1542
1252
Lex_input_stream *m_lip;
1547
1257
void init(void);
1549
1259
Initialize memory roots necessary for query processing and (!)
1550
pre-allocate memory for it. We can't do that in THD constructor because
1260
pre-allocate memory for it. We can't do that in Session constructor because
1551
1261
there are use cases (acl_init, watcher threads,
1552
1262
killing mysqld) where it's vital to not allocate excessive and not used
1553
1263
memory. Note, that we still don't return error from init_for_queries():
1554
1264
if preallocation fails, we should notice that at the first call to
1557
1267
void init_for_queries();
1558
void change_user(void);
1559
1268
void cleanup(void);
1560
1269
void cleanup_after_query();
1561
1270
bool store_globals();
1562
#ifdef SIGNAL_WITH_VIO_CLOSE
1563
inline void set_active_vio(Vio* vio)
1565
pthread_mutex_lock(&LOCK_delete);
1567
pthread_mutex_unlock(&LOCK_delete);
1569
inline void clear_active_vio()
1571
pthread_mutex_lock(&LOCK_delete);
1573
pthread_mutex_unlock(&LOCK_delete);
1575
void close_active_vio();
1577
void awake(THD::killed_state state_to_set);
1271
void awake(Session::killed_state state_to_set);
1579
#ifndef DRIZZLE_CLIENT
1580
1273
enum enum_binlog_query_type {
1582
1275
The query can be logged row-based or statement-based
1584
1277
ROW_QUERY_TYPE,
1587
1280
The query has to be logged statement-based
1589
1282
STMT_QUERY_TYPE,
1592
1285
The query represents a change to a table in the "mysql"
1593
1286
database and is currently mapped to ROW_QUERY_TYPE.
1756
1439
void set_status_var_init();
1757
1440
void reset_n_backup_open_tables_state(Open_tables_state *backup);
1758
1441
void restore_backup_open_tables_state(Open_tables_state *backup);
1759
void restore_sub_statement_state(Sub_statement_state *backup);
1760
void set_n_backup_active_arena(Query_arena *set, Query_arena *backup);
1761
void restore_active_arena(Query_arena *set, Query_arena *backup);
1763
inline void set_current_stmt_binlog_row_based_if_mixed()
1766
If in a stored/function trigger, the caller should already have done the
1767
change. We test in_sub_stmt to prevent introducing bugs where people
1768
wouldn't ensure that, and would switch to row-based mode in the middle
1769
of executing a stored function/trigger (which is too late, see also
1770
reset_current_stmt_binlog_row_based()); this condition will make their
1771
tests fail and so force them to propagate the
1772
lex->binlog_row_based_if_mixed upwards to the caller.
1774
if ((variables.binlog_format == BINLOG_FORMAT_MIXED) &&
1776
current_stmt_binlog_row_based= true;
1778
inline void set_current_stmt_binlog_row_based()
1780
current_stmt_binlog_row_based= true;
1782
inline void clear_current_stmt_binlog_row_based()
1784
current_stmt_binlog_row_based= false;
1786
inline void reset_current_stmt_binlog_row_based()
1789
If there are temporary tables, don't reset back to
1790
statement-based. Indeed it could be that:
1791
CREATE TEMPORARY TABLE t SELECT UUID(); # row-based
1792
# and row-based does not store updates to temp tables
1794
INSERT INTO u SELECT * FROM t; # stmt-based
1795
and then the INSERT will fail as data inserted into t was not logged.
1796
So we continue with row-based until the temp table is dropped.
1797
If we are in a stored function or trigger, we mustn't reset in the
1798
middle of its execution (as the binary logging way of a stored function
1799
or trigger is decided when it starts executing, depending for example on
1800
the caller (for a stored function: if caller is SELECT or
1801
INSERT/UPDATE/DELETE...).
1803
Don't reset binlog format for NDB binlog injector thread.
1805
if ((temporary_tables == NULL) && (in_sub_stmt == 0))
1807
current_stmt_binlog_row_based=
1808
test(variables.binlog_format == BINLOG_FORMAT_ROW);
1813
1444
Set the current database; use deep copy of C-string.
1919
/** A short cut for thd->main_da.set_ok_status(). */
1541
/** A short cut for session->main_da.set_ok_status(). */
1922
my_ok(THD *thd, ha_rows affected_rows= 0, uint64_t id= 0,
1544
my_ok(Session *session, ha_rows affected_rows= 0, uint64_t id= 0,
1923
1545
const char *message= NULL)
1925
thd->main_da.set_ok_status(thd, affected_rows, id, message);
1547
session->main_da.set_ok_status(session, affected_rows, id, message);
1929
/** A short cut for thd->main_da.set_eof_status(). */
1551
/** A short cut for session->main_da.set_eof_status(). */
1554
my_eof(Session *session)
1934
thd->main_da.set_eof_status(thd);
1556
session->main_da.set_eof_status(session);
1937
1559
#define tmp_disable_binlog(A) \
2169
1792
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2171
void binlog_show_create_table(Table **tables, uint count);
1794
void binlog_show_create_table(Table **tables, uint32_t count);
2172
1795
void store_values(List<Item> &values);
2173
void send_error(uint errcode,const char *err);
1796
void send_error(uint32_t errcode,const char *err);
2174
1797
bool send_eof();
2176
1799
virtual bool can_rollback_data() { return 1; }
2178
// Needed for access from local class MY_HOOKS in prepare(), since thd is proteted.
2179
const THD *get_thd(void) { return thd; }
1801
// Needed for access from local class MY_HOOKS in prepare(), since session is proteted.
1802
const Session *get_session(void) { return session; }
2180
1803
const HA_CREATE_INFO *get_create_info() { return create_info; };
2181
1804
int prepare2(void) { return 0; }
2184
1807
#include <storage/myisam/myisam.h>
2187
Param to create temporary tables when doing SELECT:s
1810
Param to create temporary tables when doing SELECT:s
2189
1812
This structure is copied using memcpy as a part of JOIN.
2201
1824
List<Item> save_copy_funcs;
2202
1825
Copy_field *copy_field, *copy_field_end;
2203
1826
Copy_field *save_copy_field, *save_copy_field_end;
1827
unsigned char *group_buff;
2205
1828
Item **items_to_copy; /* Fields in tmp table */
2206
1829
MI_COLUMNDEF *recinfo,*start_recinfo;
2208
1831
ha_rows end_write_records;
2209
1832
uint field_count,sum_func_count,func_count;
2210
uint hidden_field_count;
1833
uint32_t hidden_field_count;
2211
1834
uint group_parts,group_length,group_null_parts;
2212
1835
uint quick_group;
2213
1836
bool using_indirect_summary_function;
2214
1837
/* If >0 convert all blob fields to varchar(convert_blob_length) */
2215
uint convert_blob_length;
2216
const CHARSET_INFO *table_charset;
1838
uint32_t convert_blob_length;
1839
const CHARSET_INFO *table_charset;
2217
1840
bool schema_table;
2219
1842
True if GROUP BY and its aggregate functions are already computed
2434
2050
bool get(Table *table);
2435
static double get_use_cost(uint *buffer, uint nkeys, uint key_size,
2436
uint64_t max_in_memory_size);
2437
inline static int get_cost_calc_buff_size(ulong nkeys, uint key_size,
2438
uint64_t max_in_memory_size)
2051
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
2052
size_t max_in_memory_size);
2053
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
2054
size_t max_in_memory_size)
2440
register uint64_t max_elems_in_tree=
2056
register size_t max_elems_in_tree=
2441
2057
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
2442
2058
return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
2564
2189
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2565
2190
STATUS_VAR *dec_var);
2192
/* Some inline functions for more speed */
2194
inline bool add_item_to_list(Session *session, Item *item)
2196
return session->lex->current_select->add_item_to_list(session, item);
2199
inline bool add_value_to_list(Session *session, Item *value)
2201
return session->lex->value_list.push_back(value);
2204
inline bool add_order_to_list(Session *session, Item *item, bool asc)
2206
return session->lex->current_select->add_order_to_list(session, item, asc);
2209
inline bool add_group_to_list(Session *session, Item *item, bool asc)
2211
return session->lex->current_select->add_group_to_list(session, item, asc);
2567
2214
#endif /* DRIZZLE_SERVER */
2216
#endif /* DRIZZLED_SQL_CLASS_H */