21
21
#ifndef DRIZZLED_SESSION_H
22
22
#define DRIZZLED_SESSION_H
24
/* Classes in mysql */
24
26
#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"
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/cursor.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>
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
60
class Lex_input_stream;
142
105
List<Item> *update_fields;
143
106
List<Item> *update_values;
144
107
/* for VIEW ... WITH CHECK OPTION */
162
} /* namespace drizzled */
164
/** @TODO why is this in the middle of the file */
110
typedef struct drizzled_lock_st
113
uint32_t table_count;
115
THR_LOCK_DATA **locks;
165
118
#include <drizzled/lex_column.h>
170
120
class select_result;
173
123
#define Session_SENTRY_MAGIC 0xfeedd1ff
174
124
#define Session_SENTRY_GONE 0xdeadbeef
176
struct drizzle_system_variables
126
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
128
struct system_variables
178
drizzle_system_variables()
130
system_variables() {};
181
132
How dynamically allocated system variables are handled:
225
176
size_t range_alloc_block_size;
226
177
uint32_t query_alloc_block_size;
227
178
uint32_t query_prealloc_size;
179
uint32_t trans_alloc_block_size;
180
uint32_t trans_prealloc_size;
228
181
uint64_t group_concat_max_len;
182
/* TODO: change this to my_thread_id - but have to fix set_var first */
229
183
uint64_t pseudo_thread_id;
231
plugin::StorageEngine *storage_engine;
185
drizzled::plugin::StorageEngine *storage_engine;
233
187
/* Only charset part of these variables is sensible */
234
188
const CHARSET_INFO *character_set_filesystem;
247
201
Time_zone *time_zone;
250
extern struct drizzle_system_variables global_system_variables;
252
} /* namespace drizzled */
254
#include "drizzled/sql_lex.h"
204
extern struct system_variables global_system_variables;
209
* Per-session local status counters
211
typedef struct system_status_var
213
uint64_t bytes_received;
216
ulong com_stat[(uint32_t) SQLCOM_END];
217
ulong created_tmp_disk_tables;
218
ulong created_tmp_tables;
219
ulong ha_commit_count;
220
ulong ha_delete_count;
221
ulong ha_read_first_count;
222
ulong ha_read_last_count;
223
ulong ha_read_key_count;
224
ulong ha_read_next_count;
225
ulong ha_read_prev_count;
226
ulong ha_read_rnd_count;
227
ulong ha_read_rnd_next_count;
228
ulong ha_rollback_count;
229
ulong ha_update_count;
230
ulong ha_write_count;
231
ulong ha_prepare_count;
232
ulong ha_savepoint_count;
233
ulong ha_savepoint_rollback_count;
235
/* KEY_CACHE parts. These are copies of the original */
236
ulong key_blocks_changed;
237
ulong key_blocks_used;
238
ulong key_cache_r_requests;
239
ulong key_cache_read;
240
ulong key_cache_w_requests;
241
ulong key_cache_write;
242
/* END OF KEY_CACHE parts */
244
ulong net_big_packet_count;
247
ulong select_full_join_count;
248
ulong select_full_range_join_count;
249
ulong select_range_count;
250
ulong select_range_check_count;
251
ulong select_scan_count;
252
ulong long_query_count;
253
ulong filesort_merge_passes;
254
ulong filesort_range_count;
256
ulong filesort_scan_count;
258
Number of statements sent from the client
264
SEE last_system_status_var DEFINITION BELOW.
266
Below 'last_system_status_var' are all variables which doesn't make any
267
sense to add to the /global/ status variable counter.
269
double last_query_cost;
273
This is used for 'SHOW STATUS'. It must be updated to the last ulong
274
variable in system_status_var which is makes sens to add to the global
278
#define last_system_status_var questions
259
280
void mark_transaction_to_rollback(Session *session, bool all);
284
struct st_savepoint *prev;
287
Ha_trx_info *ha_list;
290
extern pthread_mutex_t LOCK_xid_cache;
291
extern HASH xid_cache;
293
#include <drizzled/security_context.h>
294
#include <drizzled/open_tables_state.h>
296
#include <drizzled/internal_error_handler.h>
297
#include <drizzled/diagnostics_area.h>
262
300
Storage engine specific thread local data.
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];
310
0: Life time: one statement within a transaction. If @@autocommit is
311
on, also represents the entire transaction.
312
@sa trans_register_ha()
314
1: Life time: one transaction within a connection.
315
If the storage engine does not participate in a transaction,
316
this should not be used.
317
@sa trans_register_ha()
319
Ha_trx_info ha_info[2];
291
321
Ha_data() :ha_ptr(NULL) {}
334
357
enum enum_mark_columns mark_used_columns;
335
358
inline void* alloc(size_t size)
337
return mem_root->alloc_root(size);
360
return alloc_root(mem_root,size);
339
362
inline void* calloc(size_t size)
342
if ((ptr= mem_root->alloc_root(size)))
365
if ((ptr= alloc_root(mem_root,size)))
343
366
memset(ptr, 0, size);
346
369
inline char *strdup(const char *str)
348
return mem_root->strdup_root(str);
371
return strdup_root(mem_root,str);
350
373
inline char *strmake(const char *str, size_t size)
352
return mem_root->strmake_root(str,size);
375
return strmake_root(mem_root,str,size);
354
377
inline void *memdup(const void *str, size_t size)
356
return mem_root->memdup_root(str, size);
379
return memdup_root(mem_root,str,size);
358
381
inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
361
if ((ptr= mem_root->alloc_root(size + gap)))
384
if ((ptr= alloc_root(mem_root,size+gap)))
362
385
memcpy(ptr,str,size);
399
403
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).
405
Points to the query associated with this statement. It's const, but
406
we need to declare it char * because all table handlers are written
407
in C and need to point to it.
409
Note that (A) if we set query = NULL, we must at the same time set
410
query_length = 0, and protect the whole operation with the
411
LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
412
non-NULL value if its previous value is NULL. We do not need to protect
413
operation (B) with any mutex. To avoid crashes in races, if we do not
414
know that session->query cannot change at the moment, one should print
415
session->query like this:
416
(1) reserve the LOCK_thread_count mutex;
417
(2) check if session->query is NULL;
418
(3) if not NULL, then print at most session->query_length characters from
419
it. We will see the query_length field as either 0, or the right value
421
Assuming that the write and read of an n-bit memory field in an n-bit
422
computer is atomic, we can avoid races in the above way.
423
This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
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()
427
uint32_t query_length; /**< current query length */
499
430
Name of the current (default) database.
530
450
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 */
452
MEM_ROOT warn_root; /**< Allocation area for warnings and errors */
453
drizzled::plugin::Client *client; /**< Pointer to client object */
454
drizzled::plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
543
455
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 */
456
HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
457
struct system_variables variables; /**< Mutable local variables local to the session */
558
458
struct system_status_var status_var; /**< Session-local status counters */
459
struct system_status_var *initial_status_var; /* used by show status */
559
460
THR_LOCK_INFO lock_info; /**< Locking information for this session */
560
461
THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
561
462
THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
463
pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
466
* A peek into the query string for the session. This is a best effort
467
* delivery, there is no guarantee whether the content is meaningful.
469
char process_list_info[PROCESS_LIST_WIDTH+1];
564
472
* A pointer to the stack frame of the scheduler thread
567
475
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;
479
Some members of Session (currently 'Statement::db',
480
'query') are set and alloced by the slave SQL thread
481
(for the Session of that thread); that thread is (and must remain, for now)
482
the only responsible for freeing these 3 members. If you add members
483
here, and you add code to set them in replication, don't forget to
484
free_them_and_set_them_to_0 in replication properly. For details see
485
the 'err:' label of the handle_slave_sql() in sql/slave.cc.
487
@see handle_slave_sql
489
Security_context security_ctx;
605
492
Used in error messages to tell user in what part of MySQL we found an
614
501
chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
616
503
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()
504
struct st_my_thread_var *mysys_var;
647
506
* Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
648
507
* first byte of the packet in executeStatement()
663
522
Both of the following container points in session will be converted to an API.
667
525
/* 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.
526
Ha_data ha_data[MAX_HA];
528
/* container for replication data */
529
void *replication_data;
692
531
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;
532
SAVEPOINT *savepoints;
533
Session_TRANS all; // Trans since BEGIN WORK
534
Session_TRANS stmt; // Trans for current statement
535
bool on; // see ha_enable_transaction()
716
536
XID_STATE xid_state;
539
Tables changed in transaction (that must be invalidated in query cache).
540
List contain only transactional tables, that not invalidated in query
541
cache (instead of full list of changed in transaction tables).
543
CHANGED_TableList* changed_tables;
544
MEM_ROOT mem_root; // Transaction-life memory allocation pool
549
free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
553
memset(this, 0, sizeof(*this));
554
xid_state.xid.null();
555
init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
730
558
Field *dup_field;
731
559
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
561
/* Tells if LAST_INSERT_ID(#) was called for the current statement */
749
562
bool arg_of_last_insert_id_function;
752
564
ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
753
565
insertion into an auto_increment column".
849
671
create_sort_index(); may differ from examined_row_count.
851
673
uint32_t row_count;
852
session_id_t thread_id;
674
pthread_t real_id; /**< For debugging */
675
my_thread_id thread_id;
853
676
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);
677
uint32_t global_read_lock;
899
678
uint32_t server_status;
900
679
uint32_t open_options;
901
680
uint32_t select_number; /**< number of select (used for EXPLAIN) */
1013
773
return proc_info;
1016
/** Sets this Session's current query ID */
1017
inline void setQueryId(query_id_t in_query_id)
1019
query_id= in_query_id;
776
inline void setReplicationData (void *data)
778
replication_data= data;
780
inline void *getReplicationData () const
782
return replication_data;
1022
785
/** Returns the current query ID */
1023
query_id_t getQueryId() const
786
inline query_id_t getQueryId() const
1025
788
return query_id;
1029
/** Sets this Session's warning query ID */
1030
inline void setWarningQueryId(query_id_t in_query_id)
791
/** Returns the current query text */
792
inline const char *getQueryString() const
1032
warn_query_id= in_query_id;
1035
/** Returns the Session's warning query ID */
1036
inline query_id_t getWarningQueryId() const
797
/** Returns the length of the current query text */
798
inline size_t getQueryLength() const
1038
return warn_query_id;
801
return strlen(query);
1041
806
/** Accessor method returning the session's ID. */
1042
inline session_id_t getSessionId() const
807
inline uint64_t getSessionId() const
1044
809
return thread_id;
1214
979
* 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
984
For enter_cond() / exit_cond() to work the mutex must be got before
1222
985
enter_cond(); this mutex is then released by exit_cond().
1223
986
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);
988
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
990
const char* old_msg = get_proc_info();
991
safe_mutex_assert_owner(mutex);
992
mysys_var->current_mutex = mutex;
993
mysys_var->current_cond = cond;
994
this->set_proc_info(msg);
997
inline void exit_cond(const char* old_msg)
1000
Putting the mutex unlock in exit_cond() ensures that
1001
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
1002
locked (if that would not be the case, you'll get a deadlock if someone
1003
does a Session::awake() on you).
1005
pthread_mutex_unlock(mysys_var->current_mutex);
1006
pthread_mutex_lock(&mysys_var->mutex);
1007
mysys_var->current_mutex = 0;
1008
mysys_var->current_cond = 0;
1009
this->set_proc_info(old_msg);
1010
pthread_mutex_unlock(&mysys_var->mutex);
1228
1012
inline time_t query_start() { return start_time; }
1229
1013
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
1017
start_time= user_time;
1238
connect_microseconds= start_utime;
1018
connect_microseconds= start_utime= utime_after_lock= my_micro_time();
1241
start_time= (mytime-epoch).total_seconds();
1021
start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1243
1023
inline void set_current_time() { start_time= time(NULL); }
1244
1024
inline void set_time(time_t t)
1246
1026
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();
1027
start_utime= utime_after_lock= my_micro_time();
1029
void set_time_after_lock() { utime_after_lock= my_micro_time(); }
1259
1031
* Returns the current micro-timestamp
1261
1033
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();
1035
return my_micro_time();
1269
1037
inline uint64_t found_rows(void)
1276
1044
return server_status & SERVER_STATUS_IN_TRANS;
1046
inline bool fill_derived_tables()
1048
return !lex->only_view_structure();
1050
inline void* trans_alloc(unsigned int size)
1052
return alloc_root(&transaction.mem_root,size);
1278
1055
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1279
1056
const char* str, uint32_t length,
1280
1057
bool allocate_lex_string);
1281
LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1282
const std::string &str,
1283
bool allocate_lex_string);
1059
void add_changed_table(Table *table);
1060
void add_changed_table(const char *key, long key_length);
1061
CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1285
1062
int send_explain_fields(select_result *result);
1287
1064
Clear the current error, if any.
1377
1144
database usually involves other actions, like switching other database
1378
1145
attributes including security context. In the future, this operation
1379
1146
will be made private and more convenient interface will be provided.
1381
void set_db(const std::string &new_db);
1148
@return Operation status
1149
@retval false Success
1150
@retval true Out-of-memory error
1152
bool set_db(const char *new_db, size_t new_db_len);
1155
Set the current database; use shallow copy of C-string.
1157
@param new_db a pointer to the new database name.
1158
@param new_db_len length of the new database name.
1160
@note This operation just sets {db, db_length}. Switching the current
1161
database usually involves other actions, like switching other database
1162
attributes including security context. In the future, this operation
1163
will be made private and more convenient interface will be provided.
1165
void reset_db(char *new_db, size_t new_db_len)
1168
db_length= new_db_len;
1384
1171
Copy the current database to the argument. Use the current arena to
1385
1172
allocate memory for a deep copy: current database may be freed after
1443
1230
* Current implementation does not depend on that, but future changes
1444
1231
* 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
1233
* @param Scrambled password received from client
1234
* @param Length of scrambled password
1235
* @param Database name to connect to, may be NULL
1449
bool checkUser(const std::string &passwd, const std::string &db);
1237
bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1452
1240
* Returns the timestamp (in microseconds) of when the Session
1471
1259
* Returns a pointer to the active Statement message for this
1472
1260
* Session, or NULL if no active message.
1474
message::Statement *getStatementMessage() const
1262
drizzled::message::Statement *getStatementMessage() const
1476
1264
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
1268
* Sets the active transaction message used by the ReplicationServices
1491
1271
* @param[in] Pointer to the message
1493
void setTransactionMessage(message::Transaction *in_message)
1273
void setTransactionMessage(drizzled::message::Transaction *in_message)
1495
1275
transaction_message= in_message;
1502
1282
* @param[in] Pointer to the message
1504
void setStatementMessage(message::Statement *in_message)
1284
void setStatementMessage(drizzled::message::Statement *in_message)
1506
1286
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()
1530
1289
/** 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 */
1290
drizzled::message::Transaction *transaction_message;
1291
drizzled::message::Statement *statement_message;
1292
/** Microsecond timestamp of when Session connected */
1579
1293
uint64_t connect_microseconds;
1580
1294
const char *proc_info;
1701
1423
bool openTablesLock(TableList *tables);
1426
* Open all tables in list and process derived tables
1428
* @param Pointer to a list of tables for open
1429
* @param Bitmap of flags to modify how the tables will be open:
1430
* DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
1431
* done a flush or namelock on it.
1440
* This is to be used on prepare stage when you don't read any
1441
* data from the tables.
1443
bool openTables(TableList *tables, uint32_t flags= 0);
1703
1445
int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1705
1447
Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1706
1448
Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1708
1450
void unlink_open_table(Table *find);
1709
void drop_open_table(Table *table, const TableIdentifier &identifier);
1451
void drop_open_table(Table *table, const char *db_name,
1452
const char *table_name);
1710
1453
void close_cached_table(Table *table);
1712
1455
/* 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;
1456
Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1457
bool lock_table_name_if_not_cached(const char *db,
1458
const char *table_name, Table **table);
1460
/* Work with temporary tables */
1461
Table *find_temporary_table(TableList *table_list);
1462
Table *find_temporary_table(const char *db, const char *table_name);
1463
void close_temporary_tables();
1464
void close_temporary_table(Table *table, bool free_share, bool delete_table);
1465
void close_temporary(Table *table, bool free_share, bool delete_table);
1466
int drop_temporary_table(TableList *table_list);
1467
bool rm_temporary_table(drizzled::plugin::StorageEngine *base, char *path);
1468
Table *open_temporary_table(const char *path, const char *db,
1469
const char *table_name, bool link_in_list);
1739
1471
/* Reopen operations */
1740
1472
bool reopen_tables(bool get_locks, bool mark_share_as_old);
1473
bool reopen_name_locked_table(TableList* table_list, bool link_in);
1741
1474
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);
1476
void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1744
1477
int setup_conds(TableList *leaves, COND **conds);
1745
1478
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
1482
Return the default storage engine
1766
1487
pointer to plugin::StorageEngine
1768
plugin::StorageEngine *getDefaultStorageEngine()
1489
drizzled::plugin::StorageEngine *getDefaultStorageEngine()
1770
1491
if (variables.storage_engine)
1771
1492
return variables.storage_engine;
1772
1493
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;
1812
1499
#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
1501
#include <drizzled/select_to_file.h>
1818
1502
#include <drizzled/select_export.h>
1819
1503
#include <drizzled/select_dump.h>
1820
1504
#include <drizzled/select_insert.h>
1821
1505
#include <drizzled/select_create.h>
1506
#include <plugin/myisam/myisam.h>
1822
1507
#include <drizzled/tmp_table_param.h>
1823
1508
#include <drizzled/select_union.h>
1824
1509
#include <drizzled/select_subselect.h>
1843
1524
Item_result result_type; /**< Type of item */
1844
1525
bool reverse; /**< if descending sort */
1845
1526
bool need_strxnfrm; /**< If we have to use strxnfrm() */
1852
result_type(STRING_RESULT),
1859
} /* namespace drizzled */
1861
/** @TODO why is this in the middle of the file */
1529
typedef struct st_sort_buffer
1531
uint32_t index; /* 0 or 1 */
1532
uint32_t sort_orders;
1533
uint32_t change_pos; /* If sort-fields changed */
1535
SORT_FIELD *sortorder;
1863
1538
#include <drizzled/table_ident.h>
1864
1539
#include <drizzled/user_var_entry.h>
1865
1540
#include <drizzled/unique.h>
1866
#include <drizzled/var.h>
1541
#include <drizzled/my_var.h>
1867
1542
#include <drizzled/select_dumpvar.h>
1872
1544
/* Bits in sql_command_flags */
1874
1546
enum sql_command_flag_bits
1887
1559
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1888
1560
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1891
const std::string &type(drizzled::Session::global_read_lock_t type);
1892
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1893
} /* namespace display */
1562
/* Functions in sql_class.cc */
1563
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
1895
} /* namespace drizzled */
1565
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
1566
STATUS_VAR *dec_var);
1897
1568
#endif /* DRIZZLED_SESSION_H */