21
21
#ifndef DRIZZLED_SESSION_H
22
22
#define DRIZZLED_SESSION_H
24
#include "drizzled/plugin.h"
25
#include "drizzled/sql_locale.h"
26
#include "drizzled/resource_context.h"
27
#include "drizzled/cursor.h"
28
#include "drizzled/current_session.h"
29
#include "drizzled/sql_error.h"
30
#include "drizzled/file_exchange.h"
31
#include "drizzled/select_result_interceptor.h"
32
#include "drizzled/statistics_variables.h"
33
#include "drizzled/xid.h"
34
#include "drizzled/query_id.h"
35
#include "drizzled/named_savepoint.h"
36
#include "drizzled/transaction_context.h"
37
#include "drizzled/util/storable.h"
38
#include "drizzled/my_hash.h"
39
#include "drizzled/pthread_globals.h"
24
/* Classes in mysql */
26
#include <drizzled/plugin/protocol.h>
27
#include <drizzled/sql_locale.h>
28
#include <drizzled/ha_trx_info.h>
29
#include <mysys/my_alloc.h>
30
#include <mysys/my_tree.h>
31
#include <drizzled/handler.h>
32
#include <drizzled/current_session.h>
33
#include <drizzled/sql_error.h>
34
#include <drizzled/file_exchange.h>
35
#include <drizzled/select_result_interceptor.h>
36
#include <drizzled/authentication.h>
37
#include <drizzled/db.h>
38
#include <drizzled/xid.h>
42
#include <sys/resource.h>
50
#include "drizzled/security_context.h"
51
#include "drizzled/open_tables_state.h"
52
#include "drizzled/internal_error_handler.h"
53
#include "drizzled/diagnostics_area.h"
54
#include "drizzled/plugin/authorization.h"
56
#include <boost/unordered_map.hpp>
58
#include <boost/thread/thread.hpp>
59
#include <boost/thread/mutex.hpp>
60
#include <boost/thread/shared_mutex.hpp>
61
#include <boost/thread/condition_variable.hpp>
62
#include <boost/make_shared.hpp>
65
44
#define MIN_HANDSHAKE_SIZE 6
74
class EventObserverList;
86
struct st_my_thread_var;
94
46
class Lex_input_stream;
95
47
class user_var_entry;
99
class TableShareInstance;
101
51
extern char internal_table_name[2];
102
52
extern char empty_c_string[1];
103
53
extern const char **errmesg;
247
193
Time_zone *time_zone;
250
extern struct drizzle_system_variables global_system_variables;
252
} /* namespace drizzled */
254
#include "drizzled/sql_lex.h"
196
extern struct system_variables global_system_variables;
201
* Per-session local status counters
203
typedef struct system_status_var
205
uint64_t bytes_received;
208
ulong com_stat[(uint32_t) SQLCOM_END];
209
ulong created_tmp_disk_tables;
210
ulong created_tmp_tables;
211
ulong ha_commit_count;
212
ulong ha_delete_count;
213
ulong ha_read_first_count;
214
ulong ha_read_last_count;
215
ulong ha_read_key_count;
216
ulong ha_read_next_count;
217
ulong ha_read_prev_count;
218
ulong ha_read_rnd_count;
219
ulong ha_read_rnd_next_count;
220
ulong ha_rollback_count;
221
ulong ha_update_count;
222
ulong ha_write_count;
223
ulong ha_prepare_count;
224
ulong ha_savepoint_count;
225
ulong ha_savepoint_rollback_count;
227
/* KEY_CACHE parts. These are copies of the original */
228
ulong key_blocks_changed;
229
ulong key_blocks_used;
230
ulong key_cache_r_requests;
231
ulong key_cache_read;
232
ulong key_cache_w_requests;
233
ulong key_cache_write;
234
/* END OF KEY_CACHE parts */
236
ulong net_big_packet_count;
239
ulong select_full_join_count;
240
ulong select_full_range_join_count;
241
ulong select_range_count;
242
ulong select_range_check_count;
243
ulong select_scan_count;
244
ulong long_query_count;
245
ulong filesort_merge_passes;
246
ulong filesort_range_count;
248
ulong filesort_scan_count;
250
Number of statements sent from the client
256
SEE last_system_status_var DEFINITION BELOW.
258
Below 'last_system_status_var' are all variables which doesn't make any
259
sense to add to the /global/ status variable counter.
261
double last_query_cost;
265
This is used for 'SHOW STATUS'. It must be updated to the last ulong
266
variable in system_status_var which is makes sens to add to the global
270
#define last_system_status_var questions
259
272
void mark_transaction_to_rollback(Session *session, bool all);
262
Storage engine specific thread local data.
267
Storage engine specific thread local data.
268
Lifetime: one user connection.
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
275
* Single command executed against this connection.
279
* One connection can contain a lot of simultaneously running statements,
280
* some of which could be prepared, that is, contain placeholders.
282
* To perform some action with statement we reset Session part to the state of
283
* that statement, do the action, and then save back modified state from Session
284
* to the statement. It will be changed in near future, and Statement will
285
* be used explicitly.
289
* The above comment is bullshit in Drizzle. See TODO markers on Session to
290
* completely detach the inheritance of Session from Statement.
313
typedef int64_t session_id_t;
315
class Session : public Open_tables_state
294
Statement(const Statement &rhs); /* not implemented: */
295
Statement &operator=(const Statement &rhs); /* non-copyable */
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;
298
* List of items created in the parser for this query. Every item puts
299
* itself to the list on creation (see Item::Item() for details))
302
MEM_ROOT *mem_root; /**< Pointer to current memroot */
304
* Uniquely identifies each statement object in thread scope; change during
305
* statement lifetime.
307
* @todo should be const
324
312
MARK_COLUMNS_NONE: Means mark_used_colums is not set and no indicator to
334
322
enum enum_mark_columns mark_used_columns;
324
LEX *lex; /**< parse tree descriptor */
326
Points to the query associated with this statement. It's const, but
327
we need to declare it char * because all table handlers are written
328
in C and need to point to it.
330
Note that (A) if we set query = NULL, we must at the same time set
331
query_length = 0, and protect the whole operation with the
332
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
333
non-NULL value if its previous value is NULL. We do not need to protect
334
operation (B) with any mutex. To avoid crashes in races, if we do not
335
know that session->query cannot change at the moment, one should print
336
session->query like this:
337
(1) reserve the LOCK_thread_count mutex;
338
(2) check if session->query is NULL;
339
(3) if not NULL, then print at most session->query_length characters from
340
it. We will see the query_length field as either 0, or the right value
342
Assuming that the write and read of an n-bit memory field in an n-bit
343
computer is atomic, we can avoid races in the above way.
344
This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
348
uint32_t query_length; /**< current query length */
351
Name of the current (default) database.
353
If there is the current (default) database, "db" contains its name. If
354
there is no current (default) database, "db" is NULL and "db_length" is
355
0. In other words, "db", "db_length" must either be NULL, or contain a
358
@note this attribute is set and alloced by the slave SQL thread (for
359
the Session of that thread); that thread is (and must remain, for now) the
360
only responsible for freeing this member.
363
uint32_t db_length; /**< Length of current schema name */
367
/* This constructor is called for backup statements */
370
Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, uint32_t id_arg)
373
mem_root(mem_root_arg),
375
mark_used_columns(MARK_COLUMNS_READ),
382
virtual ~Statement() {}
335
383
inline void* alloc(size_t size)
337
return mem_root->alloc_root(size);
385
return alloc_root(mem_root,size);
339
387
inline void* calloc(size_t size)
342
if ((ptr= mem_root->alloc_root(size)))
390
if ((ptr= alloc_root(mem_root,size)))
343
391
memset(ptr, 0, size);
346
394
inline char *strdup(const char *str)
348
return mem_root->strdup_root(str);
396
return strdup_root(mem_root,str);
350
398
inline char *strmake(const char *str, size_t size)
352
return mem_root->strmake_root(str,size);
400
return strmake_root(mem_root,str,size);
354
402
inline void *memdup(const void *str, size_t size)
356
return mem_root->memdup_root(str, size);
404
return memdup_root(mem_root,str,size);
358
406
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
361
if ((ptr= mem_root->alloc_root(size + gap)))
409
if ((ptr= alloc_root(mem_root,size+gap)))
362
410
memcpy(ptr,str,size);
365
413
/** Frees all items attached to this Statement */
366
414
void free_items();
368
* List of items created in the parser for this query. Every item puts
369
* itself to the list on creation (see Item::Item() for details))
372
memory::Root *mem_root; /**< Pointer to current memroot */
375
memory::Root *getMemRoot()
387
void setXaId(uint64_t in_xa_id)
393
* Uniquely identifies each statement object in thread scope; change during
394
* statement lifetime.
396
* @todo should be const
399
LEX *lex; /**< parse tree descriptor */
405
/** query associated with this statement */
406
typedef boost::shared_ptr<const std::string> QueryString;
408
boost::shared_ptr<std::string> query;
410
// Never allow for a modification of this outside of the class. c_str()
411
// requires under some setup non const, you must copy the QueryString in
414
QueryString getQueryString() const
419
void resetQueryString()
426
We need to copy the lock on the string in order to make sure we have a stable string.
427
Once this is done we can use it to build a const char* which can be handed off for
428
a method to use (Innodb is currently the only engine using this).
430
const char *getQueryStringCopy(size_t &length)
432
QueryString tmp_string(getQueryString());
441
length= tmp_string->length();
442
char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
447
std::vector <char> _query;
450
typedef boost::shared_ptr<State> const_shared_ptr;
452
State(const char *in_packet, size_t in_packet_length)
454
if (in_packet_length)
456
size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
457
_query.resize(minimum + 1);
458
memcpy(&_query[0], in_packet, minimum);
466
const char *query() const
474
const char *query(size_t &size) const
478
size= _query.size() -1;
486
friend class Session;
487
typedef boost::shared_ptr<State> shared_ptr;
490
State::shared_ptr _state;
493
State::const_shared_ptr state()
499
Name of the current (default) database.
501
If there is the current (default) database, "db" contains its name. If
502
there is no current (default) database, "db" is NULL and "db_length" is
503
0. In other words, "db", "db_length" must either be NULL, or contain a
506
@note this attribute is set and alloced by the slave SQL thread (for
507
the Session of that thread); that thread is (and must remain, for now) the
508
only responsible for freeing this member.
511
util::string::shared_ptr _schema;
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;
419
struct st_savepoint *prev;
422
Ha_trx_info *ha_list;
425
extern pthread_mutex_t LOCK_xid_cache;
426
extern HASH xid_cache;
428
#include <drizzled/security_context.h>
429
#include <drizzled/open_tables_state.h>
431
#include <drizzled/internal_error_handler.h>
432
#include <drizzled/diagnostics_area.h>
435
Storage engine specific thread local data.
440
Storage engine specific thread local data.
441
Lifetime: one user connection.
445
0: Life time: one statement within a transaction. If @@autocommit is
446
on, also represents the entire transaction.
447
@sa trans_register_ha()
449
1: Life time: one transaction within a connection.
450
If the storage engine does not participate in a transaction,
451
this should not be used.
452
@sa trans_register_ha()
454
Ha_trx_info ha_info[2];
456
Ha_data() :ha_ptr(NULL) {}
460
* Represents a client connection to the database server.
462
* Contains the client/server protocol object, the current statement
463
* being executed, local-to-session variables and status counters, and
464
* a host of other information.
468
* Session should NOT inherit from Statement, but rather it should have a
469
* vector of Statement object pointers which comprise the statements executed
470
* on the Session. Until this architectural change is done, we can forget
471
* about parallel operations inside a session.
475
* Make member variables private and have inlined accessors and setters. Hide
476
* all member variables that are not critical to non-internal operations of the
479
class Session :public Statement, public Open_tables_state
525
483
Constant for Session::where initialization in the beginning of every query.
530
488
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 */
490
MEM_ROOT warn_root; /**< Allocation area for warnings and errors */
491
Protocol *protocol; /**< Pointer to the current protocol */
492
HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
493
String packet; /**< dynamic buffer for network I/O */
494
String convert_buffer; /**< A buffer for charset conversions */
495
struct system_variables variables; /**< Mutable local variables local to the session */
558
496
struct system_status_var status_var; /**< Session-local status counters */
497
struct system_status_var *initial_status_var; /* used by show status */
559
498
THR_LOCK_INFO lock_info; /**< Locking information for this session */
560
499
THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
561
500
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
501
pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
504
* A peek into the query string for the session. This is a best effort
505
* delivery, there is no guarantee whether the content is meaningful.
507
char process_list_info[PROCESS_LIST_WIDTH+1];
510
* A pointer to the stack frame of handle_one_connection(),
565
511
* which is called first in the thread for handling a client
567
513
char *thread_stack;
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;
517
Some members of Session (currently 'Statement::db',
518
'query') are set and alloced by the slave SQL thread
519
(for the Session of that thread); that thread is (and must remain, for now)
520
the only responsible for freeing these 3 members. If you add members
521
here, and you add code to set them in replication, don't forget to
522
free_them_and_set_them_to_0 in replication properly. For details see
523
the 'err:' label of the handle_slave_sql() in sql/slave.cc.
525
@see handle_slave_sql
527
Security_context security_ctx;
605
530
Used in error messages to tell user in what part of MySQL we found an
614
539
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
616
541
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()
542
struct st_my_thread_var *mysys_var;
647
544
* Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
648
545
* first byte of the packet in executeStatement()
650
547
enum enum_server_command command;
651
548
uint32_t file_id; /**< File ID for LOAD DATA INFILE */
652
/* @note the following three members should likely move to Client */
549
/* @note the following three members should likely move to Protocol */
550
uint32_t client_capabilities; /**< What the client supports */
551
uint16_t peer_port; /**< The remote (peer) port */
653
552
uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
654
553
time_t start_time;
655
554
time_t user_time;
555
uint64_t connect_utime;
656
556
uint64_t thr_create_utime; /**< track down slow pthread_create */
657
557
uint64_t start_utime;
658
558
uint64_t utime_after_lock;
663
563
Both of the following container points in session will be converted to an API.
667
566
/* 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,
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.
567
Ha_data ha_data[MAX_HA];
569
/* container for replication data */
570
void *replication_data;
692
572
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;
573
SAVEPOINT *savepoints;
574
Session_TRANS all; // Trans since BEGIN WORK
575
Session_TRANS stmt; // Trans for current statement
576
bool on; // see ha_enable_transaction()
716
577
XID_STATE xid_state;
580
Tables changed in transaction (that must be invalidated in query cache).
581
List contain only transactional tables, that not invalidated in query
582
cache (instead of full list of changed in transaction tables).
584
CHANGED_TableList* changed_tables;
585
MEM_ROOT mem_root; // Transaction-life memory allocation pool
590
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
594
memset(this, 0, sizeof(*this));
595
xid_state.xid.null();
596
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
730
599
Field *dup_field;
731
600
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;
748
602
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
749
603
bool arg_of_last_insert_id_function;
752
605
ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
753
606
insertion into an auto_increment column".
849
715
create_sort_index(); may differ from examined_row_count.
851
717
uint32_t row_count;
852
session_id_t thread_id;
718
pthread_t real_id; /**< For debugging */
719
my_thread_id thread_id;
853
720
uint32_t tmp_table;
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);
721
uint32_t global_read_lock;
899
722
uint32_t server_status;
900
723
uint32_t open_options;
901
724
uint32_t select_number; /**< number of select (used for EXPLAIN) */
1204
1013
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&);
1221
1016
For enter_cond() / exit_cond() to work the mutex must be got before
1222
1017
enter_cond(); this mutex is then released by exit_cond().
1223
1018
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);
1020
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
1022
const char* old_msg = get_proc_info();
1023
safe_mutex_assert_owner(mutex);
1024
mysys_var->current_mutex = mutex;
1025
mysys_var->current_cond = cond;
1026
this->set_proc_info(msg);
1029
inline void exit_cond(const char* old_msg)
1032
Putting the mutex unlock in exit_cond() ensures that
1033
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
1034
locked (if that would not be the case, you'll get a deadlock if someone
1035
does a Session::awake() on you).
1037
pthread_mutex_unlock(mysys_var->current_mutex);
1038
pthread_mutex_lock(&mysys_var->mutex);
1039
mysys_var->current_mutex = 0;
1040
mysys_var->current_cond = 0;
1041
this->set_proc_info(old_msg);
1042
pthread_mutex_unlock(&mysys_var->mutex);
1228
1044
inline time_t query_start() { return start_time; }
1229
1045
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
1049
start_time= user_time;
1238
connect_microseconds= start_utime;
1050
start_utime= utime_after_lock= my_micro_time();
1241
start_time= (mytime-epoch).total_seconds();
1053
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1243
1055
inline void set_current_time() { start_time= time(NULL); }
1244
1056
inline void set_time(time_t t)
1246
1058
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();
1059
start_utime= utime_after_lock= my_micro_time();
1061
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
1259
1063
* Returns the current micro-timestamp
1261
1065
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();
1067
return my_micro_time();
1269
1069
inline uint64_t found_rows(void)
1443
1262
* Current implementation does not depend on that, but future changes
1444
1263
* should be done with this in mind;
1446
* @param passwd Scrambled password received from client
1447
* @param db Database name to connect to, may be NULL
1449
bool checkUser(const std::string &passwd, const std::string &db);
1452
* Returns the timestamp (in microseconds) of when the Session
1453
* connected to the server.
1455
inline uint64_t getConnectMicroseconds() const
1457
return connect_microseconds;
1461
* Returns a pointer to the active Transaction message for this
1462
* Session being managed by the ReplicationServices component, or
1463
* NULL if no active message.
1465
message::Transaction *getTransactionMessage() const
1467
return transaction_message;
1471
* Returns a pointer to the active Statement message for this
1472
* Session, or NULL if no active message.
1474
message::Statement *getStatementMessage() const
1476
return statement_message;
1480
* Returns a pointer to the current Resulset message for this
1481
* Session, or NULL if no active message.
1483
message::Resultset *getResultsetMessage() const
1488
* Sets the active transaction message used by the ReplicationServices
1491
* @param[in] Pointer to the message
1493
void setTransactionMessage(message::Transaction *in_message)
1495
transaction_message= in_message;
1499
* Sets the active statement message used by the ReplicationServices
1502
* @param[in] Pointer to the message
1504
void setStatementMessage(message::Statement *in_message)
1506
statement_message= in_message;
1510
* Sets the active Resultset message used by the Query Cache
1513
* @param[in] Pointer to the message
1515
void setResultsetMessage(message::Resultset *in_message)
1517
resultset= in_message;
1520
* reset the active Resultset message used by the Query Cache
1524
void resetResultsetMessage()
1265
* @param Scrambled password received from client
1266
* @param Length of scrambled password
1267
* @param Database name to connect to, may be NULL
1269
bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1530
/** Pointers to memory managed by the ReplicationServices component */
1531
message::Transaction *transaction_message;
1532
message::Statement *statement_message;
1533
/* Pointer to the current resultset of Select query */
1534
message::Resultset *resultset;
1535
plugin::EventObserverList *session_event_observers;
1537
/* Schema observers are mapped to databases. */
1538
std::map<std::string, plugin::EventObserverList *> schema_event_observers;
1542
plugin::EventObserverList *getSessionObservers()
1544
return session_event_observers;
1547
void setSessionObservers(plugin::EventObserverList *observers)
1549
session_event_observers= observers;
1552
/* For schema event observers there is one set of observers per database. */
1553
plugin::EventObserverList *getSchemaObservers(const std::string &db_name)
1555
std::map<std::string, plugin::EventObserverList *>::iterator it;
1557
it= schema_event_observers.find(db_name);
1558
if (it == schema_event_observers.end())
1564
void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers)
1566
std::map<std::string, plugin::EventObserverList *>::iterator it;
1568
it= schema_event_observers.find(db_name);
1569
if (it != schema_event_observers.end())
1570
schema_event_observers.erase(it);;
1573
schema_event_observers[db_name] = observers;
1578
/** Microsecond timestamp of when Session connected */
1579
uint64_t connect_microseconds;
1580
1272
const char *proc_info;
1582
1274
/** The current internal error handler for this thread, or NULL. */
1699
1390
* 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);
1392
int open_and_lock_tables(TableList *tables);
1394
* Open all tables in list and process derived tables
1396
* @param Pointer to a list of tables for open
1397
* @param Bitmap of flags to modify how the tables will be open:
1398
* DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
1399
* done a flush or namelock on it.
1408
* This is to be used on prepare stage when you don't read any
1409
* data from the tables.
1411
bool open_normal_and_derived_tables(TableList *tables, uint32_t flags);
1412
int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags);
1413
Table *open_ltable(TableList *table_list, thr_lock_type lock_type);
1414
Table *open_table(TableList *table_list, bool *refresh, uint32_t flags);
1708
1415
void unlink_open_table(Table *find);
1709
void drop_open_table(Table *table, const TableIdentifier &identifier);
1416
void drop_open_table(Table *table, const char *db_name,
1417
const char *table_name);
1710
1418
void close_cached_table(Table *table);
1712
1420
/* 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;
1421
Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1422
bool lock_table_name_if_not_cached(const char *db,
1423
const char *table_name, Table **table);
1425
/* Work with temporary tables */
1426
Table *find_temporary_table(TableList *table_list);
1427
Table *find_temporary_table(const char *db, const char *table_name);
1428
void close_temporary_tables();
1429
void close_temporary_table(Table *table, bool free_share, bool delete_table);
1430
int drop_temporary_table(TableList *table_list);
1739
1432
/* Reopen operations */
1740
1433
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;
1434
bool reopen_name_locked_table(TableList* table_list, bool link_in);
1436
void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1812
1441
#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
1443
#include <drizzled/select_to_file.h>
1818
1444
#include <drizzled/select_export.h>
1819
1445
#include <drizzled/select_dump.h>
1820
1446
#include <drizzled/select_insert.h>
1821
1447
#include <drizzled/select_create.h>
1448
#include <plugin/myisam/myisam.h>
1822
1449
#include <drizzled/tmp_table_param.h>
1823
1450
#include <drizzled/select_union.h>
1824
1451
#include <drizzled/select_subselect.h>