295
286
void mark_transaction_to_rollback(Session *session, bool all);
297
extern pthread_mutex_t LOCK_xid_cache;
298
extern HASH xid_cache;
302
Storage engine specific thread local data.
290
@brief State of a single command executed against this connection.
292
One connection can contain a lot of simultaneously running statements,
293
some of which could be:
294
- prepared, that is, contain placeholders,
295
To perform some action with statement we reset Session part to the state of
296
that statement, do the action, and then save back modified state from Session
297
to the statement. It will be changed in near future, and Statement will
301
class Statement: public ilink, public Query_arena
307
Storage engine specific thread local data.
308
Lifetime: one user connection.
303
Statement(const Statement &rhs); /* not implemented: */
304
Statement &operator=(const Statement &rhs); /* non-copyable */
307
Uniquely identifies each statement object in thread scope; change during
308
statement lifetime. FIXME: must be const
312
* Resource contexts for both the "statement" and "normal"
315
* Resource context at index 0:
317
* Life time: one statement within a transaction. If @@autocommit is
318
* on, also represents the entire transaction.
320
* Resource context at index 1:
322
* Life time: one transaction within a connection.
326
* If the storage engine does not participate in a transaction,
327
* there will not be a resource context.
329
drizzled::ResourceContext resource_context[2];
331
Ha_data() :ha_ptr(NULL) {}
335
* Represents a client connection to the database server.
337
* Contains the client/server protocol object, the current statement
338
* being executed, local-to-session variables and status counters, and
339
* a host of other information.
343
* The Session class should have a vector of Statement object pointers which
344
* comprise the statements executed on the Session. Until this architectural
345
* change is done, we can forget about parallel operations inside a session.
349
* Make member variables private and have inlined accessors and setters. Hide
350
* all member variables that are not critical to non-internal operations of the
353
class Session : public Open_tables_state
357
313
MARK_COLUMNS_NONE: Means mark_used_colums is not set and no indicator to
358
314
handler of fields used is set
367
323
enum enum_mark_columns mark_used_columns;
368
inline void* alloc(size_t size)
370
return alloc_root(mem_root,size);
372
inline void* calloc(size_t size)
375
if ((ptr= alloc_root(mem_root,size)))
376
memset(ptr, 0, size);
379
inline char *strdup(const char *str)
381
return strdup_root(mem_root,str);
383
inline char *strmake(const char *str, size_t size)
385
return strmake_root(mem_root,str,size);
387
inline void *memdup(const void *str, size_t size)
389
return memdup_root(mem_root,str,size);
391
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
394
if ((ptr= alloc_root(mem_root,size+gap)))
395
memcpy(ptr,str,size);
398
/** Frees all items attached to this Statement */
401
* List of items created in the parser for this query. Every item puts
402
* itself to the list on creation (see Item::Item() for details))
405
memory::Root *mem_root; /**< Pointer to current memroot */
407
* Uniquely identifies each statement object in thread scope; change during
408
* statement lifetime.
410
* @todo should be const
413
LEX *lex; /**< parse tree descriptor */
414
/** query associated with this statement */
325
LEX *lex; // parse tree descriptor
327
Points to the query associated with this statement. It's const, but
328
we need to declare it char * because all table handlers are written
329
in C and need to point to it.
331
Note that (A) if we set query = NULL, we must at the same time set
332
query_length = 0, and protect the whole operation with the
333
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
334
non-NULL value if its previous value is NULL. We do not need to protect
335
operation (B) with any mutex. To avoid crashes in races, if we do not
336
know that session->query cannot change at the moment, one should print
337
session->query like this:
338
(1) reserve the LOCK_thread_count mutex;
339
(2) check if session->query is NULL;
340
(3) if not NULL, then print at most session->query_length characters from
341
it. We will see the query_length field as either 0, or the right value
343
Assuming that the write and read of an n-bit memory field in an n-bit
344
computer is atomic, we can avoid races in the above way.
345
This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
349
uint32_t query_length; // current query length
418
352
Name of the current (default) database.
437
426
static const char * const DEFAULT_WHERE;
439
memory::Root warn_root; /**< Allocation area for warnings and errors */
440
plugin::Client *client; /**< Pointer to client object */
441
plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
442
void *scheduler_arg; /**< Pointer to the optional scheduler argument */
443
HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
444
struct system_variables variables; /**< Mutable local variables local to the session */
445
struct system_status_var status_var; /**< Session-local status counters */
446
struct system_status_var *initial_status_var; /* used by show status */
447
THR_LOCK_INFO lock_info; /**< Locking information for this session */
448
THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
449
THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
450
pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
453
* A peek into the query string for the session. This is a best effort
454
* delivery, there is no guarantee whether the content is meaningful.
456
char process_list_info[PROCESS_LIST_WIDTH+1];
459
* A pointer to the stack frame of the scheduler thread
460
* which is called first in the thread for handling a client
465
SecurityContext security_ctx;
467
inline void checkSentry() const
469
assert(this->dbug_sentry == Session_SENTRY_MAGIC);
472
const SecurityContext& getSecurityContext() const
477
SecurityContext& getSecurityContext()
483
* Is this session viewable by the current user?
485
bool isViewable() const
487
return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
428
NET net; // client connection descriptor
429
MEM_ROOT warn_root; // For warnings and errors
430
Protocol *protocol; // Current protocol
431
Protocol_text protocol_text; // Normal protocol
432
HASH user_vars; // hash for user variables
433
String packet; // dynamic buffer for network I/O
434
String convert_buffer; // buffer for charset conversions
435
struct system_variables variables; // Changeable local variables
436
struct system_status_var status_var; // Per thread statistic vars
437
struct system_status_var *initial_status_var; /* used by show status */
438
THR_LOCK_INFO lock_info; // Locking info of this thread
439
THR_LOCK_OWNER main_lock_id; // To use for conventional queries
440
THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to
441
// the lock_id of a cursor.
442
pthread_mutex_t LOCK_delete; // Locked before session is deleted
443
char process_list_info[PROCESS_LIST_WIDTH];
445
A pointer to the stack frame of handle_one_connection(),
446
which is called first in the thread for handling a client
451
Currently selected catalog.
457
Some members of Session (currently 'Statement::db',
458
'catalog' and 'query') are set and alloced by the slave SQL thread
459
(for the Session of that thread); that thread is (and must remain, for now)
460
the only responsible for freeing these 3 members. If you add members
461
here, and you add code to set them in replication, don't forget to
462
free_them_and_set_them_to_0 in replication properly. For details see
463
the 'err:' label of the handle_slave_sql() in sql/slave.cc.
465
@see handle_slave_sql
468
Security_context security_ctx;
471
Points to info-string that we show in SHOW PROCESSLIST
472
You are supposed to call Session_SET_PROC_INFO only if you have coded
473
a time-consuming piece that MySQL can get stuck in for a long time.
475
Set it using the session_proc_info(Session *thread, const char *message)
478
void set_proc_info(const char *info) { proc_info= info; }
479
const char* get_proc_info() const { return proc_info; }
493
482
Used in error messages to tell user in what part of MySQL we found an
494
483
error. E. g. when where= "having clause", if fix_fields() fails, user
495
484
will know that the error was in having clause.
497
486
const char *where;
488
double tmp_double_value; /* Used in set_var.cc */
489
ulong client_capabilities; /* What the client supports */
490
ulong max_client_packet_length;
500
493
One thread can hold up to one named user-level lock. This variable
501
494
points to a lock object if the lock is present. See item_func.cc and
502
495
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
504
uint32_t dbug_sentry; /**< watch for memory corruption */
505
internal::st_my_thread_var *mysys_var;
507
* Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
508
* first byte of the packet in executeStatement()
497
uint32_t dbug_sentry; // watch out for memory corruption
498
struct st_my_thread_var *mysys_var;
500
Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
501
first byte of the packet in executeStatement()
510
503
enum enum_server_command command;
511
uint32_t file_id; /**< File ID for LOAD DATA INFILE */
512
/* @note the following three members should likely move to Client */
513
uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
516
uint64_t thr_create_utime; /**< track down slow pthread_create */
517
uint64_t start_utime;
518
uint64_t utime_after_lock;
505
uint32_t file_id; // for LOAD DATA INFILE
506
/* remote (peer) port */
508
time_t start_time, user_time;
509
uint64_t connect_utime, thr_create_utime; // track down slow pthread_create
510
uint64_t start_utime, utime_after_lock;
520
512
thr_lock_type update_lock_default;
523
515
Both of the following container points in session will be converted to an API.
527
518
/* container for handler's private per-connection data */
528
std::vector<Ha_data> ha_data;
530
Id of current query. Statement can be reused to execute several queries
531
query_id is global in context of the whole MySQL server.
532
ID is automatically generated from an atomic counter.
533
It's used in Cursor code for various purposes: to check which columns
534
from table are necessary for this select, to check if it's necessary to
535
update auto-updatable fields (like auto_increment and timestamp).
538
query_id_t warn_query_id;
519
Ha_data ha_data[MAX_HA];
521
/* container for replication data */
522
void *replication_data;
523
inline void setReplicationData (void *data) { replication_data= data; }
524
inline void *getReplicationData () { return replication_data; }
526
/* Place to store various things */
527
void *session_marker;
529
void set_server_id(uint32_t sid) { server_id = sid; }
540
void **getEngineData(const plugin::MonitoredInTransaction *monitored);
541
ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
544
533
struct st_transactions {
545
std::deque<NamedSavepoint> savepoints;
546
TransactionContext all; ///< Trans since BEGIN WORK
547
TransactionContext stmt; ///< Trans for current statement
534
SAVEPOINT *savepoints;
535
Session_TRANS all; // Trans since BEGIN WORK
536
Session_TRANS stmt; // Trans for current statement
537
bool on; // see ha_enable_transaction()
548
538
XID_STATE xid_state;
541
Tables changed in transaction (that must be invalidated in query cache).
542
List contain only transactional tables, that not invalidated in query
543
cache (instead of full list of changed in transaction tables).
545
CHANGED_TableList* changed_tables;
546
MEM_ROOT mem_root; // Transaction-life memory allocation pool
551
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
555
memset(this, 0, sizeof(*this));
556
xid_state.xid.null();
557
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
563
561
sigset_t signals;
565
563
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
611
610
in the binlog is still needed; the list's minimum will contain 3.
613
612
Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
614
/** Used by replication and SET INSERT_ID */
613
/* Used by replication and SET INSERT_ID */
615
614
Discrete_intervals_list auto_inc_intervals_forced;
617
uint64_t limit_found_rows;
618
uint64_t options; /**< Bitmap of options */
619
int64_t row_count_func; /**< For the ROW_COUNT() function */
620
ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
623
* Number of rows we actually sent to the client, including "synthetic"
624
* rows in ROLLUP etc.
626
ha_rows sent_row_count;
629
* Number of rows we read, sent or not, including in create_sort_index()
631
ha_rows examined_row_count;
634
* The set of those tables whose fields are referenced in all subqueries
639
* Possibly this it is incorrect to have used tables in Session because
640
* with more than one subquery, it is not clear what does the field mean.
642
table_map used_tables;
647
This, and some other variables like 'count_cuted_fields'
648
maybe should be statement/cursor local, that is, moved to Statement
649
class. With current implementation warnings produced in each prepared
650
statement/cursor settle here.
652
List<DRIZZLE_ERROR> warn_list;
653
uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
654
uint32_t total_warn_count;
655
Diagnostics_area main_da;
659
/* Statement id is thread-wide. This counter is used to generate ids */
660
uint32_t statement_id_counter;
661
uint32_t rand_saved_seed1;
662
uint32_t rand_saved_seed2;
664
Row counter, mainly for errors and warnings. Not increased in
665
create_sort_index(); may differ from examined_row_count.
668
pthread_t real_id; /**< For debugging */
671
uint32_t global_read_lock;
672
uint32_t server_status;
673
uint32_t open_options;
674
uint32_t select_number; /**< number of select (used for EXPLAIN) */
675
/* variables.transaction_isolation is reset to this after each commit */
676
enum_tx_isolation session_tx_isolation;
677
enum_check_fields count_cuted_fields;
685
KILLED_NO_VALUE /* means none of the above states apply */
687
killed_state volatile killed;
689
bool some_tables_deleted;
693
Set to true if execution of the current compound statement
694
can not continue. In particular, disables activation of
695
CONTINUE or EXIT handlers of stored routines.
696
Reset in the end of processing of the current user request, in
697
@see mysql_reset_session_for_next_command().
701
Set by a storage engine to request the entire
702
transaction (that possibly spans multiple engines) to
703
rollback. Reset in ha_rollback.
705
bool transaction_rollback_request;
707
true if we are in a sub-statement and the current error can
708
not be safely recovered until we left the sub-statement mode.
709
In particular, disables activation of CONTINUE and EXIT
710
handlers inside sub-statements. E.g. if it is a deadlock
711
error and requires a transaction-wide rollback, this flag is
712
raised (traditionally, MySQL first has to close all the reads
713
via @see handler::ha_index_or_rnd_end() and only then perform
715
Reset to false when we leave the sub-statement mode.
717
bool is_fatal_sub_stmt_error;
718
/** for IS NULL => = last_insert_id() fix in remove_eq_conds() */
719
bool substitute_null_with_insert_id;
722
bool abort_on_warning;
723
bool got_warning; /**< Set on call to push_warning() */
724
bool no_warnings_for_error; /**< no warnings on call to my_error() */
725
/** set during loop of derived table processing */
726
bool derived_tables_processing;
727
bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
729
/** Used by the sys_var class to store temporary values */
733
uint32_t uint32_t_value;
734
int32_t int32_t_value;
735
uint64_t uint64_t_value;
739
Character input stream consumed by the lexical analyser,
741
Note that since the parser is not re-entrant, we keep only one input
742
stream here. This member is valid only when executing code during parsing,
743
and may point to invalid memory after that.
745
Lex_input_stream *m_lip;
747
/** Place to store various things */
748
void *session_marker;
750
/** Keeps a copy of the previous table around in case we are just slamming on particular table */
754
Points to info-string that we show in SHOW PROCESSLIST
755
You are supposed to call Session_SET_PROC_INFO only if you have coded
756
a time-consuming piece that MySQL can get stuck in for a long time.
758
Set it using the session_proc_info(Session *thread, const char *message)
761
inline void set_proc_info(const char *info)
765
inline const char* get_proc_info() const
770
/** Sets this Session's current query ID */
771
inline void setQueryId(query_id_t in_query_id)
773
query_id= in_query_id;
776
/** Returns the current query ID */
777
inline query_id_t getQueryId() const
783
/** Sets this Session's warning query ID */
784
inline void setWarningQueryId(query_id_t in_query_id)
786
warn_query_id= in_query_id;
789
/** Returns the Session's warning query ID */
790
inline query_id_t getWarningQueryId() const
792
return warn_query_id;
795
/** Returns the current query text */
796
inline const std::string &getQueryString() const
801
/** Returns the length of the current query text */
802
inline size_t getQueryLength() const
805
return query.length();
810
/** Accessor method returning the session's ID. */
811
inline uint64_t getSessionId() const
816
/** Accessor method returning the server's ID. */
817
inline uint32_t getServerId() const
819
/* We return the global server ID. */
823
/** Returns the current transaction ID for the session's current statement */
824
inline my_xid getTransactionId()
826
return transaction.xid_state.xid.quick_get_my_xid();
829
616
There is BUG#19630 where statement-based replication of stored
830
617
functions/triggers with two auto_increment columns breaks.
831
618
We however ensure that it works when there is 0 or 1 auto_increment
881
668
auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
884
Session(plugin::Client *client_arg);
671
uint64_t limit_found_rows;
672
uint64_t options; /* Bitmap of states */
673
int64_t row_count_func; /* For the ROW_COUNT() function */
674
ha_rows cuted_fields;
677
number of rows we actually sent to the client, including "synthetic"
680
ha_rows sent_row_count;
683
number of rows we read, sent or not, including in create_sort_index()
685
ha_rows examined_row_count;
688
The set of those tables whose fields are referenced in all subqueries
690
TODO: possibly this it is incorrect to have used tables in Session because
691
with more than one subquery, it is not clear what does the field mean.
693
table_map used_tables;
694
const CHARSET_INFO *db_charset;
696
FIXME: this, and some other variables like 'count_cuted_fields'
697
maybe should be statement/cursor local, that is, moved to Statement
698
class. With current implementation warnings produced in each prepared
699
statement/cursor settle here.
701
List <DRIZZLE_ERROR> warn_list;
702
uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
703
uint32_t total_warn_count;
704
Diagnostics_area main_da;
707
Id of current query. Statement can be reused to execute several queries
708
query_id is global in context of the whole MySQL server.
709
ID is automatically generated from mutex-protected counter.
710
It's used in handler code for various purposes: to check which columns
711
from table are necessary for this select, to check if it's necessary to
712
update auto-updatable fields (like auto_increment and timestamp).
714
query_id_t query_id, warn_id;
717
#ifdef ERROR_INJECT_SUPPORT
718
ulong error_inject_value;
720
/* Statement id is thread-wide. This counter is used to generate ids */
721
ulong statement_id_counter;
722
ulong rand_saved_seed1, rand_saved_seed2;
724
Row counter, mainly for errors and warnings. Not increased in
725
create_sort_index(); may differ from examined_row_count.
728
pthread_t real_id; /* For debugging */
729
my_thread_id thread_id;
730
uint tmp_table, global_read_lock;
731
uint server_status,open_options;
732
uint32_t select_number; //number of select (used for EXPLAIN)
733
/* variables.transaction_isolation is reset to this after each commit */
734
enum_tx_isolation session_tx_isolation;
735
enum_check_fields count_cuted_fields;
743
KILLED_NO_VALUE /* means neither of the states */
745
killed_state volatile killed;
747
bool some_tables_deleted;
748
bool last_cuted_field;
749
bool no_errors, password;
751
Set to true if execution of the current compound statement
752
can not continue. In particular, disables activation of
753
CONTINUE or EXIT handlers of stored routines.
754
Reset in the end of processing of the current user request, in
755
@see mysql_reset_session_for_next_command().
759
Set by a storage engine to request the entire
760
transaction (that possibly spans multiple engines) to
761
rollback. Reset in ha_rollback.
763
bool transaction_rollback_request;
765
true if we are in a sub-statement and the current error can
766
not be safely recovered until we left the sub-statement mode.
767
In particular, disables activation of CONTINUE and EXIT
768
handlers inside sub-statements. E.g. if it is a deadlock
769
error and requires a transaction-wide rollback, this flag is
770
raised (traditionally, MySQL first has to close all the reads
771
via @see handler::ha_index_or_rnd_end() and only then perform
773
Reset to false when we leave the sub-statement mode.
775
bool is_fatal_sub_stmt_error;
776
/* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
777
bool substitute_null_with_insert_id;
781
/** is set if some thread specific value(s) used in a statement. */
782
bool thread_specific_used;
783
bool charset_is_system_charset, charset_is_collation_connection;
784
bool charset_is_character_set_filesystem;
785
bool abort_on_warning;
786
bool got_warning; /* Set on call to push_warning() */
787
bool no_warnings_for_error; /* no warnings on call to my_error() */
788
/* set during loop of derived table processing */
789
bool derived_tables_processing;
790
bool tablespace_op; /* This is true in DISCARD/IMPORT TABLESPACE */
792
/* Used by the sys_var class to store temporary values */
796
uint32_t uint32_t_value;
799
uint64_t uint64_t_value;
803
Character input stream consumed by the lexical analyser,
805
Note that since the parser is not re-entrant, we keep only one input
806
stream here. This member is valid only when executing code during parsing,
807
and may point to invalid memory after that.
809
Lex_input_stream *m_lip;
816
Initialize memory roots necessary for query processing and (!)
817
pre-allocate memory for it. We can't do that in Session constructor because
818
there are use cases (acl_init, watcher threads,
819
killing mysqld) where it's vital to not allocate excessive and not used
820
memory. Note, that we still don't return error from init_for_queries():
821
if preallocation fails, we should notice that at the first call to
824
void init_for_queries();
887
825
void cleanup(void);
889
* Cleans up after query.
893
* This function is used to reset thread data to its default state.
895
* This function is not suitable for setting thread data to some
896
* non-default values, as there is only one replication thread, so
897
* different master threads may overwrite data of each other on
900
826
void cleanup_after_query();
827
bool store_globals();
902
828
void awake(Session::killed_state state_to_set);
904
830
* Pulls thread-specific variables into Session state.
973
896
bool authenticate();
978
* This will initialize the session and begin the command loop.
983
* Schedule a session to be run on the default scheduler.
988
899
For enter_cond() / exit_cond() to work the mutex must be got before
989
900
enter_cond(); this mutex is then released by exit_cond().
990
901
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
992
const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg);
993
void exit_cond(const char* old_msg);
903
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
905
const char* old_msg = get_proc_info();
906
safe_mutex_assert_owner(mutex);
907
mysys_var->current_mutex = mutex;
908
mysys_var->current_cond = cond;
909
this->set_proc_info(msg);
912
inline void exit_cond(const char* old_msg)
915
Putting the mutex unlock in exit_cond() ensures that
916
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
917
locked (if that would not be the case, you'll get a deadlock if someone
918
does a Session::awake() on you).
920
pthread_mutex_unlock(mysys_var->current_mutex);
921
pthread_mutex_lock(&mysys_var->mutex);
922
mysys_var->current_mutex = 0;
923
mysys_var->current_cond = 0;
924
this->set_proc_info(old_msg);
925
pthread_mutex_unlock(&mysys_var->mutex);
995
927
inline time_t query_start() { return start_time; }
996
928
inline void set_time()
1000
932
start_time= user_time;
1001
connect_microseconds= start_utime= utime_after_lock= my_micro_time();
933
start_utime= utime_after_lock= my_micro_time();
1004
936
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1198
1140
* @param Database name to connect to, may be NULL
1200
1142
bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1203
* Returns the timestamp (in microseconds) of when the Session
1204
* connected to the server.
1206
inline uint64_t getConnectMicroseconds() const
1208
return connect_microseconds;
1212
* Returns a pointer to the active Transaction message for this
1213
* Session being managed by the ReplicationServices component, or
1214
* NULL if no active message.
1216
message::Transaction *getTransactionMessage() const
1218
return transaction_message;
1222
* Returns a pointer to the active Statement message for this
1223
* Session, or NULL if no active message.
1225
message::Statement *getStatementMessage() const
1227
return statement_message;
1231
* Sets the active transaction message used by the ReplicationServices
1234
* @param[in] Pointer to the message
1236
void setTransactionMessage(message::Transaction *in_message)
1238
transaction_message= in_message;
1242
* Sets the active statement message used by the ReplicationServices
1245
* @param[in] Pointer to the message
1247
void setStatementMessage(message::Statement *in_message)
1249
statement_message= in_message;
1252
/** Pointers to memory managed by the ReplicationServices component */
1253
message::Transaction *transaction_message;
1254
message::Statement *statement_message;
1255
/** Microsecond timestamp of when Session connected */
1256
uint64_t connect_microseconds;
1257
1145
const char *proc_info;
1259
1147
/** The current internal error handler for this thread, or NULL. */
1273
1161
- for prepared queries, only to allocate runtime data. The parsed
1274
1162
tree itself is reused between executions and thus is stored elsewhere.
1276
memory::Root main_mem_root;
1279
* Marks all tables in the list which were used by current substatement
1280
* as free for reuse.
1282
* @param Head of the list of tables
1286
* The reason we reset query_id is that it's not enough to just test
1287
* if table->query_id != session->query_id to know if a table is in use.
1291
* SELECT f1_that_uses_t1() FROM t1;
1293
* In f1_that_uses_t1() we will see one instance of t1 where query_id is
1294
* set to query_id of original query.
1296
void mark_used_tables_as_free_for_reuse(Table *table);
1298
Mark all temporary tables which were used by the current statement or
1299
substatement as free for reuse, but only if the query_id can be cleared.
1301
@param session thread context
1303
@remark For temp tables associated with a open SQL HANDLER the query_id
1304
is not reset until the HANDLER is closed.
1306
void mark_temp_tables_as_free_for_reuse();
1164
MEM_ROOT main_mem_root;
1310
1167
/** A short cut for session->main_da.set_ok_status(). */
1311
inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1312
uint64_t passed_id= 0, const char *message= NULL)
1168
inline void my_ok(ha_rows affected_rows= 0, uint64_t passed_id= 0, const char *message= NULL)
1314
main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
1170
main_da.set_ok_status(this, affected_rows, passed_id, message);
1344
1200
return lex->current_select->add_group_to_list(this, item, asc);
1346
1202
void refresh_status();
1347
user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1350
* Closes all tables used by the current substatement, or all tables
1351
* used by this thread if we are on the upper level.
1353
void close_thread_tables();
1354
void close_old_data_files(bool morph_locks= false,
1355
bool send_refresh= false);
1356
void close_open_tables();
1357
void close_data_files_and_morph_locks(TableIdentifier &identifier);
1358
void close_data_files_and_morph_locks(const char *db, const char *table_name);
1361
bool free_cached_table();
1365
* Prepares statement for reopening of tables and recalculation of set of
1368
* @param Pointer to a pointer to a list of tables which we were trying to open and lock
1370
void close_tables_for_reopen(TableList **tables);
1374
* Open all tables in list, locks them (all, including derived)
1376
* @param Pointer to a list of tables for open & locking
1385
* The lock will automaticaly be freed by close_thread_tables()
1387
bool openTablesLock(TableList *tables);
1390
* Open all tables in list and process derived tables
1392
* @param Pointer to a list of tables for open
1393
* @param Bitmap of flags to modify how the tables will be open:
1394
* DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
1395
* done a flush or namelock on it.
1404
* This is to be used on prepare stage when you don't read any
1405
* data from the tables.
1407
bool openTables(TableList *tables, uint32_t flags= 0);
1409
int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1411
Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1412
Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1414
void unlink_open_table(Table *find);
1415
void drop_open_table(Table *table, TableIdentifier &identifier);
1416
void close_cached_table(Table *table);
1418
/* Create a lock in the cache */
1419
Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1420
bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1421
bool lock_table_name_if_not_cached(const char *db,
1422
const char *table_name, Table **table);
1424
typedef drizzled::hash_map<std::string, message::Table> TableMessageCache;
1425
TableMessageCache table_message_cache;
1427
bool storeTableMessage(TableIdentifier &identifier, message::Table &table_message);
1428
bool removeTableMessage(TableIdentifier &identifier);
1429
bool getTableMessage(TableIdentifier &identifier, message::Table &table_message);
1430
bool doesTableMessageExist(TableIdentifier &identifier);
1431
bool renameTableMessage(TableIdentifier &from, TableIdentifier &to);
1433
/* Work with temporary tables */
1434
Table *find_temporary_table(TableList *table_list);
1435
Table *find_temporary_table(const char *db, const char *table_name);
1436
Table *find_temporary_table(TableIdentifier &identifier);
1438
void doGetTableNames(CachedDirectory &directory,
1439
SchemaIdentifier &schema_identifier,
1440
std::set<std::string>& set_of_names);
1441
void doGetTableNames(SchemaIdentifier &schema_identifier,
1442
std::set<std::string>& set_of_names);
1444
void doGetTableIdentifiers(CachedDirectory &directory,
1445
SchemaIdentifier &schema_identifier,
1446
TableIdentifiers &set_of_identifiers);
1447
void doGetTableIdentifiers(SchemaIdentifier &schema_identifier,
1448
TableIdentifiers &set_of_identifiers);
1450
int doGetTableDefinition(drizzled::TableIdentifier &identifier,
1451
message::Table &table_proto);
1452
bool doDoesTableExist(TableIdentifier &identifier);
1454
void close_temporary_tables();
1455
void close_temporary_table(Table *table);
1456
// The method below just handles the de-allocation of the table. In
1457
// a better memory type world, this would not be needed.
1459
void nukeTable(Table *table);
1462
void dumpTemporaryTableNames(const char *id);
1463
int drop_temporary_table(TableList *table_list);
1464
bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
1465
bool rm_temporary_table(TableIdentifier &identifier);
1466
Table *open_temporary_table(TableIdentifier &identifier,
1467
bool link_in_list= true);
1469
/* Reopen operations */
1470
bool reopen_tables(bool get_locks, bool mark_share_as_old);
1471
bool reopen_name_locked_table(TableList* table_list, bool link_in);
1472
bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1474
void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1475
int setup_conds(TableList *leaves, COND **conds);
1476
int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1480
Return the default storage engine
1482
@param getDefaultStorageEngine()
1485
pointer to plugin::StorageEngine
1487
plugin::StorageEngine *getDefaultStorageEngine()
1489
if (variables.storage_engine)
1490
return variables.storage_engine;
1491
return global_system_variables.storage_engine;
1494
static void unlink(Session *session);
1206
This is used to get result from a select
1500
1212
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1502
} /* namespace drizzled */
1504
/** @TODO why is this in the middle of the file */
1505
1214
#include <drizzled/select_to_file.h>
1506
1216
#include <drizzled/select_export.h>
1507
1218
#include <drizzled/select_dump.h>
1508
1220
#include <drizzled/select_insert.h>
1509
1222
#include <drizzled/select_create.h>
1226
#include <storage/myisam/myisam.h>
1510
1228
#include <drizzled/tmp_table_param.h>
1511
1230
#include <drizzled/select_union.h>
1512
1232
#include <drizzled/select_subselect.h>
1513
1234
#include <drizzled/select_singlerow_subselect.h>
1514
1235
#include <drizzled/select_max_min_finder_subselect.h>
1515
1236
#include <drizzled/select_exists_subselect.h>
1238
/* Structs used when sorting */
1521
* A structure used to describe sort information
1522
* for a field or item used in ORDER BY.
1524
typedef struct st_sort_field
1526
Field *field; /**< Field to sort */
1527
Item *item; /**< Item if not sorting fields */
1528
size_t length; /**< Length of sort field */
1529
uint32_t suffix_length; /**< Length suffix (0-4) */
1530
Item_result result_type; /**< Type of item */
1531
bool reverse; /**< if descending sort */
1532
bool need_strxnfrm; /**< If we have to use strxnfrm() */
1240
typedef struct st_sort_field {
1241
Field *field; /* Field to sort */
1242
Item *item; /* Item if not sorting fields */
1243
size_t length; /* Length of sort field */
1244
uint32_t suffix_length; /* Length suffix (0-4) */
1245
Item_result result_type; /* Type of item */
1246
bool reverse; /* if descending sort */
1247
bool need_strxnfrm; /* If we have to use strxnfrm() */
1535
typedef struct st_sort_buffer
1537
uint32_t index; /* 0 or 1 */
1251
typedef struct st_sort_buffer {
1252
uint32_t index; /* 0 or 1 */
1538
1253
uint32_t sort_orders;
1539
uint32_t change_pos; /* If sort-fields changed */
1254
uint32_t change_pos; /* If sort-fields changed */
1541
1256
SORT_FIELD *sortorder;
1544
} /* namespace drizzled */
1546
/** @TODO why is this in the middle of the file */
1548
1260
#include <drizzled/table_ident.h>
1549
1261
#include <drizzled/user_var_entry.h>
1550
1262
#include <drizzled/unique.h>
1551
#include <drizzled/var.h>
1263
#include <drizzled/multi_delete.h>
1264
#include <drizzled/multi_update.h>
1265
#include <drizzled/my_var.h>
1552
1266
#include <drizzled/select_dumpvar.h>
1557
1268
/* Bits in sql_command_flags */
1559
enum sql_command_flag_bits
1270
enum sql_command_flag_bits {
1561
1271
CF_BIT_CHANGES_DATA,
1562
1272
CF_BIT_HAS_ROW_COUNT,
1563
1273
CF_BIT_STATUS_COMMAND,