17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
21
#ifndef DRIZZLED_SESSION_H
21
22
#define DRIZZLED_SESSION_H
23
#include "drizzled/cursor.h"
24
#include "drizzled/diagnostics_area.h"
25
#include "drizzled/file_exchange.h"
26
#include "drizzled/identifier.h"
27
#include "drizzled/internal_error_handler.h"
28
#include "drizzled/my_hash.h"
29
#include "drizzled/named_savepoint.h"
30
#include "drizzled/open_tables_state.h"
24
/* Classes in mysql */
31
26
#include "drizzled/plugin.h"
32
#include "drizzled/plugin/authorization.h"
33
#include "drizzled/pthread_globals.h"
34
#include "drizzled/query_id.h"
35
#include "drizzled/resource_context.h"
36
#include "drizzled/select_result_interceptor.h"
37
#include "drizzled/sql_error.h"
38
#include "drizzled/sql_locale.h"
39
#include "drizzled/statistics_variables.h"
40
#include "drizzled/transaction_context.h"
41
#include "drizzled/util/storable.h"
42
#include "drizzled/xid.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/db.h>
37
#include <drizzled/xid.h>
47
#include <sys/resource.h>
54
#include "drizzled/catalog/instance.h"
55
#include "drizzled/catalog/local.h"
57
#include <drizzled/session/property_map.h>
58
#include <drizzled/session/state.h>
59
#include <drizzled/session/table_messages.h>
60
#include <drizzled/session/transactions.h>
61
#include <drizzled/system_variables.h>
62
#include <drizzled/copy_info.h>
63
#include <drizzled/system_variables.h>
64
#include <drizzled/ha_data.h>
66
#include <boost/thread/thread.hpp>
67
#include <boost/thread/mutex.hpp>
68
#include <boost/thread/shared_mutex.hpp>
69
#include <boost/thread/condition_variable.hpp>
70
#include <boost/make_shared.hpp>
72
#include <drizzled/lex_column.h>
73
#include "drizzled/sql_lex.h"
75
#include "drizzled/visibility.h"
77
43
#define MIN_HANDSHAKE_SIZE 6
86
class EventObserverList;
96
namespace internal { struct st_my_thread_var; }
98
namespace table { class Placeholder; }
100
54
class Lex_input_stream;
101
55
class user_var_entry;
103
57
class Table_ident;
105
class TableShareInstance;
107
59
extern char internal_table_name[2];
108
60
extern char empty_c_string[1];
109
61
extern const char **errmesg;
112
64
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
113
65
extern uint32_t tc_heuristic_recover;
68
The COPY_INFO structure is used by INSERT/REPLACE code.
69
The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
71
If a row is inserted then the copied variable is incremented.
72
If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
73
new data differs from the old one then the copied and the updated
74
variables are incremented.
75
The touched variable is incremented if a row was touched by the update part
76
of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
77
was actually changed or not.
79
typedef struct st_copy_info
81
ha_rows records; /**< Number of processed records */
82
ha_rows deleted; /**< Number of deleted records */
83
ha_rows updated; /**< Number of updated records */
84
ha_rows copied; /**< Number of copied records */
86
ha_rows touched; /* Number of touched records */
87
enum enum_duplicates handle_duplicates;
88
int escape_char, last_errno;
90
/* for INSERT ... UPDATE */
91
List<Item> *update_fields;
92
List<Item> *update_values;
93
/* for VIEW ... WITH CHECK OPTION */
96
typedef struct drizzled_lock_st
101
THR_LOCK_DATA **locks;
104
#include <drizzled/lex_column.h>
115
106
class select_result;
118
109
#define Session_SENTRY_MAGIC 0xfeedd1ff
119
110
#define Session_SENTRY_GONE 0xdeadbeef
121
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
112
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
114
struct system_variables
116
system_variables() {};
118
How dynamically allocated system variables are handled:
120
The global_system_variables and max_system_variables are "authoritative"
121
They both should have the same 'version' and 'size'.
122
When attempting to access a dynamic variable, if the session version
123
is out of date, then the session version is updated and realloced if
124
neccessary and bytes copied from global to make up for missing data.
126
ulong dynamic_variables_version;
127
char * dynamic_variables_ptr;
128
uint32_t dynamic_variables_head; /* largest valid variable offset */
129
uint32_t dynamic_variables_size; /* how many bytes are in use */
131
uint64_t myisam_max_extra_sort_file_size;
132
uint64_t max_heap_table_size;
133
uint64_t tmp_table_size;
134
ha_rows select_limit;
135
ha_rows max_join_size;
136
uint64_t auto_increment_increment;
137
uint64_t auto_increment_offset;
138
uint64_t bulk_insert_buff_size;
139
uint64_t join_buff_size;
140
uint32_t max_allowed_packet;
141
uint64_t max_error_count;
142
uint64_t max_length_for_sort_data;
143
size_t max_sort_length;
144
uint64_t min_examined_row_limit;
145
uint32_t net_buffer_length;
146
bool optimizer_prune_level;
149
uint32_t optimizer_search_depth;
150
/* A bitmap for switching optimizations on/off */
151
uint32_t optimizer_switch;
152
uint32_t div_precincrement;
153
uint64_t preload_buff_size;
154
uint32_t read_buff_size;
155
uint32_t read_rnd_buff_size;
156
size_t sortbuff_size;
157
uint32_t thread_handling;
158
uint32_t tx_isolation;
159
uint32_t completion_type;
160
/* Determines which non-standard SQL behaviour should be enabled */
162
uint64_t max_seeks_for_key;
163
size_t range_alloc_block_size;
164
uint32_t query_alloc_block_size;
165
uint32_t query_prealloc_size;
166
uint32_t trans_alloc_block_size;
167
uint32_t trans_prealloc_size;
168
uint64_t group_concat_max_len;
169
/* TODO: change this to my_thread_id - but have to fix set_var first */
170
uint64_t pseudo_thread_id;
172
drizzled::plugin::StorageEngine *storage_engine;
174
/* Only charset part of these variables is sensible */
175
const CHARSET_INFO *character_set_filesystem;
177
/* Both charset and collation parts of these variables are important */
178
const CHARSET_INFO *collation_server;
180
inline const CHARSET_INFO *getCollation(void)
182
return collation_server;
186
MY_LOCALE *lc_time_names;
188
Time_zone *time_zone;
191
extern struct system_variables global_system_variables;
196
* Per-session local status counters
198
typedef struct system_status_var
200
uint64_t bytes_received;
203
ulong com_stat[(uint32_t) SQLCOM_END];
204
ulong created_tmp_disk_tables;
205
ulong created_tmp_tables;
206
ulong ha_commit_count;
207
ulong ha_delete_count;
208
ulong ha_read_first_count;
209
ulong ha_read_last_count;
210
ulong ha_read_key_count;
211
ulong ha_read_next_count;
212
ulong ha_read_prev_count;
213
ulong ha_read_rnd_count;
214
ulong ha_read_rnd_next_count;
215
ulong ha_rollback_count;
216
ulong ha_update_count;
217
ulong ha_write_count;
218
ulong ha_prepare_count;
219
ulong ha_savepoint_count;
220
ulong ha_savepoint_rollback_count;
222
/* KEY_CACHE parts. These are copies of the original */
223
ulong key_blocks_changed;
224
ulong key_blocks_used;
225
ulong key_cache_r_requests;
226
ulong key_cache_read;
227
ulong key_cache_w_requests;
228
ulong key_cache_write;
229
/* END OF KEY_CACHE parts */
231
ulong net_big_packet_count;
234
ulong select_full_join_count;
235
ulong select_full_range_join_count;
236
ulong select_range_count;
237
ulong select_range_check_count;
238
ulong select_scan_count;
239
ulong long_query_count;
240
ulong filesort_merge_passes;
241
ulong filesort_range_count;
243
ulong filesort_scan_count;
245
Number of statements sent from the client
251
SEE last_system_status_var DEFINITION BELOW.
253
Below 'last_system_status_var' are all variables which doesn't make any
254
sense to add to the /global/ status variable counter.
256
double last_query_cost;
260
This is used for 'SHOW STATUS'. It must be updated to the last ulong
261
variable in system_status_var which is makes sens to add to the global
265
#define last_system_status_var questions
267
void mark_transaction_to_rollback(Session *session, bool all);
271
struct st_savepoint *prev;
274
Ha_trx_info *ha_list;
277
extern pthread_mutex_t LOCK_xid_cache;
278
extern HASH xid_cache;
280
#include <drizzled/security_context.h>
281
#include <drizzled/open_tables_state.h>
283
#include <drizzled/internal_error_handler.h>
284
#include <drizzled/diagnostics_area.h>
287
Storage engine specific thread local data.
292
Storage engine specific thread local data.
293
Lifetime: one user connection.
297
0: Life time: one statement within a transaction. If @@autocommit is
298
on, also represents the entire transaction.
299
@sa trans_register_ha()
301
1: Life time: one transaction within a connection.
302
If the storage engine does not participate in a transaction,
303
this should not be used.
304
@sa trans_register_ha()
306
Ha_trx_info ha_info[2];
308
Ha_data() :ha_ptr(NULL) {}
124
312
* Represents a client connection to the database server.
170
344
enum enum_mark_columns mark_used_columns;
345
inline void* alloc(size_t size)
347
return alloc_root(mem_root,size);
171
349
inline void* calloc(size_t size)
174
if ((ptr= mem_root->alloc_root(size)))
352
if ((ptr= alloc_root(mem_root,size)))
175
353
memset(ptr, 0, size);
356
inline char *strdup(const char *str)
358
return strdup_root(mem_root,str);
178
360
inline char *strmake(const char *str, size_t size)
180
return mem_root->strmake_root(str,size);
362
return strmake_root(mem_root,str,size);
364
inline void *memdup(const void *str, size_t size)
366
return memdup_root(mem_root,str,size);
183
368
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
186
if ((ptr= mem_root->alloc_root(size + gap)))
371
if ((ptr= alloc_root(mem_root,size+gap)))
187
372
memcpy(ptr,str,size);
190
375
/** Frees all items attached to this Statement */
191
376
void free_items();
194
378
* List of items created in the parser for this query. Every item puts
195
379
* itself to the list on creation (see Item::Item() for details))
198
memory::Root *mem_root; /**< Pointer to current memroot */
201
memory::Root *getMemRoot()
213
void setXaId(uint64_t in_xa_id)
382
MEM_ROOT *mem_root; /**< Pointer to current memroot */
219
384
* Uniquely identifies each statement object in thread scope; change during
220
385
* statement lifetime.
225
390
LEX *lex; /**< parse tree descriptor */
232
enum_sql_command getSqlCommand() const
234
return lex->sql_command;
237
/** query associated with this statement */
238
typedef boost::shared_ptr<const std::string> QueryString;
241
boost::shared_ptr<std::string> query;
243
// Never allow for a modification of this outside of the class. c_str()
244
// requires under some setup non const, you must copy the QueryString in
247
QueryString getQueryString() const
252
void resetQueryString()
259
We need to copy the lock on the string in order to make sure we have a stable string.
260
Once this is done we can use it to build a const char* which can be handed off for
261
a method to use (Innodb is currently the only engine using this).
392
Points to the query associated with this statement. It's const, but
393
we need to declare it char * because all table handlers are written
394
in C and need to point to it.
396
Note that (A) if we set query = NULL, we must at the same time set
397
query_length = 0, and protect the whole operation with the
398
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
399
non-NULL value if its previous value is NULL. We do not need to protect
400
operation (B) with any mutex. To avoid crashes in races, if we do not
401
know that session->query cannot change at the moment, one should print
402
session->query like this:
403
(1) reserve the LOCK_thread_count mutex;
404
(2) check if session->query is NULL;
405
(3) if not NULL, then print at most session->query_length characters from
406
it. We will see the query_length field as either 0, or the right value
408
Assuming that the write and read of an n-bit memory field in an n-bit
409
computer is atomic, we can avoid races in the above way.
410
This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
263
const char *getQueryStringCopy(size_t &length)
265
QueryString tmp_string(getQueryString());
273
length= tmp_string->length();
274
char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
279
session::State::shared_ptr _state;
283
session::State::const_shared_ptr state()
414
uint32_t query_length; /**< current query length */
289
417
Name of the current (default) database.
321
437
static const char * const DEFAULT_WHERE;
323
memory::Root warn_root; /**< Allocation area for warnings and errors */
325
plugin::Client *client; /**< Pointer to client object */
329
void setClient(plugin::Client *client_arg);
331
plugin::Client *getClient()
336
plugin::Client *getClient() const
341
plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
439
MEM_ROOT warn_root; /**< Allocation area for warnings and errors */
440
drizzled::plugin::Client *client; /**< Pointer to client object */
441
drizzled::plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
342
442
void *scheduler_arg; /**< Pointer to the optional scheduler argument */
344
typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
347
typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
348
UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
351
const UserVars &getUserVariables() const
356
drizzle_system_variables variables; /**< Mutable local variables local to the session */
358
enum_tx_isolation getTxIsolation()
360
return (enum_tx_isolation)variables.tx_isolation;
443
HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
444
String packet; /**< dynamic buffer for network I/O */
445
String convert_buffer; /**< A buffer for charset conversions */
446
struct system_variables variables; /**< Mutable local variables local to the session */
363
447
struct system_status_var status_var; /**< Session-local status counters */
448
struct system_status_var *initial_status_var; /* used by show status */
364
449
THR_LOCK_INFO lock_info; /**< Locking information for this session */
365
450
THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
366
451
THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
452
pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
455
* A peek into the query string for the session. This is a best effort
456
* delivery, there is no guarantee whether the content is meaningful.
458
char process_list_info[PROCESS_LIST_WIDTH+1];
369
461
* A pointer to the stack frame of the scheduler thread
372
464
char *thread_stack;
375
identifier::User::shared_ptr security_ctx;
377
int32_t scoreboard_index;
379
inline void checkSentry() const
381
assert(this->dbug_sentry == Session_SENTRY_MAGIC);
385
identifier::User::const_shared_ptr user() const
390
return identifier::User::const_shared_ptr();
393
void setUser(identifier::User::shared_ptr arg)
398
int32_t getScoreboardIndex()
400
return scoreboard_index;
403
void setScoreboardIndex(int32_t in_scoreboard_index)
405
scoreboard_index= in_scoreboard_index;
409
* Is this session viewable by the current user?
411
bool isViewable(identifier::User::const_reference) const;
468
Some members of Session (currently 'Statement::db',
469
'query') are set and alloced by the slave SQL thread
470
(for the Session of that thread); that thread is (and must remain, for now)
471
the only responsible for freeing these 3 members. If you add members
472
here, and you add code to set them in replication, don't forget to
473
free_them_and_set_them_to_0 in replication properly. For details see
474
the 'err:' label of the handle_slave_sql() in sql/slave.cc.
476
@see handle_slave_sql
478
Security_context security_ctx;
415
481
Used in error messages to tell user in what part of MySQL we found an
416
482
error. E. g. when where= "having clause", if fix_fields() fails, user
417
483
will know that the error was in having clause.
427
void setWhere(const char *arg)
433
488
One thread can hold up to one named user-level lock. This variable
505
511
Both of the following container points in session will be converted to an API.
509
514
/* container for handler's private per-connection data */
510
std::vector<Ha_data> ha_data;
512
Id of current query. Statement can be reused to execute several queries
513
query_id is global in context of the whole MySQL server.
514
ID is automatically generated from an atomic counter.
515
It's used in Cursor code for various purposes: to check which columns
516
from table are necessary for this select, to check if it's necessary to
517
update auto-updatable fields (like auto_increment and timestamp).
520
query_id_t warn_query_id;
523
void **getEngineData(const plugin::MonitoredInTransaction *monitored);
524
ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
527
session::Transactions transaction;
515
Ha_data ha_data[MAX_HA];
517
/* container for replication data */
518
void *replication_data;
520
struct st_transactions {
521
SAVEPOINT *savepoints;
522
Session_TRANS all; // Trans since BEGIN WORK
523
Session_TRANS stmt; // Trans for current statement
524
bool on; // see ha_enable_transaction()
528
Tables changed in transaction (that must be invalidated in query cache).
529
List contain only transactional tables, that not invalidated in query
530
cache (instead of full list of changed in transaction tables).
532
CHANGED_TableList* changed_tables;
533
MEM_ROOT mem_root; // Transaction-life memory allocation pool
538
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
542
memset(this, 0, sizeof(*this));
543
xid_state.xid.null();
544
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
529
547
Field *dup_field;
530
548
sigset_t signals;
532
// As of right now we do not allow a concurrent execute to launch itself
534
bool concurrent_execute_allowed;
538
void setConcurrentExecute(bool arg)
540
concurrent_execute_allowed= arg;
543
bool isConcurrentExecuteAllowed() const
545
return concurrent_execute_allowed;
548
550
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
549
551
bool arg_of_last_insert_id_function;
552
553
ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
553
554
insertion into an auto_increment column".
655
660
create_sort_index(); may differ from examined_row_count.
657
662
uint32_t row_count;
659
uint32_t getRowCount() const
664
session_id_t thread_id;
663
pthread_t real_id; /**< For debugging */
664
my_thread_id thread_id;
665
665
uint32_t tmp_table;
666
enum global_read_lock_t
669
GOT_GLOBAL_READ_LOCK= 1,
670
MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
673
global_read_lock_t _global_read_lock;
677
global_read_lock_t isGlobalReadLock() const
679
return _global_read_lock;
682
void setGlobalReadLock(global_read_lock_t arg)
684
_global_read_lock= arg;
687
DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags);
688
bool lockGlobalReadLock();
689
bool lock_table_names(TableList *table_list);
690
bool lock_table_names_exclusively(TableList *table_list);
691
bool makeGlobalReadLockBlockCommit();
692
bool abortLockForThread(Table *table);
693
bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
694
int lock_table_name(TableList *table_list);
695
void abortLock(Table *table);
696
void removeLock(Table *table);
697
void unlockReadTables(DrizzleLock *sql_lock);
698
void unlockSomeTables(Table **table, uint32_t count);
699
void unlockTables(DrizzleLock *sql_lock);
700
void startWaitingGlobalReadLock();
701
void unlockGlobalReadLock();
704
int unlock_external(Table **table, uint32_t count);
705
int lock_external(Table **tables, uint32_t count);
706
bool wait_for_locked_table_names(TableList *table_list);
707
DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
708
bool should_lock, Table **write_lock_used);
666
uint32_t global_read_lock;
711
667
uint32_t server_status;
712
668
uint32_t open_options;
713
669
uint32_t select_number; /**< number of select (used for EXPLAIN) */
1041
967
* Schedule a session to be run on the default scheduler.
1043
static bool schedule(Session::shared_ptr&);
1045
static void unlink(session_id_t &session_id);
1046
static void unlink(Session::shared_ptr&);
1049
972
For enter_cond() / exit_cond() to work the mutex must be got before
1050
973
enter_cond(); this mutex is then released by exit_cond().
1051
974
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
1053
const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1054
void exit_cond(const char* old_msg);
1056
type::Time::epoch_t query_start()
1058
return getCurrentTimestampEpoch();
1063
_end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
1064
utime_after_lock= (_start_timer - _epoch).total_microseconds();
1067
void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
1069
_user_time= boost::posix_time::from_time_t(t);
1072
void set_time_after_lock()
1074
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1075
utime_after_lock= (mytime - _epoch).total_microseconds();
1078
void set_end_timer()
1080
_end_timer= boost::posix_time::microsec_clock::universal_time();
1081
status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
1084
uint64_t getElapsedTime() const
1086
return (_end_timer - _start_timer).total_microseconds();
976
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
978
const char* old_msg = get_proc_info();
979
safe_mutex_assert_owner(mutex);
980
mysys_var->current_mutex = mutex;
981
mysys_var->current_cond = cond;
982
this->set_proc_info(msg);
985
inline void exit_cond(const char* old_msg)
988
Putting the mutex unlock in exit_cond() ensures that
989
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
990
locked (if that would not be the case, you'll get a deadlock if someone
991
does a Session::awake() on you).
993
pthread_mutex_unlock(mysys_var->current_mutex);
994
pthread_mutex_lock(&mysys_var->mutex);
995
mysys_var->current_mutex = 0;
996
mysys_var->current_cond = 0;
997
this->set_proc_info(old_msg);
998
pthread_mutex_unlock(&mysys_var->mutex);
1000
inline time_t query_start() { return start_time; }
1001
inline void set_time()
1005
start_time= user_time;
1006
connect_microseconds= start_utime= utime_after_lock= my_micro_time();
1009
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1011
inline void set_current_time() { start_time= time(NULL); }
1012
inline void set_time(time_t t)
1014
start_time= user_time= t;
1015
start_utime= utime_after_lock= my_micro_time();
1017
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
1090
1019
* Returns the current micro-timestamp
1092
type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
1094
type::Time::epoch_t t_mark;
1098
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1099
t_mark= (mytime - _epoch).total_microseconds();
1103
t_mark= (_end_timer - _epoch).total_microseconds();
1109
// We may need to set user on this
1110
type::Time::epoch_t getCurrentTimestampEpoch() const
1112
if (not _user_time.is_not_a_date_time())
1113
return (_user_time - _epoch).total_seconds();
1115
return (_start_timer - _epoch).total_seconds();
1118
type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
1120
if (not _user_time.is_not_a_date_time())
1123
return (_user_time - _epoch).total_seconds();
1126
fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
1127
return (_start_timer - _epoch).total_seconds();
1130
uint64_t found_rows(void) const
1021
inline uint64_t getCurrentTimestamp()
1023
return my_micro_time();
1025
inline uint64_t found_rows(void)
1132
1027
return limit_found_rows;
1135
1029
/** Returns whether the session is currently inside a transaction */
1136
bool inTransaction() const
1030
inline bool inTransaction()
1138
1032
return server_status & SERVER_STATUS_IN_TRANS;
1034
inline bool fill_derived_tables()
1036
return !lex->only_view_structure();
1038
inline void* trans_alloc(unsigned int size)
1040
return alloc_root(&transaction.mem_root,size);
1141
1043
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1142
1044
const char* str, uint32_t length,
1143
1045
bool allocate_lex_string);
1145
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1146
const std::string &str,
1147
bool allocate_lex_string);
1047
void add_changed_table(Table *table);
1048
void add_changed_table(const char *key, long key_length);
1049
CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1149
1050
int send_explain_fields(select_result *result);
1152
1052
Clear the current error, if any.
1153
1053
We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
1312
1218
* Current implementation does not depend on that, but future changes
1313
1219
* should be done with this in mind;
1315
* @param passwd Scrambled password received from client
1316
* @param db Database name to connect to, may be NULL
1221
* @param Scrambled password received from client
1222
* @param Length of scrambled password
1223
* @param Database name to connect to, may be NULL
1318
bool checkUser(const std::string &passwd, const std::string &db);
1225
bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1321
1228
* Returns the timestamp (in microseconds) of when the Session
1322
1229
* connected to the server.
1324
uint64_t getConnectMicroseconds() const
1326
return (_connect_time - _epoch).total_microseconds();
1329
uint64_t getConnectSeconds() const
1331
return (_connect_time - _epoch).total_seconds();
1335
* Returns a pointer to the active Transaction message for this
1336
* Session being managed by the ReplicationServices component, or
1337
* NULL if no active message.
1339
message::Transaction *getTransactionMessage() const
1341
return transaction_message;
1345
* Returns a pointer to the active Statement message for this
1346
* Session, or NULL if no active message.
1348
message::Statement *getStatementMessage() const
1350
return statement_message;
1354
* Returns a pointer to the current Resulset message for this
1355
* Session, or NULL if no active message.
1357
message::Resultset *getResultsetMessage() const
1362
* Sets the active transaction message used by the ReplicationServices
1365
* @param[in] Pointer to the message
1367
void setTransactionMessage(message::Transaction *in_message)
1369
transaction_message= in_message;
1373
* Sets the active statement message used by the ReplicationServices
1376
* @param[in] Pointer to the message
1378
void setStatementMessage(message::Statement *in_message)
1380
statement_message= in_message;
1384
* Sets the active Resultset message used by the Query Cache
1387
* @param[in] Pointer to the message
1389
void setResultsetMessage(message::Resultset *in_message)
1391
resultset= in_message;
1394
* reset the active Resultset message used by the Query Cache
1398
void resetResultsetMessage()
1231
inline uint64_t getConnectMicroseconds() const
1233
return connect_microseconds;
1404
/** Pointers to memory managed by the ReplicationServices component */
1405
message::Transaction *transaction_message;
1406
message::Statement *statement_message;
1407
/* Pointer to the current resultset of Select query */
1408
message::Resultset *resultset;
1409
plugin::EventObserverList *session_event_observers;
1411
/* Schema observers are mapped to databases. */
1412
std::map<std::string, plugin::EventObserverList *> schema_event_observers;
1416
plugin::EventObserverList *getSessionObservers()
1418
return session_event_observers;
1421
void setSessionObservers(plugin::EventObserverList *observers)
1423
session_event_observers= observers;
1426
/* For schema event observers there is one set of observers per database. */
1427
plugin::EventObserverList *getSchemaObservers(const std::string &db_name)
1429
std::map<std::string, plugin::EventObserverList *>::iterator it;
1431
it= schema_event_observers.find(db_name);
1432
if (it == schema_event_observers.end())
1438
void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers)
1440
std::map<std::string, plugin::EventObserverList *>::iterator it;
1442
it= schema_event_observers.find(db_name);
1443
if (it != schema_event_observers.end())
1444
schema_event_observers.erase(it);;
1447
schema_event_observers[db_name] = observers;
1237
/** Microsecond timestamp of when Session connected */
1238
uint64_t connect_microseconds;
1452
1239
const char *proc_info;
1454
1241
/** The current internal error handler for this thread, or NULL. */
1574
1368
bool openTablesLock(TableList *tables);
1371
* Open all tables in list and process derived tables
1373
* @param Pointer to a list of tables for open
1374
* @param Bitmap of flags to modify how the tables will be open:
1375
* DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
1376
* done a flush or namelock on it.
1385
* This is to be used on prepare stage when you don't read any
1386
* data from the tables.
1388
bool openTables(TableList *tables, uint32_t flags= 0);
1576
1390
int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1578
1392
Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1579
1393
Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1581
1395
void unlink_open_table(Table *find);
1582
void drop_open_table(Table *table, const identifier::Table &identifier);
1396
void drop_open_table(Table *table, const char *db_name,
1397
const char *table_name);
1583
1398
void close_cached_table(Table *table);
1585
1400
/* Create a lock in the cache */
1586
table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1587
bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1590
session::TableMessages _table_message_cache;
1593
session::TableMessages &getMessageCache()
1595
return _table_message_cache;
1401
Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1402
bool lock_table_name_if_not_cached(const char *db,
1403
const char *table_name, Table **table);
1405
/* Work with temporary tables */
1406
Table *find_temporary_table(TableList *table_list);
1407
Table *find_temporary_table(const char *db, const char *table_name);
1408
void close_temporary_tables();
1409
void close_temporary_table(Table *table, bool free_share, bool delete_table);
1410
void close_temporary(Table *table, bool free_share, bool delete_table);
1411
int drop_temporary_table(TableList *table_list);
1412
bool rm_temporary_table(drizzled::plugin::StorageEngine *base, char *path);
1413
Table *open_temporary_table(const char *path, const char *db,
1414
const char *table_name, bool link_in_list,
1415
open_table_mode open_mode);
1598
1417
/* Reopen operations */
1599
bool reopen_tables();
1418
bool reopen_tables(bool get_locks, bool mark_share_as_old);
1419
bool reopen_name_locked_table(TableList* table_list, bool link_in);
1600
1420
bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1602
void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1422
void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1603
1423
int setup_conds(TableList *leaves, COND **conds);
1604
1424
int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1606
drizzled::util::Storable *getProperty(const std::string &arg)
1608
return life_properties.getProperty(arg);
1612
bool setProperty(const std::string &arg, T *value)
1614
life_properties.setProperty(arg, value);
1620
Return the default storage engine
1622
@param getDefaultStorageEngine()
1625
pointer to plugin::StorageEngine
1627
plugin::StorageEngine *getDefaultStorageEngine()
1629
if (variables.storage_engine)
1630
return variables.storage_engine;
1631
return global_system_variables.storage_engine;
1634
void get_xid(DRIZZLE_XID *xid); // Innodb only
1636
table::Singular *getInstanceTable();
1637
table::Singular *getInstanceTable(List<CreateField> &field_list);
1642
if (getrusage(RUSAGE_THREAD, &usage))
1652
void setUsage(bool arg)
1657
const struct rusage &getUsage()
1662
catalog::Instance::const_reference catalog() const
1664
return *(_catalog.get());
1667
catalog::Instance::reference catalog()
1669
return *(_catalog.get());
1673
catalog::Instance::shared_ptr _catalog;
1675
// This lives throughout the life of Session
1677
session::PropertyMap life_properties;
1678
std::vector<table::Singular *> temporary_shares;
1679
struct rusage usage;
1684
1429
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1686
} /* namespace drizzled */
1688
/** @TODO why is this in the middle of the file */
1689
1431
#include <drizzled/select_to_file.h>
1690
1432
#include <drizzled/select_export.h>
1691
1433
#include <drizzled/select_dump.h>
1692
1434
#include <drizzled/select_insert.h>
1693
1435
#include <drizzled/select_create.h>
1436
#include <plugin/myisam/myisam.h>
1694
1437
#include <drizzled/tmp_table_param.h>
1695
1438
#include <drizzled/select_union.h>
1696
1439
#include <drizzled/select_subselect.h>