142
100
List<Item> *update_fields;
143
101
List<Item> *update_values;
144
102
/* for VIEW ... WITH CHECK OPTION */
162
} /* namespace drizzled */
164
/** @TODO why is this in the middle of the file */
165
#include <drizzled/lex_column.h>
106
class Key_part_spec :public Sql_alloc {
108
LEX_STRING field_name;
110
Key_part_spec(const LEX_STRING &name, uint32_t len)
111
: field_name(name), length(len)
113
Key_part_spec(const char *name, const size_t name_len, uint32_t len)
115
{ field_name.str= (char *)name; field_name.length= name_len; }
116
bool operator==(const Key_part_spec& other) const;
118
Construct a copy of this Key_part_spec. field_name is copied
119
by-pointer as it is known to never change. At the same time
120
'length' may be reset in mysql_prepare_create_table, and this
121
is why we supply it with a copy.
123
@return If out of memory, 0 is returned and an error is set in
126
Key_part_spec *clone(MEM_ROOT *mem_root) const
127
{ return new (mem_root) Key_part_spec(*this); }
131
class Alter_drop :public Sql_alloc {
133
enum drop_type {KEY, COLUMN };
136
Alter_drop(enum drop_type par_type,const char *par_name)
137
:name(par_name), type(par_type) {}
139
Used to make a clone of this object for ALTER/CREATE TABLE
140
@sa comment for Key_part_spec::clone
142
Alter_drop *clone(MEM_ROOT *mem_root) const
143
{ return new (mem_root) Alter_drop(*this); }
147
class Alter_column :public Sql_alloc {
151
Alter_column(const char *par_name,Item *literal)
152
:name(par_name), def(literal) {}
154
Used to make a clone of this object for ALTER/CREATE TABLE
155
@sa comment for Key_part_spec::clone
157
Alter_column *clone(MEM_ROOT *mem_root) const
158
{ return new (mem_root) Alter_column(*this); }
162
class Key :public Sql_alloc {
164
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
166
KEY_CREATE_INFO key_create_info;
167
List<Key_part_spec> columns;
171
Key(enum Keytype type_par, const LEX_STRING &name_arg,
172
KEY_CREATE_INFO *key_info_arg,
173
bool generated_arg, List<Key_part_spec> &cols)
174
:type(type_par), key_create_info(*key_info_arg), columns(cols),
175
name(name_arg), generated(generated_arg)
177
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
178
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
179
List<Key_part_spec> &cols)
180
:type(type_par), key_create_info(*key_info_arg), columns(cols),
181
generated(generated_arg)
183
name.str= (char *)name_arg;
184
name.length= name_len_arg;
186
Key(const Key &rhs, MEM_ROOT *mem_root);
188
/* Equality comparison of keys (ignoring name) */
189
friend bool foreign_key_prefix(Key *a, Key *b);
191
Used to make a clone of this object for ALTER/CREATE TABLE
192
@sa comment for Key_part_spec::clone
194
virtual Key *clone(MEM_ROOT *mem_root) const
195
{ return new (mem_root) Key(*this, mem_root); }
200
class Foreign_key: public Key {
202
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
203
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
204
enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
205
FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
207
Table_ident *ref_table;
208
List<Key_part_spec> ref_columns;
209
uint32_t delete_opt, update_opt, match_opt;
210
Foreign_key(const LEX_STRING &name_arg, List<Key_part_spec> &cols,
211
Table_ident *table, List<Key_part_spec> &ref_cols,
212
uint32_t delete_opt_arg, uint32_t update_opt_arg, uint32_t match_opt_arg)
213
:Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols),
214
ref_table(table), ref_columns(ref_cols),
215
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
216
match_opt(match_opt_arg)
218
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
220
Used to make a clone of this object for ALTER/CREATE TABLE
221
@sa comment for Key_part_spec::clone
223
virtual Key *clone(MEM_ROOT *mem_root) const
224
{ return new (mem_root) Foreign_key(*this, mem_root); }
225
/* Used to validate foreign key options */
226
bool validate(List<Create_field> &table_fields);
229
typedef struct st_mysql_lock
232
uint32_t table_count,lock_count;
233
THR_LOCK_DATA **locks;
237
class LEX_COLUMN : public Sql_alloc
242
LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {}
170
245
class select_result;
173
248
#define Session_SENTRY_MAGIC 0xfeedd1ff
174
249
#define Session_SENTRY_GONE 0xdeadbeef
176
struct drizzle_system_variables
251
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
253
struct system_variables
178
drizzle_system_variables()
181
256
How dynamically allocated system variables are handled:
183
258
The global_system_variables and max_system_variables are "authoritative"
184
259
They both should have the same 'version' and 'size'.
185
260
When attempting to access a dynamic variable, if the session version
186
261
is out of date, then the session version is updated and realloced if
187
262
neccessary and bytes copied from global to make up for missing data.
189
264
ulong dynamic_variables_version;
190
char * dynamic_variables_ptr;
265
char* dynamic_variables_ptr;
191
266
uint32_t dynamic_variables_head; /* largest valid variable offset */
192
267
uint32_t dynamic_variables_size; /* how many bytes are in use */
194
269
uint64_t myisam_max_extra_sort_file_size;
270
uint64_t myisam_max_sort_file_size;
195
271
uint64_t max_heap_table_size;
196
272
uint64_t tmp_table_size;
197
273
ha_rows select_limit;
198
274
ha_rows max_join_size;
199
uint64_t auto_increment_increment;
200
uint64_t auto_increment_offset;
201
uint64_t bulk_insert_buff_size;
202
uint64_t join_buff_size;
203
uint32_t max_allowed_packet;
204
uint64_t max_error_count;
205
uint64_t max_length_for_sort_data;
206
size_t max_sort_length;
207
uint64_t min_examined_row_limit;
208
bool optimizer_prune_level;
211
uint32_t optimizer_search_depth;
212
uint32_t div_precincrement;
213
uint64_t preload_buff_size;
214
uint32_t read_buff_size;
215
uint32_t read_rnd_buff_size;
216
bool replicate_query;
217
size_t sortbuff_size;
218
uint32_t thread_handling;
219
uint32_t tx_isolation;
220
size_t transaction_message_threshold;
221
uint32_t completion_type;
275
ulong auto_increment_increment, auto_increment_offset;
276
ulong bulk_insert_buff_size;
277
ulong join_buff_size;
278
ulong max_allowed_packet;
279
ulong max_error_count;
280
ulong max_length_for_sort_data;
281
ulong max_sort_length;
282
ulong max_tmp_tables;
283
ulong min_examined_row_limit;
284
ulong myisam_repair_threads;
285
ulong myisam_sort_buff_size;
286
ulong myisam_stats_method;
287
ulong net_buffer_length;
288
ulong net_interactive_timeout;
289
ulong net_read_timeout;
290
ulong net_retry_count;
291
ulong net_wait_timeout;
292
ulong net_write_timeout;
293
ulong optimizer_prune_level;
294
ulong optimizer_search_depth;
296
Controls use of Engine-MRR:
297
0 - auto, based on cost
298
1 - force MRR when the storage engine is capable of doing it
301
ulong optimizer_use_mrr;
302
/* A bitmap for switching optimizations on/off */
303
ulong optimizer_switch;
304
ulong preload_buff_size;
305
ulong read_buff_size;
306
ulong read_rnd_buff_size;
307
ulong div_precincrement;
309
ulong thread_handling;
311
ulong completion_type;
222
312
/* Determines which non-standard SQL behaviour should be enabled */
224
uint64_t max_seeks_for_key;
225
size_t range_alloc_block_size;
226
uint32_t query_alloc_block_size;
227
uint32_t query_prealloc_size;
228
uint64_t group_concat_max_len;
314
ulong default_week_format;
315
ulong max_seeks_for_key;
316
ulong range_alloc_block_size;
317
ulong query_alloc_block_size;
318
ulong query_prealloc_size;
319
ulong trans_alloc_block_size;
320
ulong trans_prealloc_size;
322
ulong group_concat_max_len;
323
ulong binlog_format; // binlog format for this session (see enum_binlog_format)
325
In slave thread we need to know in behalf of which
326
thread the query is being run to replicate temp tables properly
328
/* TODO: change this to my_thread_id - but have to fix set_var first */
229
329
uint64_t pseudo_thread_id;
231
plugin::StorageEngine *storage_engine;
331
bool low_priority_updates;
334
compatibility option:
335
- index usage hints (USE INDEX without a FOR clause) behave as in 5.0
338
bool engine_condition_pushdown;
339
bool keep_files_on_create;
341
bool old_alter_table;
343
plugin_ref table_plugin;
233
345
/* Only charset part of these variables is sensible */
234
346
const CHARSET_INFO *character_set_filesystem;
347
const CHARSET_INFO *character_set_client;
348
const CHARSET_INFO *character_set_results;
236
350
/* Both charset and collation parts of these variables are important */
237
351
const CHARSET_INFO *collation_server;
239
inline const CHARSET_INFO *getCollation(void)
241
return collation_server;
352
const CHARSET_INFO *collation_database;
353
const CHARSET_INFO *collation_connection;
244
355
/* Locale Support */
245
356
MY_LOCALE *lc_time_names;
247
358
Time_zone *time_zone;
360
/* DATE, DATETIME and DRIZZLE_TIME formats */
361
DATE_TIME_FORMAT *date_format;
362
DATE_TIME_FORMAT *datetime_format;
363
DATE_TIME_FORMAT *time_format;
250
extern struct drizzle_system_variables global_system_variables;
252
} /* namespace drizzled */
254
#include "drizzled/sql_lex.h"
368
extern struct system_variables global_system_variables;
370
#include "sql_lex.h" /* only for SQLCOM_END */
372
/* per thread status variables */
374
typedef struct system_status_var
376
uint64_t bytes_received;
379
ulong com_stat[(uint) SQLCOM_END];
380
ulong created_tmp_disk_tables;
381
ulong created_tmp_tables;
382
ulong ha_commit_count;
383
ulong ha_delete_count;
384
ulong ha_read_first_count;
385
ulong ha_read_last_count;
386
ulong ha_read_key_count;
387
ulong ha_read_next_count;
388
ulong ha_read_prev_count;
389
ulong ha_read_rnd_count;
390
ulong ha_read_rnd_next_count;
391
ulong ha_rollback_count;
392
ulong ha_update_count;
393
ulong ha_write_count;
394
ulong ha_prepare_count;
395
ulong ha_discover_count;
396
ulong ha_savepoint_count;
397
ulong ha_savepoint_rollback_count;
399
/* KEY_CACHE parts. These are copies of the original */
400
ulong key_blocks_changed;
401
ulong key_blocks_used;
402
ulong key_cache_r_requests;
403
ulong key_cache_read;
404
ulong key_cache_w_requests;
405
ulong key_cache_write;
406
/* END OF KEY_CACHE parts */
408
ulong net_big_packet_count;
411
ulong select_full_join_count;
412
ulong select_full_range_join_count;
413
ulong select_range_count;
414
ulong select_range_check_count;
415
ulong select_scan_count;
416
ulong long_query_count;
417
ulong filesort_merge_passes;
418
ulong filesort_range_count;
420
ulong filesort_scan_count;
421
/* Prepared statements and binary protocol */
422
ulong com_stmt_prepare;
423
ulong com_stmt_execute;
424
ulong com_stmt_send_long_data;
425
ulong com_stmt_fetch;
426
ulong com_stmt_reset;
427
ulong com_stmt_close;
429
Number of statements sent from the client
435
SEE last_system_status_var DEFINITION BELOW.
437
Below 'last_system_status_var' are all variables which doesn't make any
438
sense to add to the /global/ status variable counter.
440
double last_query_cost;
446
This is used for 'SHOW STATUS'. It must be updated to the last ulong
447
variable in system_status_var which is makes sens to add to the global
451
#define last_system_status_var questions
259
453
void mark_transaction_to_rollback(Session *session, bool all);
455
#ifdef DRIZZLE_SERVER
461
List of items created in the parser for this query. Every item puts
462
itself to the list on creation (see Item::Item() for details))
465
MEM_ROOT *mem_root; // Pointer to current memroot
467
Query_arena(MEM_ROOT *mem_root_arg) :
468
free_list(0), mem_root(mem_root_arg)
471
This constructor is used only when Query_arena is created as
472
backup storage for another instance of Query_arena.
476
virtual ~Query_arena() {};
478
inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
479
inline void* calloc(size_t size)
482
if ((ptr=alloc_root(mem_root,size)))
483
memset(ptr, 0, size);
486
inline char *strdup(const char *str)
487
{ return strdup_root(mem_root,str); }
488
inline char *strmake(const char *str, size_t size)
489
{ return strmake_root(mem_root,str,size); }
490
inline void *memdup(const void *str, size_t size)
491
{ return memdup_root(mem_root,str,size); }
492
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
495
if ((ptr= alloc_root(mem_root,size+gap)))
496
memcpy(ptr,str,size);
262
Storage engine specific thread local data.
506
@brief State of a single command executed against this connection.
508
One connection can contain a lot of simultaneously running statements,
509
some of which could be:
510
- prepared, that is, contain placeholders,
511
To perform some action with statement we reset Session part to the state of
512
that statement, do the action, and then save back modified state from Session
513
to the statement. It will be changed in near future, and Statement will
517
class Statement: public ilink, public Query_arena
267
Storage engine specific thread local data.
268
Lifetime: one user connection.
519
Statement(const Statement &rhs); /* not implemented: */
520
Statement &operator=(const Statement &rhs); /* non-copyable */
523
Uniquely identifies each statement object in thread scope; change during
524
statement lifetime. FIXME: must be const
272
* Resource contexts for both the "statement" and "normal"
275
* Resource context at index 0:
277
* Life time: one statement within a transaction. If @@autocommit is
278
* on, also represents the entire transaction.
280
* Resource context at index 1:
282
* Life time: one transaction within a connection.
286
* If the storage engine does not participate in a transaction,
287
* there will not be a resource context.
289
drizzled::ResourceContext resource_context[2];
291
Ha_data() :ha_ptr(NULL) {}
295
* Represents a client connection to the database server.
297
* Contains the client/server protocol object, the current statement
298
* being executed, local-to-session variables and status counters, and
299
* a host of other information.
303
* The Session class should have a vector of Statement object pointers which
304
* comprise the statements executed on the Session. Until this architectural
305
* change is done, we can forget about parallel operations inside a session.
309
* Make member variables private and have inlined accessors and setters. Hide
310
* all member variables that are not critical to non-internal operations of the
313
typedef int64_t session_id_t;
315
class Session : public Open_tables_state
318
// Plugin storage in Session.
319
typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
320
typedef Session* Ptr;
321
typedef boost::shared_ptr<Session> shared_ptr;
324
529
MARK_COLUMNS_NONE: Means mark_used_colums is not set and no indicator to
507
576
the Session of that thread); that thread is (and must remain, for now) the
508
577
only responsible for freeing this member.
585
/* This constructor is called for backup statements */
588
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, ulong id_arg);
592
struct st_savepoint {
593
struct st_savepoint *prev;
596
Ha_trx_info *ha_list;
599
enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
600
extern const char *xa_state_names[];
602
typedef struct st_xid_state {
603
/* For now, this is only used to catch duplicated external xids */
604
XID xid; // transaction identifier
605
enum xa_states xa_state; // used by external XA only
609
extern pthread_mutex_t LOCK_xid_cache;
610
extern HASH xid_cache;
611
bool xid_cache_init(void);
612
void xid_cache_free(void);
613
XID_STATE *xid_cache_search(XID *xid);
614
bool xid_cache_insert(XID *xid, enum xa_states xa_state);
615
bool xid_cache_insert(XID_STATE *xid_state);
616
void xid_cache_delete(XID_STATE *xid_state);
619
@class Security_context
620
@brief A set of Session members describing the current authenticated user.
623
class Security_context {
625
Security_context() {} /* Remove gcc warning */
627
host - host of the client
628
user - user of the client, set to NULL until the user has been read from
630
priv_user - The user privilege we are using. May be "" for anonymous user.
639
inline char *priv_host_name()
641
return (ip ? ip : (char *)"%");
647
A registry for item tree transformations performed during
648
query optimization. We register only those changes which require
649
a rollback to re-execute a prepared statement or stored procedure
653
struct Item_change_record;
654
typedef I_List<Item_change_record> Item_change_list;
658
Class that holds information about tables which were opened and locked
659
by the thread. It is also used to save/restore this information in
660
push_open_tables_state()/pop_open_tables_state().
663
class Open_tables_state
667
List of regular tables in use by this thread. Contains temporary and
668
base tables that were opened with @see open_tables().
672
List of temporary tables used by this thread. Contains user-level
673
temporary tables, created with CREATE TEMPORARY TABLE, and
674
internal temporary tables, created, e.g., to resolve a SELECT,
675
or for an intermediate table used in ALTER.
676
XXX Why are internal temporary tables added to this list?
678
Table *temporary_tables;
680
List of tables that were opened with HANDLER OPEN and are
681
still in use by this thread.
683
Table *handler_tables;
684
Table *derived_tables;
686
During a MySQL session, one can lock tables in two modes: automatic
687
or manual. In automatic mode all necessary tables are locked just before
688
statement execution, and all acquired locks are stored in 'lock'
689
member. Unlocking takes place automatically as well, when the
691
Manual mode comes into play when a user issues a 'LOCK TABLES'
692
statement. In this mode the user can only use the locked tables.
693
Trying to use any other tables will give an error. The locked tables are
694
stored in 'locked_tables' member. Manual locking is described in
695
the 'LOCK_TABLES' chapter of the MySQL manual.
696
See also lock_tables() for details.
700
Tables that were locked with explicit or implicit LOCK TABLES.
701
(Implicit LOCK TABLES happens when we are prelocking tables for
702
execution of statement which uses stored routines. See description
703
Session::prelocked_mode for more info.)
705
DRIZZLE_LOCK *locked_tables;
708
CREATE-SELECT keeps an extra lock for the table being
709
created. This field is used to keep the extra lock available for
710
lower level routines, which would otherwise miss that lock.
712
DRIZZLE_LOCK *extra_lock;
715
uint32_t current_tablenr;
718
BACKUPS_AVAIL = (1U << 0) /* There are backups available */
722
Flags with information about the open tables state.
724
uint32_t state_flags;
727
This constructor serves for creation of Open_tables_state instances
728
which are used as backup storage.
730
Open_tables_state() : state_flags(0U) { }
732
Open_tables_state(ulong version_arg);
734
void set_open_tables_state(Open_tables_state *state)
739
void reset_open_tables_state()
741
open_tables= temporary_tables= handler_tables= derived_tables= 0;
742
extra_lock= lock= locked_tables= 0;
748
/* Flags for the Session::system_thread variable */
749
enum enum_thread_type
752
SYSTEM_THREAD_SLAVE_IO,
753
SYSTEM_THREAD_SLAVE_SQL
758
This class represents the interface for internal error handlers.
759
Internal error handlers are exception handlers used by the server
762
class Internal_error_handler
765
Internal_error_handler() {}
766
virtual ~Internal_error_handler() {}
770
Handle an error condition.
771
This method can be implemented by a subclass to achieve any of the
773
- mask an error internally, prevent exposing it to the user,
774
- mask an error and throw another one instead.
775
When this method returns true, the error condition is considered
776
'handled', and will not be propagated to upper layers.
777
It is the responsability of the code installing an internal handler
778
to then check for trapped conditions, and implement logic to recover
779
from the anticipated conditions trapped during runtime.
781
This mechanism is similar to C++ try/throw/catch:
782
- 'try' correspond to <code>Session::push_internal_handler()</code>,
783
- 'throw' correspond to <code>my_error()</code>,
784
which invokes <code>my_message_sql()</code>,
785
- 'catch' correspond to checking how/if an internal handler was invoked,
786
before removing it from the exception stack with
787
<code>Session::pop_internal_handler()</code>.
789
@param sql_errno the error number
790
@param level the error level
791
@param session the calling thread
792
@return true if the error is handled
794
virtual bool handle_error(uint32_t sql_errno,
796
DRIZZLE_ERROR::enum_warning_level level,
797
Session *session) = 0;
802
Stores status of the currently executed statement.
803
Cleared at the beginning of the statement, and then
804
can hold either OK, ERROR, or EOF status.
805
Can not be assigned twice per statement.
808
class Diagnostics_area
811
enum enum_diagnostics_status
813
/** The area is cleared at start of a statement. */
815
/** Set whenever one calls my_ok(). */
817
/** Set whenever one calls my_eof(). */
819
/** Set whenever one calls my_error() or my_message(). */
821
/** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
824
/** True if status information is sent to the client. */
826
/** Set to make set_error_status after set_{ok,eof}_status possible. */
827
bool can_overwrite_status;
829
void set_ok_status(Session *session, ha_rows affected_rows_arg,
830
uint64_t last_insert_id_arg,
831
const char *message);
832
void set_eof_status(Session *session);
833
void set_error_status(Session *session, uint32_t sql_errno_arg, const char *message_arg);
835
void disable_status();
837
void reset_diagnostics_area();
839
bool is_set() const { return m_status != DA_EMPTY; }
840
bool is_error() const { return m_status == DA_ERROR; }
841
bool is_eof() const { return m_status == DA_EOF; }
842
bool is_ok() const { return m_status == DA_OK; }
843
bool is_disabled() const { return m_status == DA_DISABLED; }
844
enum_diagnostics_status status() const { return m_status; }
846
const char *message() const
847
{ assert(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
849
uint32_t sql_errno() const
850
{ assert(m_status == DA_ERROR); return m_sql_errno; }
852
uint32_t server_status() const
854
assert(m_status == DA_OK || m_status == DA_EOF);
855
return m_server_status;
858
ha_rows affected_rows() const
859
{ assert(m_status == DA_OK); return m_affected_rows; }
861
uint64_t last_insert_id() const
862
{ assert(m_status == DA_OK); return m_last_insert_id; }
864
uint32_t total_warn_count() const
866
assert(m_status == DA_OK || m_status == DA_EOF);
867
return m_total_warn_count;
870
Diagnostics_area() { reset_diagnostics_area(); }
511
util::string::shared_ptr _schema;
873
/** Message buffer. Can be used by OK or ERROR status. */
874
char m_message[DRIZZLE_ERRMSG_SIZE];
876
SQL error number. One of ER_ codes from share/errmsg.txt.
877
Set by set_error_status.
879
uint32_t m_sql_errno;
882
Copied from session->server_status when the diagnostics area is assigned.
883
We need this member as some places in the code use the following pattern:
884
session->server_status|= ...
886
session->server_status&= ~...
887
Assigned by OK, EOF or ERROR.
889
uint32_t m_server_status;
891
The number of rows affected by the last statement. This is
892
semantically close to session->row_count_func, but has a different
893
life cycle. session->row_count_func stores the value returned by
894
function ROW_COUNT() and is cleared only by statements that
895
update its value, such as INSERT, UPDATE, DELETE and few others.
896
This member is cleared at the beginning of the next statement.
898
We could possibly merge the two, but life cycle of session->row_count_func
901
ha_rows m_affected_rows;
903
Similarly to the previous member, this is a replacement of
904
session->first_successful_insert_id_in_prev_stmt, which is used
905
to implement LAST_INSERT_ID().
907
uint64_t m_last_insert_id;
908
/** The total number of warnings. */
909
uint m_total_warn_count;
910
enum_diagnostics_status m_status;
912
@todo: the following Session members belong here:
913
- warn_list, warn_count,
919
Storage engine specific thread local data.
925
Storage engine specific thread local data.
926
Lifetime: one user connection.
930
0: Life time: one statement within a transaction. If @@autocommit is
931
on, also represents the entire transaction.
932
@sa trans_register_ha()
934
1: Life time: one transaction within a connection.
935
If the storage engine does not participate in a transaction,
936
this should not be used.
937
@sa trans_register_ha()
939
Ha_trx_info ha_info[2];
941
Ha_data() :ha_ptr(NULL) {}
947
For each client connection we create a separate thread with Session serving as
948
a thread/connection descriptor
951
class Session :public Statement,
952
public Open_tables_state
514
util::string::const_shared_ptr schema() const
519
return util::string::const_shared_ptr(new std::string(""));
522
/* current cache key */
523
std::string query_cache_key;
955
/* Used to execute base64 coded binlog events in MySQL server */
956
Relay_log_info* rli_fake;
525
959
Constant for Session::where initialization in the beginning of every query.
527
961
It's needed because we do not save/restore Session::where normally during
530
964
static const char * const DEFAULT_WHERE;
532
memory::Root warn_root; /**< Allocation area for warnings and errors */
533
plugin::Client *client; /**< Pointer to client object */
535
void setClient(plugin::Client *client_arg);
537
plugin::Client *getClient()
542
plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
543
void *scheduler_arg; /**< Pointer to the optional scheduler argument */
545
typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
547
typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
548
UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
552
const UserVars &getUserVariables() const
557
drizzle_system_variables variables; /**< Mutable local variables local to the session */
558
struct system_status_var status_var; /**< Session-local status counters */
559
THR_LOCK_INFO lock_info; /**< Locking information for this session */
560
THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
561
THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
564
* A pointer to the stack frame of the scheduler thread
565
* which is called first in the thread for handling a client
570
SecurityContext security_ctx;
572
int32_t scoreboard_index;
574
inline void checkSentry() const
576
assert(this->dbug_sentry == Session_SENTRY_MAGIC);
579
const SecurityContext& getSecurityContext() const
584
SecurityContext& getSecurityContext()
589
int32_t getScoreboardIndex()
591
return scoreboard_index;
594
void setScoreboardIndex(int32_t in_scoreboard_index)
596
scoreboard_index= in_scoreboard_index;
600
* Is this session viewable by the current user?
602
bool isViewable() const;
966
NET net; // client connection descriptor
967
MEM_ROOT warn_root; // For warnings and errors
968
Protocol *protocol; // Current protocol
969
Protocol_text protocol_text; // Normal protocol
970
HASH user_vars; // hash for user variables
971
String packet; // dynamic buffer for network I/O
972
String convert_buffer; // buffer for charset conversions
973
struct rand_struct rand; // used for authentication
974
struct system_variables variables; // Changeable local variables
975
struct system_status_var status_var; // Per thread statistic vars
976
struct system_status_var *initial_status_var; /* used by show status */
977
THR_LOCK_INFO lock_info; // Locking info of this thread
978
THR_LOCK_OWNER main_lock_id; // To use for conventional queries
979
THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to
980
// the lock_id of a cursor.
981
pthread_mutex_t LOCK_delete; // Locked before session is deleted
983
A pointer to the stack frame of handle_one_connection(),
984
which is called first in the thread for handling a client
989
Currently selected catalog.
995
Some members of Session (currently 'Statement::db',
996
'catalog' and 'query') are set and alloced by the slave SQL thread
997
(for the Session of that thread); that thread is (and must remain, for now)
998
the only responsible for freeing these 3 members. If you add members
999
here, and you add code to set them in replication, don't forget to
1000
free_them_and_set_them_to_0 in replication properly. For details see
1001
the 'err:' label of the handle_slave_sql() in sql/slave.cc.
1003
@see handle_slave_sql
1006
Security_context main_security_ctx;
1007
Security_context *security_ctx;
1010
Points to info-string that we show in SHOW PROCESSLIST
1011
You are supposed to call Session_SET_PROC_INFO only if you have coded
1012
a time-consuming piece that MySQL can get stuck in for a long time.
1014
Set it using the session_proc_info(Session *thread, const char *message)
1017
void set_proc_info(const char *info) { proc_info= info; }
1018
const char* get_proc_info() const { return proc_info; }
605
1021
Used in error messages to tell user in what part of MySQL we found an
606
1022
error. E. g. when where= "having clause", if fix_fields() fails, user
607
1023
will know that the error was in having clause.
609
1025
const char *where;
1027
double tmp_double_value; /* Used in set_var.cc */
1028
ulong client_capabilities; /* What the client supports */
1029
ulong max_client_packet_length;
1031
HASH handler_tables_hash;
612
1033
One thread can hold up to one named user-level lock. This variable
613
1034
points to a lock object if the lock is present. See item_func.cc and
614
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
616
uint32_t dbug_sentry; /**< watch for memory corruption */
618
boost::thread::id boost_thread_id;
619
boost_thread_shared_ptr _thread;
620
boost::this_thread::disable_interruption *interrupt;
622
internal::st_my_thread_var *mysys_var;
625
boost_thread_shared_ptr &getThread()
630
void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
632
interrupt= interrupt_arg;
635
boost::this_thread::disable_interruption &getThreadInterupt()
641
internal::st_my_thread_var *getThreadVar()
647
* Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
648
* first byte of the packet in executeStatement()
1035
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
1037
uint32_t dbug_sentry; // watch out for memory corruption
1038
struct st_my_thread_var *mysys_var;
1040
Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
1041
first byte of the packet in do_command()
650
1043
enum enum_server_command command;
651
uint32_t file_id; /**< File ID for LOAD DATA INFILE */
652
/* @note the following three members should likely move to Client */
653
uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
656
uint64_t thr_create_utime; /**< track down slow pthread_create */
657
uint64_t start_utime;
658
uint64_t utime_after_lock;
1045
uint32_t file_id; // for LOAD DATA INFILE
1046
/* remote (peer) port */
1048
time_t start_time, user_time;
1049
uint64_t connect_utime, thr_create_utime; // track down slow pthread_create
1050
uint64_t start_utime, utime_after_lock;
660
1052
thr_lock_type update_lock_default;
663
Both of the following container points in session will be converted to an API.
667
1054
/* container for handler's private per-connection data */
668
std::vector<Ha_data> ha_data;
670
Id of current query. Statement can be reused to execute several queries
671
query_id is global in context of the whole MySQL server.
672
ID is automatically generated from an atomic counter.
673
It's used in Cursor code for various purposes: to check which columns
674
from table are necessary for this select, to check if it's necessary to
675
update auto-updatable fields (like auto_increment and timestamp).
678
query_id_t warn_query_id;
680
void **getEngineData(const plugin::MonitoredInTransaction *monitored);
681
ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
1055
Ha_data ha_data[MAX_HA];
1057
/* Place to store various things */
1058
void *session_marker;
1059
int binlog_setup_trx_data();
1062
Public interface to write RBR events to the binlog
1064
void binlog_start_trans_and_stmt();
1065
void binlog_set_stmt_begin();
1066
int binlog_write_table_map(Table *table, bool is_transactional);
1067
int binlog_write_row(Table* table, bool is_transactional,
1068
const unsigned char *new_data);
1069
int binlog_delete_row(Table* table, bool is_transactional,
1070
const unsigned char *old_data);
1071
int binlog_update_row(Table* table, bool is_transactional,
1072
const unsigned char *old_data, const unsigned char *new_data);
1074
void set_server_id(uint32_t sid) { server_id = sid; }
1077
Member functions to handle pending event for row-level logging.
1079
template <class RowsEventT> Rows_log_event*
1080
binlog_prepare_pending_rows_event(Table* table, uint32_t serv_id,
1082
bool is_transactional,
1084
Rows_log_event* binlog_get_pending_rows_event() const;
1085
void binlog_set_pending_rows_event(Rows_log_event* ev);
1086
int binlog_flush_pending_rows_event(bool stmt_end);
1089
uint32_t binlog_table_maps; // Number of table maps currently in the binlog
1091
enum enum_binlog_flag {
1092
BINLOG_FLAG_UNSAFE_STMT_PRINTED,
685
* Structure used to manage "statement transactions" and
686
* "normal transactions". In autocommit mode, the normal transaction is
687
* equivalent to the statement transaction.
689
* Storage engines will be registered here when they participate in
690
* a transaction. No engine is registered more than once.
1097
Flags with per-thread information regarding the status of the
1100
uint32_t binlog_flags;
1102
uint32_t get_binlog_table_maps() const {
1103
return binlog_table_maps;
1105
void clear_binlog_table_maps() {
1106
binlog_table_maps= 0;
692
1111
struct st_transactions {
693
std::deque<NamedSavepoint> savepoints;
696
* The normal transaction (since BEGIN WORK).
698
* Contains a list of all engines that have participated in any of the
699
* statement transactions started within the context of the normal
702
* @note In autocommit mode, this is empty.
704
TransactionContext all;
707
* The statment transaction.
709
* Contains a list of all engines participating in the given statement.
711
* @note In autocommit mode, this will be used to commit/rollback the
712
* normal transaction.
714
TransactionContext stmt;
1112
SAVEPOINT *savepoints;
1113
Session_TRANS all; // Trans since BEGIN WORK
1114
Session_TRANS stmt; // Trans for current statement
1115
bool on; // see ha_enable_transaction()
716
1116
XID_STATE xid_state;
1117
Rows_log_event *m_pending_rows_event;
1120
Tables changed in transaction (that must be invalidated in query cache).
1121
List contain only transactional tables, that not invalidated in query
1122
cache (instead of full list of changed in transaction tables).
1124
CHANGED_TableList* changed_tables;
1125
MEM_ROOT mem_root; // Transaction-life memory allocation pool
1130
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
1134
memset(this, 0, sizeof(*this));
1135
xid_state.xid.null();
1136
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
731
1140
sigset_t signals;
733
// As of right now we do not allow a concurrent execute to launch itself
735
bool concurrent_execute_allowed;
738
void setConcurrentExecute(bool arg)
740
concurrent_execute_allowed= arg;
743
bool isConcurrentExecuteAllowed() const
745
return concurrent_execute_allowed;
1142
This is to track items changed during execution of a prepared
1143
statement/stored procedure. It's created by
1144
register_item_tree_change() in memory root of Session, and freed in
1145
rollback_item_tree_changes(). For conventional execution it's always
1148
Item_change_list change_list;
748
1150
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
749
1151
bool arg_of_last_insert_id_function;
752
1153
ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
753
1154
insertion into an auto_increment column".
756
1157
This is the first autogenerated insert id which was *successfully*
757
1158
inserted by the previous statement (exactly, if the previous statement
758
1159
didn't successfully insert an autogenerated insert id, then it's the one
795
1216
in the binlog is still needed; the list's minimum will contain 3.
797
1218
Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
798
/** Used by replication and SET INSERT_ID */
1219
/* Used by replication and SET INSERT_ID */
799
1220
Discrete_intervals_list auto_inc_intervals_forced;
801
uint64_t limit_found_rows;
802
uint64_t options; /**< Bitmap of options */
803
int64_t row_count_func; /**< For the ROW_COUNT() function */
804
ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
807
* Number of rows we actually sent to the client, including "synthetic"
808
* rows in ROLLUP etc.
810
ha_rows sent_row_count;
813
* Number of rows we read, sent or not, including in create_sort_index()
815
ha_rows examined_row_count;
818
* The set of those tables whose fields are referenced in all subqueries
823
* Possibly this it is incorrect to have used tables in Session because
824
* with more than one subquery, it is not clear what does the field mean.
826
table_map used_tables;
831
This, and some other variables like 'count_cuted_fields'
832
maybe should be statement/cursor local, that is, moved to Statement
833
class. With current implementation warnings produced in each prepared
834
statement/cursor settle here.
836
List<DRIZZLE_ERROR> warn_list;
837
uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
838
uint32_t total_warn_count;
839
Diagnostics_area main_da;
843
/* Statement id is thread-wide. This counter is used to generate ids */
844
uint32_t statement_id_counter;
845
uint32_t rand_saved_seed1;
846
uint32_t rand_saved_seed2;
848
Row counter, mainly for errors and warnings. Not increased in
849
create_sort_index(); may differ from examined_row_count.
852
session_id_t thread_id;
854
enum global_read_lock_t
857
GOT_GLOBAL_READ_LOCK= 1,
858
MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
861
global_read_lock_t _global_read_lock;
865
global_read_lock_t isGlobalReadLock() const
867
return _global_read_lock;
870
void setGlobalReadLock(global_read_lock_t arg)
872
_global_read_lock= arg;
875
DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags, bool *need_reopen);
876
bool lockGlobalReadLock();
877
bool lock_table_names(TableList *table_list);
878
bool lock_table_names_exclusively(TableList *table_list);
879
bool makeGlobalReadLockBlockCommit();
880
bool abortLockForThread(Table *table);
881
bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
882
int lock_table_name(TableList *table_list);
883
void abortLock(Table *table);
884
void removeLock(Table *table);
885
void unlockReadTables(DrizzleLock *sql_lock);
886
void unlockSomeTables(Table **table, uint32_t count);
887
void unlockTables(DrizzleLock *sql_lock);
888
void startWaitingGlobalReadLock();
889
void unlockGlobalReadLock();
892
int unlock_external(Table **table, uint32_t count);
893
int lock_external(Table **tables, uint32_t count);
894
bool wait_for_locked_table_names(TableList *table_list);
895
DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
896
bool should_lock, Table **write_lock_used);
899
uint32_t server_status;
900
uint32_t open_options;
901
uint32_t select_number; /**< number of select (used for EXPLAIN) */
902
/* variables.transaction_isolation is reset to this after each commit */
903
enum_tx_isolation session_tx_isolation;
904
enum_check_fields count_cuted_fields;
912
KILLED_NO_VALUE /* means none of the above states apply */
915
killed_state_t volatile _killed;
919
void setKilled(killed_state_t arg)
924
killed_state_t getKilled()
929
volatile killed_state_t *getKilledPtr() // Do not use this method, it is here for historical convience.
934
bool is_admin_connection;
935
bool some_tables_deleted;
939
Set to true if execution of the current compound statement
940
can not continue. In particular, disables activation of
941
CONTINUE or EXIT handlers of stored routines.
942
Reset in the end of processing of the current user request, in
943
@see mysql_reset_session_for_next_command().
947
Set by a storage engine to request the entire
948
transaction (that possibly spans multiple engines) to
949
rollback. Reset in ha_rollback.
951
bool transaction_rollback_request;
953
true if we are in a sub-statement and the current error can
954
not be safely recovered until we left the sub-statement mode.
955
In particular, disables activation of CONTINUE and EXIT
956
handlers inside sub-statements. E.g. if it is a deadlock
957
error and requires a transaction-wide rollback, this flag is
958
raised (traditionally, MySQL first has to close all the reads
959
via @see handler::ha_index_or_rnd_end() and only then perform
961
Reset to false when we leave the sub-statement mode.
963
bool is_fatal_sub_stmt_error;
964
/** for IS NULL => = last_insert_id() fix in remove_eq_conds() */
965
bool substitute_null_with_insert_id;
968
bool abort_on_warning;
969
bool got_warning; /**< Set on call to push_warning() */
970
bool no_warnings_for_error; /**< no warnings on call to my_error() */
971
/** set during loop of derived table processing */
972
bool derived_tables_processing;
973
bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
975
/** Used by the sys_var class to store temporary values */
979
uint32_t uint32_t_value;
980
int32_t int32_t_value;
981
uint64_t uint64_t_value;
985
Character input stream consumed by the lexical analyser,
987
Note that since the parser is not re-entrant, we keep only one input
988
stream here. This member is valid only when executing code during parsing,
989
and may point to invalid memory after that.
991
Lex_input_stream *m_lip;
993
/** Place to store various things */
994
void *session_marker;
996
/** Keeps a copy of the previous table around in case we are just slamming on particular table */
1000
Points to info-string that we show in SHOW PROCESSLIST
1001
You are supposed to call Session_SET_PROC_INFO only if you have coded
1002
a time-consuming piece that MySQL can get stuck in for a long time.
1004
Set it using the session_proc_info(Session *thread, const char *message)
1007
inline void set_proc_info(const char *info)
1011
inline const char* get_proc_info() const
1016
/** Sets this Session's current query ID */
1017
inline void setQueryId(query_id_t in_query_id)
1019
query_id= in_query_id;
1022
/** Returns the current query ID */
1023
query_id_t getQueryId() const
1029
/** Sets this Session's warning query ID */
1030
inline void setWarningQueryId(query_id_t in_query_id)
1032
warn_query_id= in_query_id;
1035
/** Returns the Session's warning query ID */
1036
inline query_id_t getWarningQueryId() const
1038
return warn_query_id;
1041
/** Accessor method returning the session's ID. */
1042
inline session_id_t getSessionId() const
1047
/** Accessor method returning the server's ID. */
1048
inline uint32_t getServerId() const
1050
/* We return the global server ID. */
1054
/** Returns the current transaction ID for the session's current statement */
1055
inline my_xid getTransactionId()
1057
return transaction.xid_state.xid.quick_get_my_xid();
1060
1222
There is BUG#19630 where statement-based replication of stored
1061
1223
functions/triggers with two auto_increment columns breaks.
1062
1224
We however ensure that it works when there is 0 or 1 auto_increment
1112
1281
auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
1115
Session(plugin::Client *client_arg);
1284
uint64_t limit_found_rows;
1285
uint64_t options; /* Bitmap of states */
1286
int64_t row_count_func; /* For the ROW_COUNT() function */
1287
ha_rows cuted_fields;
1290
number of rows we actually sent to the client, including "synthetic"
1293
ha_rows sent_row_count;
1296
number of rows we read, sent or not, including in create_sort_index()
1298
ha_rows examined_row_count;
1301
The set of those tables whose fields are referenced in all subqueries
1303
TODO: possibly this it is incorrect to have used tables in Session because
1304
with more than one subquery, it is not clear what does the field mean.
1306
table_map used_tables;
1307
USER_CONN *user_connect;
1308
const CHARSET_INFO *db_charset;
1310
FIXME: this, and some other variables like 'count_cuted_fields'
1311
maybe should be statement/cursor local, that is, moved to Statement
1312
class. With current implementation warnings produced in each prepared
1313
statement/cursor settle here.
1315
List <DRIZZLE_ERROR> warn_list;
1316
uint warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_END];
1317
uint total_warn_count;
1318
Diagnostics_area main_da;
1321
Id of current query. Statement can be reused to execute several queries
1322
query_id is global in context of the whole MySQL server.
1323
ID is automatically generated from mutex-protected counter.
1324
It's used in handler code for various purposes: to check which columns
1325
from table are necessary for this select, to check if it's necessary to
1326
update auto-updatable fields (like auto_increment and timestamp).
1328
query_id_t query_id, warn_id;
1331
#ifdef ERROR_INJECT_SUPPORT
1332
ulong error_inject_value;
1334
/* Statement id is thread-wide. This counter is used to generate ids */
1335
ulong statement_id_counter;
1336
ulong rand_saved_seed1, rand_saved_seed2;
1338
Row counter, mainly for errors and warnings. Not increased in
1339
create_sort_index(); may differ from examined_row_count.
1342
pthread_t real_id; /* For debugging */
1343
my_thread_id thread_id;
1344
uint tmp_table, global_read_lock;
1345
uint server_status,open_options;
1346
enum enum_thread_type system_thread;
1347
uint32_t select_number; //number of select (used for EXPLAIN)
1348
/* variables.transaction_isolation is reset to this after each commit */
1349
enum_tx_isolation session_tx_isolation;
1350
enum_check_fields count_cuted_fields;
1352
DYNAMIC_ARRAY user_var_events; /* For user variables replication */
1353
MEM_ROOT *user_var_events_alloc; /* Allocate above array elements here */
1361
KILLED_NO_VALUE /* means neither of the states */
1363
killed_state volatile killed;
1365
/* scramble - random string sent to client on handshake */
1366
char scramble[SCRAMBLE_LENGTH+1];
1368
bool slave_thread, one_shot_set;
1369
/* tells if current statement should binlog row-based(1) or stmt-based(0) */
1370
bool current_stmt_binlog_row_based;
1371
bool some_tables_deleted;
1372
bool last_cuted_field;
1373
bool no_errors, password;
1375
Set to true if execution of the current compound statement
1376
can not continue. In particular, disables activation of
1377
CONTINUE or EXIT handlers of stored routines.
1378
Reset in the end of processing of the current user request, in
1379
@see mysql_reset_session_for_next_command().
1381
bool is_fatal_error;
1383
Set by a storage engine to request the entire
1384
transaction (that possibly spans multiple engines) to
1385
rollback. Reset in ha_rollback.
1387
bool transaction_rollback_request;
1389
true if we are in a sub-statement and the current error can
1390
not be safely recovered until we left the sub-statement mode.
1391
In particular, disables activation of CONTINUE and EXIT
1392
handlers inside sub-statements. E.g. if it is a deadlock
1393
error and requires a transaction-wide rollback, this flag is
1394
raised (traditionally, MySQL first has to close all the reads
1395
via @see handler::ha_index_or_rnd_end() and only then perform
1397
Reset to false when we leave the sub-statement mode.
1399
bool is_fatal_sub_stmt_error;
1400
bool query_start_used, rand_used, time_zone_used;
1401
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
1402
bool substitute_null_with_insert_id;
1403
bool in_lock_tables;
1405
True if a slave error. Causes the slave to stop. Not the same
1406
as the statement execution error (is_error()), since
1407
a statement may be expected to return an error, e.g. because
1408
it returned an error on master, and this is OK on the slave.
1410
bool is_slave_error;
1413
/** is set if some thread specific value(s) used in a statement. */
1414
bool thread_specific_used;
1415
bool charset_is_system_charset, charset_is_collation_connection;
1416
bool charset_is_character_set_filesystem;
1417
bool abort_on_warning;
1418
bool got_warning; /* Set on call to push_warning() */
1419
bool no_warnings_for_error; /* no warnings on call to my_error() */
1420
/* set during loop of derived table processing */
1421
bool derived_tables_processing;
1422
bool tablespace_op; /* This is true in DISCARD/IMPORT TABLESPACE */
1425
If we do a purge of binary logs, log index info of the threads
1426
that are currently reading it needs to be adjusted. To do that
1427
each thread that is using LOG_INFO needs to adjust the pointer to it
1429
LOG_INFO* current_linfo;
1430
NET* slave_net; // network connection from slave -> m.
1431
/* Used by the sys_var class to store temporary values */
1437
uint64_t uint64_t_value;
1442
If true, mysql_bin_log::write(Log_event) call will not write events to
1443
binlog, and maintain 2 below variables instead (use
1444
mysql_bin_log.start_union_events to turn this on)
1448
If true, at least one mysql_bin_log::write(Log_event) call has been
1449
made after last mysql_bin_log.start_union_events() call.
1451
bool unioned_events;
1453
If true, at least one mysql_bin_log::write(Log_event e), where
1454
e.cache_stmt == true call has been made after last
1455
mysql_bin_log.start_union_events() call.
1457
bool unioned_events_trans;
1460
'queries' (actually SP statements) that run under inside this binlog
1461
union have session->query_id >= first_query_id.
1463
query_id_t first_query_id;
1467
Character input stream consumed by the lexical analyser,
1468
used during parsing.
1469
Note that since the parser is not re-entrant, we keep only one input
1470
stream here. This member is valid only when executing code during parsing,
1471
and may point to invalid memory after that.
1473
Lex_input_stream *m_lip;
1480
Initialize memory roots necessary for query processing and (!)
1481
pre-allocate memory for it. We can't do that in Session constructor because
1482
there are use cases (acl_init, watcher threads,
1483
killing mysqld) where it's vital to not allocate excessive and not used
1484
memory. Note, that we still don't return error from init_for_queries():
1485
if preallocation fails, we should notice that at the first call to
1488
void init_for_queries();
1489
void change_user(void);
1118
1490
void cleanup(void);
1120
* Cleans up after query.
1124
* This function is used to reset thread data to its default state.
1126
* This function is not suitable for setting thread data to some
1127
* non-default values, as there is only one replication thread, so
1128
* different master threads may overwrite data of each other on
1131
1491
void cleanup_after_query();
1132
bool storeGlobals();
1133
void awake(Session::killed_state_t state_to_set);
1135
* Pulls thread-specific variables into Session state.
1137
* Returns true most times, or false if there was a problem
1138
* allocating resources for thread-specific storage.
1140
* @TODO Kill this. It's not necessary once my_thr_init() is bye bye.
1146
Initialize memory roots necessary for query processing and (!)
1147
pre-allocate memory for it. We can't do that in Session constructor because
1148
there are use cases where it's vital to not allocate excessive and not used
1151
void prepareForQueries();
1154
* Executes a single statement received from the
1155
* client connection.
1157
* Returns true if the statement was successful, or false
1162
* For profiling to work, it must never be called recursively.
1164
* In MySQL, this used to be the do_command() C function whic
1165
* accepted a single parameter of the THD pointer.
1167
bool executeStatement();
1170
* Reads a query from packet and stores it.
1172
* Returns true if query is read and allocated successfully,
1173
* false otherwise. On a return of false, Session::fatal_error
1176
* @note Used in COM_QUERY and COM_STMT_PREPARE.
1178
* Sets the following Session variables:
1182
* @param The packet pointer to read from
1183
* @param The length of the query to read
1185
bool readAndStoreQuery(const char *in_packet, uint32_t in_packet_length);
1188
* Ends the current transaction and (maybe) begins the next.
1190
* Returns true if the transaction completed successfully,
1193
* @param Completion type
1195
bool endTransaction(enum enum_mysql_completiontype completion);
1196
bool endActiveTransaction();
1197
bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
1200
* Authenticates users, with error reporting.
1202
* Returns true on success, or false on failure.
1204
bool authenticate();
1209
* This will initialize the session and begin the command loop.
1214
* Schedule a session to be run on the default scheduler.
1216
static bool schedule(Session::shared_ptr&);
1218
static void unlink(Session::shared_ptr&);
1492
bool store_globals();
1493
void awake(Session::killed_state state_to_set);
1495
enum enum_binlog_query_type {
1497
The query can be logged row-based or statement-based
1502
The query has to be logged statement-based
1507
The query represents a change to a table in the "mysql"
1508
database and is currently mapped to ROW_QUERY_TYPE.
1514
int binlog_query(enum_binlog_query_type qtype,
1515
char const *query, ulong query_len,
1516
bool is_trans, bool suppress_use,
1517
Session::killed_state killed_err_arg= Session::KILLED_NO_VALUE);
1221
1520
For enter_cond() / exit_cond() to work the mutex must be got before
1222
1521
enter_cond(); this mutex is then released by exit_cond().
1223
1522
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
1225
const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1226
void exit_cond(const char* old_msg);
1228
inline time_t query_start() { return start_time; }
1524
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
1527
const char* old_msg = get_proc_info();
1528
safe_mutex_assert_owner(mutex);
1529
mysys_var->current_mutex = mutex;
1530
mysys_var->current_cond = cond;
1531
this->set_proc_info(msg);
1534
inline void exit_cond(const char* old_msg)
1537
Putting the mutex unlock in exit_cond() ensures that
1538
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
1539
locked (if that would not be the case, you'll get a deadlock if someone
1540
does a Session::awake() on you).
1542
pthread_mutex_unlock(mysys_var->current_mutex);
1543
pthread_mutex_lock(&mysys_var->mutex);
1544
mysys_var->current_mutex = 0;
1545
mysys_var->current_cond = 0;
1546
this->set_proc_info(old_msg);
1547
pthread_mutex_unlock(&mysys_var->mutex);
1549
inline time_t query_start() { query_start_used=1; return start_time; }
1229
1550
inline void set_time()
1231
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1232
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1233
start_utime= utime_after_lock= (mytime-epoch).total_microseconds();
1237
1554
start_time= user_time;
1238
connect_microseconds= start_utime;
1555
start_utime= utime_after_lock= my_micro_time();
1241
start_time= (mytime-epoch).total_seconds();
1558
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1243
inline void set_current_time() { start_time= time(NULL); }
1560
inline void set_current_time() { start_time= my_time(MY_WME); }
1244
1561
inline void set_time(time_t t)
1246
1563
start_time= user_time= t;
1247
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1248
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1249
uint64_t t_mark= (mytime-epoch).total_microseconds();
1251
start_utime= utime_after_lock= t_mark;
1253
void set_time_after_lock() {
1254
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1255
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1256
utime_after_lock= (mytime-epoch).total_microseconds();
1259
* Returns the current micro-timestamp
1261
inline uint64_t getCurrentTimestamp()
1263
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1264
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1265
uint64_t t_mark= (mytime-epoch).total_microseconds();
1564
start_utime= utime_after_lock= my_micro_time();
1566
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
1567
uint64_t current_utime() { return my_micro_time(); }
1269
1568
inline uint64_t found_rows(void)
1271
1570
return limit_found_rows;
1273
/** Returns whether the session is currently inside a transaction */
1274
inline bool inTransaction()
1572
inline bool active_transaction()
1276
1574
return server_status & SERVER_STATUS_IN_TRANS;
1576
inline bool fill_derived_tables()
1578
return !lex->only_view_structure();
1580
inline void* trans_alloc(unsigned int size)
1582
return alloc_root(&transaction.mem_root,size);
1278
1585
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1279
1586
const char* str, uint32_t length,
1280
1587
bool allocate_lex_string);
1281
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1282
const std::string &str,
1283
bool allocate_lex_string);
1589
bool convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
1590
const char *from, uint32_t from_length,
1591
const CHARSET_INFO * const from_cs);
1593
bool convert_string(String *s, const CHARSET_INFO * const from_cs, const CHARSET_INFO * const to_cs);
1595
void add_changed_table(Table *table);
1596
void add_changed_table(const char *key, long key_length);
1597
CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1285
1598
int send_explain_fields(select_result *result);
1287
1600
Clear the current error, if any.
1596
1802
- for prepared queries, only to allocate runtime data. The parsed
1597
1803
tree itself is reused between executions and thus is stored elsewhere.
1599
memory::Root main_mem_root;
1602
* Marks all tables in the list which were used by current substatement
1603
* as free for reuse.
1605
* @param Head of the list of tables
1609
* The reason we reset query_id is that it's not enough to just test
1610
* if table->query_id != session->query_id to know if a table is in use.
1614
* SELECT f1_that_uses_t1() FROM t1;
1616
* In f1_that_uses_t1() we will see one instance of t1 where query_id is
1617
* set to query_id of original query.
1619
void mark_used_tables_as_free_for_reuse(Table *table);
1623
/** A short cut for session->main_da.set_ok_status(). */
1624
inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1625
uint64_t passed_id= 0, const char *message= NULL)
1627
main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
1631
/** A short cut for session->main_da.set_eof_status(). */
1633
inline void my_eof()
1635
main_da.set_eof_status(this);
1638
/* Some inline functions for more speed */
1640
inline bool add_item_to_list(Item *item)
1642
return lex->current_select->add_item_to_list(this, item);
1645
inline bool add_value_to_list(Item *value)
1647
return lex->value_list.push_back(value);
1650
inline bool add_order_to_list(Item *item, bool asc)
1652
return lex->current_select->add_order_to_list(this, item, asc);
1655
inline bool add_group_to_list(Item *item, bool asc)
1657
return lex->current_select->add_group_to_list(this, item, asc);
1659
void refresh_status();
1660
user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1661
user_var_entry *getVariable(const std::string &name, bool create_if_not_exists);
1662
void setVariable(const std::string &name, const std::string &value);
1665
* Closes all tables used by the current substatement, or all tables
1666
* used by this thread if we are on the upper level.
1668
void close_thread_tables();
1669
void close_old_data_files(bool morph_locks= false,
1670
bool send_refresh= false);
1671
void close_open_tables();
1672
void close_data_files_and_morph_locks(const TableIdentifier &identifier);
1675
bool free_cached_table();
1679
* Prepares statement for reopening of tables and recalculation of set of
1682
* @param Pointer to a pointer to a list of tables which we were trying to open and lock
1684
void close_tables_for_reopen(TableList **tables);
1688
* Open all tables in list, locks them (all, including derived)
1690
* @param Pointer to a list of tables for open & locking
1699
* The lock will automaticaly be freed by close_thread_tables()
1701
bool openTablesLock(TableList *tables);
1703
int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1705
Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1706
Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1708
void unlink_open_table(Table *find);
1709
void drop_open_table(Table *table, const TableIdentifier &identifier);
1710
void close_cached_table(Table *table);
1712
/* Create a lock in the cache */
1713
table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
1714
bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
1716
typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1720
TableMessageCache table_message_cache;
1723
bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1724
bool removeTableMessage(const TableIdentifier &identifier);
1725
bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1726
bool doesTableMessageExist(const TableIdentifier &identifier);
1727
bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1731
TableMessages _table_message_cache;
1734
TableMessages &getMessageCache()
1736
return _table_message_cache;
1739
/* Reopen operations */
1740
bool reopen_tables(bool get_locks, bool mark_share_as_old);
1741
bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1743
void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1744
int setup_conds(TableList *leaves, COND **conds);
1745
int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1747
drizzled::util::Storable *getProperty(const std::string &arg)
1749
return life_properties[arg];
1753
bool setProperty(const std::string &arg, T *value)
1755
life_properties[arg]= value;
1761
Return the default storage engine
1763
@param getDefaultStorageEngine()
1766
pointer to plugin::StorageEngine
1768
plugin::StorageEngine *getDefaultStorageEngine()
1770
if (variables.storage_engine)
1771
return variables.storage_engine;
1772
return global_system_variables.storage_engine;
1775
void get_xid(DRIZZLE_XID *xid); // Innodb only
1777
table::Instance *getInstanceTable();
1778
table::Instance *getInstanceTable(List<CreateField> &field_list);
1783
if (getrusage(RUSAGE_THREAD, &usage))
1792
void setUsage(bool arg)
1797
const struct rusage &getUsage()
1803
// This lives throughout the life of Session
1805
PropertyMap life_properties;
1806
std::vector<table::Instance *> temporary_shares;
1807
struct rusage usage;
1805
MEM_ROOT main_mem_root;
1809
/** A short cut for session->main_da.set_ok_status(). */
1812
my_ok(Session *session, ha_rows affected_rows= 0, uint64_t id= 0,
1813
const char *message= NULL)
1815
session->main_da.set_ok_status(session, affected_rows, id, message);
1819
/** A short cut for session->main_da.set_eof_status(). */
1822
my_eof(Session *session)
1824
session->main_da.set_eof_status(session);
1827
#define tmp_disable_binlog(A) \
1828
{uint64_t tmp_disable_binlog__save_options= (A)->options; \
1829
(A)->options&= ~OPTION_BIN_LOG
1831
#define reenable_binlog(A) (A)->options= tmp_disable_binlog__save_options;}
1835
Used to hold information about file and file structure in exchange
1836
via non-DB file (...INTO OUTFILE..., ...LOAD DATA...)
1837
XXX: We never call destructor for objects of this class.
1840
class sql_exchange :public Sql_alloc
1843
enum enum_filetype filetype; /* load XML, Added by Arnold & Erik */
1845
String *field_term,*enclosed,*line_term,*line_start,*escaped;
1849
const CHARSET_INFO *cs;
1850
sql_exchange(char *name, bool dumpfile_flag,
1851
enum_filetype filetype_arg= FILETYPE_CSV);
1854
#include "log_event.h"
1857
This is used to get result from a select
1862
class select_result :public Sql_alloc {
1865
SELECT_LEX_UNIT *unit;
1868
virtual ~select_result() {};
1869
virtual int prepare(List<Item> &list __attribute__((unused)),
1875
virtual int prepare2(void) { return 0; }
1877
Because of peculiarities of prepared statements protocol
1878
we need to know number of columns in the result set (if
1879
there is a result set) apart from sending columns metadata.
1881
virtual uint32_t field_count(List<Item> &fields) const
1882
{ return fields.elements; }
1883
virtual bool send_fields(List<Item> &list, uint32_t flags)=0;
1884
virtual bool send_data(List<Item> &items)=0;
1885
virtual bool initialize_tables (JOIN __attribute__((unused)) *join=0)
1887
virtual void send_error(uint32_t errcode,const char *err);
1888
virtual bool send_eof()=0;
1890
Check if this query returns a result set and therefore is allowed in
1891
cursors and set an error message if it is not the case.
1893
@retval false success
1894
@retval true error, an error message is set
1896
virtual bool check_simple_select() const;
1897
virtual void abort() {}
1899
Cleanup instance of this class for next execution of a prepared
1900
statement/stored procedure.
1902
virtual void cleanup();
1903
void set_session(Session *session_arg) { session= session_arg; }
1904
void begin_dataset() {}
1909
Base class for select_result descendands which intercept and
1910
transform result set rows. As the rows are not sent to the client,
1911
sending of result set metadata should be suppressed as well.
1914
class select_result_interceptor: public select_result
1917
select_result_interceptor() {} /* Remove gcc warning */
1918
uint32_t field_count(List<Item> &fields __attribute__((unused))) const
1920
bool send_fields(List<Item> &fields __attribute__((unused)),
1921
uint32_t flag __attribute__((unused))) { return false; }
1925
class select_send :public select_result {
1927
True if we have sent result set metadata to the client.
1928
In this case the client always expects us to end the result
1929
set with an eof or error packet
1931
bool is_result_set_started;
1933
select_send() :is_result_set_started(false) {}
1934
bool send_fields(List<Item> &list, uint32_t flags);
1935
bool send_data(List<Item> &items);
1937
virtual bool check_simple_select() const { return false; }
1939
virtual void cleanup();
1943
class select_to_file :public select_result_interceptor {
1945
sql_exchange *exchange;
1949
char path[FN_REFLEN];
1952
select_to_file(sql_exchange *ex) :exchange(ex), file(-1),row_count(0L)
1955
void send_error(uint32_t errcode,const char *err);
1812
1961
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1814
} /* namespace drizzled */
1816
/** @TODO why is this in the middle of the file */
1817
#include <drizzled/select_to_file.h>
1818
#include <drizzled/select_export.h>
1819
#include <drizzled/select_dump.h>
1820
#include <drizzled/select_insert.h>
1821
#include <drizzled/select_create.h>
1822
#include <drizzled/tmp_table_param.h>
1823
#include <drizzled/select_union.h>
1824
#include <drizzled/select_subselect.h>
1825
#include <drizzled/select_singlerow_subselect.h>
1826
#include <drizzled/select_max_min_finder_subselect.h>
1827
#include <drizzled/select_exists_subselect.h>
1833
* A structure used to describe sort information
1834
* for a field or item used in ORDER BY.
1965
List of all possible characters of a numeric value text representation.
1967
#define NUMERIC_CHARS ".0123456789e+-"
1970
class select_export :public select_to_file {
1971
uint32_t field_term_length;
1972
int field_sep_char,escape_char,line_sep_char;
1973
int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
1975
The is_ambiguous_field_sep field is true if a value of the field_sep_char
1976
field is one of the 'n', 't', 'r' etc characters
1977
(see the READ_INFO::unescape method and the ESCAPE_CHARS constant value).
1979
bool is_ambiguous_field_sep;
1981
The is_ambiguous_field_term is true if field_sep_char contains the first
1982
char of the FIELDS TERMINATED BY (ENCLOSED BY is empty), and items can
1983
contain this character.
1985
bool is_ambiguous_field_term;
1987
The is_unsafe_field_sep field is true if a value of the field_sep_char
1988
field is one of the '0'..'9', '+', '-', '.' and 'e' characters
1989
(see the NUMERIC_CHARS constant value).
1991
bool is_unsafe_field_sep;
1992
bool fixed_row_size;
1994
select_export(sql_exchange *ex) :select_to_file(ex) {}
1996
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
1997
bool send_data(List<Item> &items);
2001
class select_dump :public select_to_file {
2003
select_dump(sql_exchange *ex) :select_to_file(ex) {}
2004
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2005
bool send_data(List<Item> &items);
2009
class select_insert :public select_result_interceptor {
2011
TableList *table_list;
2014
uint64_t autoinc_value_of_last_inserted_row; // autogenerated or not
2016
bool insert_into_view;
2017
select_insert(TableList *table_list_par,
2018
Table *table_par, List<Item> *fields_par,
2019
List<Item> *update_fields, List<Item> *update_values,
2020
enum_duplicates duplic, bool ignore);
2022
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2023
virtual int prepare2(void);
2024
bool send_data(List<Item> &items);
2025
virtual void store_values(List<Item> &values);
2026
virtual bool can_rollback_data() { return 0; }
2027
void send_error(uint32_t errcode,const char *err);
2030
/* not implemented: select_insert is never re-used in prepared statements */
2035
class select_create: public select_insert {
2037
TableList *create_table;
2038
HA_CREATE_INFO *create_info;
2039
TableList *select_tables;
2040
Alter_info *alter_info;
2042
/* lock data for tmp table */
2043
DRIZZLE_LOCK *m_lock;
2044
/* m_lock or session->extra_lock */
2045
DRIZZLE_LOCK **m_plock;
2047
select_create (TableList *table_arg,
2048
HA_CREATE_INFO *create_info_par,
2049
Alter_info *alter_info_arg,
2050
List<Item> &select_fields,enum_duplicates duplic, bool ignore,
2051
TableList *select_tables_arg)
2052
:select_insert (NULL, NULL, &select_fields, 0, 0, duplic, ignore),
2053
create_table(table_arg),
2054
create_info(create_info_par),
2055
select_tables(select_tables_arg),
2056
alter_info(alter_info_arg),
2059
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2061
void binlog_show_create_table(Table **tables, uint32_t count);
2062
void store_values(List<Item> &values);
2063
void send_error(uint32_t errcode,const char *err);
2066
virtual bool can_rollback_data() { return 1; }
2068
// Needed for access from local class MY_HOOKS in prepare(), since session is proteted.
2069
const Session *get_session(void) { return session; }
2070
const HA_CREATE_INFO *get_create_info() { return create_info; };
2071
int prepare2(void) { return 0; }
2074
#include <storage/myisam/myisam.h>
2077
Param to create temporary tables when doing SELECT:s
2079
This structure is copied using memcpy as a part of JOIN.
2082
class TMP_TABLE_PARAM :public Sql_alloc
2085
/* Prevent use of these (not safe because of lists and copy_field) */
2086
TMP_TABLE_PARAM(const TMP_TABLE_PARAM &);
2087
void operator=(TMP_TABLE_PARAM &);
2090
List<Item> copy_funcs;
2091
List<Item> save_copy_funcs;
2092
Copy_field *copy_field, *copy_field_end;
2093
Copy_field *save_copy_field, *save_copy_field_end;
2094
unsigned char *group_buff;
2095
Item **items_to_copy; /* Fields in tmp table */
2096
MI_COLUMNDEF *recinfo,*start_recinfo;
2098
ha_rows end_write_records;
2099
uint field_count,sum_func_count,func_count;
2100
uint32_t hidden_field_count;
2101
uint group_parts,group_length,group_null_parts;
2103
bool using_indirect_summary_function;
2104
/* If >0 convert all blob fields to varchar(convert_blob_length) */
2105
uint32_t convert_blob_length;
2106
const CHARSET_INFO *table_charset;
2109
True if GROUP BY and its aggregate functions are already computed
2110
by a table access method (e.g. by loose index scan). In this case
2111
query execution should not perform aggregation and should treat
2112
aggregate functions as normal functions.
2114
bool precomputed_group_by;
2115
bool force_copy_fields;
2117
If true, create_tmp_field called from create_tmp_table will convert
2118
all BIT fields to 64-bit longs. This is a workaround the limitation
2119
that MEMORY tables cannot index BIT columns.
2121
bool bit_fields_as_long;
2124
:copy_field(0), group_parts(0),
2125
group_length(0), group_null_parts(0), convert_blob_length(0),
2126
schema_table(0), precomputed_group_by(0), force_copy_fields(0),
2127
bit_fields_as_long(0)
2134
inline void cleanup(void)
2136
if (copy_field) /* Fix for Intel compiler */
2138
delete [] copy_field;
2139
save_copy_field= copy_field= 0;
2144
class select_union :public select_result_interceptor
2146
TMP_TABLE_PARAM tmp_table_param;
2150
select_union() :table(0) {}
2151
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2152
bool send_data(List<Item> &items);
2156
bool create_result_table(Session *session, List<Item> *column_types,
2157
bool is_distinct, uint64_t options,
2158
const char *alias, bool bit_fields_as_long);
2161
/* Base subselect interface class */
2162
class select_subselect :public select_result_interceptor
2165
Item_subselect *item;
2167
select_subselect(Item_subselect *item);
2168
bool send_data(List<Item> &items)=0;
2169
bool send_eof() { return 0; };
2172
/* Single value subselect interface class */
2173
class select_singlerow_subselect :public select_subselect
2176
select_singlerow_subselect(Item_subselect *item_arg)
2177
:select_subselect(item_arg)
2179
bool send_data(List<Item> &items);
2182
/* used in independent ALL/ANY optimisation */
2183
class select_max_min_finder_subselect :public select_subselect
2186
bool (select_max_min_finder_subselect::*op)();
2189
select_max_min_finder_subselect(Item_subselect *item_arg, bool mx)
2190
:select_subselect(item_arg), cache(0), fmax(mx)
2193
bool send_data(List<Item> &items);
2200
/* EXISTS subselect interface class */
2201
class select_exists_subselect :public select_subselect
2204
select_exists_subselect(Item_subselect *item_arg)
2205
:select_subselect(item_arg){}
2206
bool send_data(List<Item> &items);
2209
/* Structs used when sorting */
2211
typedef struct st_sort_field {
2212
Field *field; /* Field to sort */
2213
Item *item; /* Item if not sorting fields */
2214
uint length; /* Length of sort field */
2215
uint32_t suffix_length; /* Length suffix (0-4) */
2216
Item_result result_type; /* Type of item */
2217
bool reverse; /* if descending sort */
2218
bool need_strxnfrm; /* If we have to use strxnfrm() */
2222
typedef struct st_sort_buffer {
2223
uint32_t index; /* 0 or 1 */
2224
uint32_t sort_orders;
2225
uint32_t change_pos; /* If sort-fields changed */
2227
SORT_FIELD *sortorder;
2230
/* Structure for db & table in sql_yacc */
2232
class Table_ident :public Sql_alloc
2237
SELECT_LEX_UNIT *sel;
2238
inline Table_ident(Session *session, LEX_STRING db_arg, LEX_STRING table_arg,
2240
:table(table_arg), sel((SELECT_LEX_UNIT *)0)
2242
if (!force && (session->client_capabilities & CLIENT_NO_SCHEMA))
2247
inline Table_ident(LEX_STRING table_arg)
2248
:table(table_arg), sel((SELECT_LEX_UNIT *)0)
2253
This constructor is used only for the case when we create a derived
2254
table. A derived table has no name and doesn't belong to any database.
2255
Later, if there was an alias specified for the table, it will be set
2256
by add_table_to_list.
2258
inline Table_ident(SELECT_LEX_UNIT *s) : sel(s)
2260
/* We must have a table name here as this is used with add_table_to_list */
2261
db.str= empty_c_string; /* a subject to casedn_str */
2263
table.str= internal_table_name;
2266
bool is_derived_table() const { return test(sel); }
2267
inline void change_db(char *db_name)
2269
db.str= db_name; db.length= (uint) strlen(db_name);
2273
// this is needed for user_vars hash
2274
class user_var_entry
2277
user_var_entry() {} /* Remove gcc warning */
2281
query_id_t update_query_id, used_query_id;
2285
double val_real(bool *null_value);
2286
int64_t val_int(bool *null_value) const;
2287
String *val_str(bool *null_value, String *str, uint32_t decimals);
2288
my_decimal *val_decimal(bool *null_value, my_decimal *result);
2289
DTCollation collation;
2293
Unique -- class for unique (removing of duplicates).
2294
Puts all values to the TREE. If the tree becomes too big,
2295
it's dumped to the file. User can request sorted values, or
2296
just iterate through them. In the last case tree merging is performed in
2297
memory simultaneously with iteration, so it should be ~2-3x faster.
1839
Field *field; /**< Field to sort */
1840
Item *item; /**< Item if not sorting fields */
1841
size_t length; /**< Length of sort field */
1842
uint32_t suffix_length; /**< Length suffix (0-4) */
1843
Item_result result_type; /**< Type of item */
1844
bool reverse; /**< if descending sort */
1845
bool need_strxnfrm; /**< If we have to use strxnfrm() */
1852
result_type(STRING_RESULT),
1859
} /* namespace drizzled */
1861
/** @TODO why is this in the middle of the file */
1863
#include <drizzled/table_ident.h>
1864
#include <drizzled/user_var_entry.h>
1865
#include <drizzled/unique.h>
1866
#include <drizzled/var.h>
1867
#include <drizzled/select_dumpvar.h>
2300
class Unique :public Sql_alloc
2302
DYNAMIC_ARRAY file_ptrs;
2304
uint64_t max_in_memory_size;
2307
unsigned char *record_pointers;
2313
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
2314
uint32_t size_arg, uint64_t max_in_memory_size_arg);
2316
ulong elements_in_tree() { return tree.elements_in_tree; }
2317
inline bool unique_add(void *ptr)
2319
if (tree.elements_in_tree > max_elements && flush())
2321
return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
2324
bool get(Table *table);
2325
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
2326
uint64_t max_in_memory_size);
2327
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
2328
uint64_t max_in_memory_size)
2330
register uint64_t max_elems_in_tree=
2331
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
2332
return (int) (sizeof(uint)*(1 + nkeys/max_elems_in_tree));
2336
bool walk(tree_walk_action action, void *walk_action_arg);
2338
friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique);
2339
friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique);
2343
class multi_delete :public select_result_interceptor
2345
TableList *delete_tables, *table_being_deleted;
2347
ha_rows deleted, found;
2348
uint32_t num_of_tables;
2351
/* True if at least one table we delete from is transactional */
2352
bool transactional_tables;
2353
/* True if at least one table we delete from is not transactional */
2355
bool delete_while_scanning;
2357
error handling (rollback and binlogging) can happen in send_eof()
2358
so that afterward send_error() needs to find out that.
2363
multi_delete(TableList *dt, uint32_t num_of_tables);
2365
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2366
bool send_data(List<Item> &items);
2367
bool initialize_tables (JOIN *join);
2368
void send_error(uint32_t errcode,const char *err);
2371
virtual void abort();
2375
class multi_update :public select_result_interceptor
2377
TableList *all_tables; /* query/update command tables */
2378
TableList *leaves; /* list of leves of join table tree */
2379
TableList *update_tables, *table_being_updated;
2380
Table **tmp_tables, *main_table, *table_to_update;
2381
TMP_TABLE_PARAM *tmp_table_param;
2382
ha_rows updated, found;
2383
List <Item> *fields, *values;
2384
List <Item> **fields_for_table, **values_for_table;
2385
uint32_t table_count;
2387
List of tables referenced in the CHECK OPTION condition of
2388
the updated view excluding the updated table.
2390
List <Table> unupdated_check_opt_tables;
2391
Copy_field *copy_field;
2392
enum enum_duplicates handle_duplicates;
2393
bool do_update, trans_safe;
2394
/* True if the update operation has made a change in a transactional table */
2395
bool transactional_tables;
2398
error handling (rollback and binlogging) can happen in send_eof()
2399
so that afterward send_error() needs to find out that.
2404
multi_update(TableList *ut, TableList *leaves_list,
2405
List<Item> *fields, List<Item> *values,
2406
enum_duplicates handle_duplicates, bool ignore);
2408
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2409
bool send_data(List<Item> &items);
2410
bool initialize_tables (JOIN *join);
2411
void send_error(uint32_t errcode,const char *err);
2414
virtual void abort();
2417
class my_var : public Sql_alloc {
2422
enum_field_types type;
2423
my_var (LEX_STRING& j, bool i, uint32_t o, enum_field_types t)
2424
:s(j), local(i), offset(o), type(t)
2429
class select_dumpvar :public select_result_interceptor {
2432
List<my_var> var_list;
2433
select_dumpvar() { var_list.empty(); row_count= 0;}
2434
~select_dumpvar() {}
2435
int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
2436
bool send_data(List<Item> &items);
2438
virtual bool check_simple_select() const;
1872
2442
/* Bits in sql_command_flags */
1874
enum sql_command_flag_bits
1876
CF_BIT_CHANGES_DATA,
1877
CF_BIT_HAS_ROW_COUNT,
1878
CF_BIT_STATUS_COMMAND,
1879
CF_BIT_SHOW_TABLE_COMMAND,
1880
CF_BIT_WRITE_LOGS_COMMAND,
1884
static const std::bitset<CF_BIT_SIZE> CF_CHANGES_DATA(1 << CF_BIT_CHANGES_DATA);
1885
static const std::bitset<CF_BIT_SIZE> CF_HAS_ROW_COUNT(1 << CF_BIT_HAS_ROW_COUNT);
1886
static const std::bitset<CF_BIT_SIZE> CF_STATUS_COMMAND(1 << CF_BIT_STATUS_COMMAND);
1887
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1888
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1891
const std::string &type(drizzled::Session::global_read_lock_t type);
1892
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1893
} /* namespace display */
1895
} /* namespace drizzled */
1897
#endif /* DRIZZLED_SESSION_H */
2444
#define CF_CHANGES_DATA 1
2445
#define CF_HAS_ROW_COUNT 2
2446
#define CF_STATUS_COMMAND 4
2447
#define CF_SHOW_TABLE_COMMAND 8
2448
#define CF_WRITE_LOGS_COMMAND 16
2450
/* Functions in sql_class.cc */
2452
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
2454
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
2455
STATUS_VAR *dec_var);
2457
#endif /* DRIZZLE_SERVER */
2459
#endif /* DRIZZLED_SQL_CLASS_H */