~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: devananda
  • Date: 2009-07-01 17:38:47 UTC
  • mto: (1093.1.7 captain)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: devananda.vdv@gmail.com-20090701173847-3n3mbtessg5ff35e
refactored function/benchmark into plugin/benchmark

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_SESSION_H
22
22
#define DRIZZLED_SESSION_H
23
23
 
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 */
 
25
 
 
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>
 
39
 
40
40
#include <netdb.h>
41
 
#include <sys/time.h>
42
 
#include <sys/resource.h>
43
 
 
44
 
#include <algorithm>
 
41
#include <string>
45
42
#include <bitset>
46
 
#include <deque>
47
 
#include <map>
48
 
#include <string>
49
 
 
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"
55
 
 
56
 
#include <boost/unordered_map.hpp>
57
 
 
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>
63
 
 
64
43
 
65
44
#define MIN_HANDSHAKE_SIZE      6
66
45
 
67
 
namespace drizzled
68
 
{
69
 
 
70
 
namespace plugin
71
 
{
72
 
class Client;
73
 
class Scheduler;
74
 
class EventObserverList;
75
 
}
76
 
 
77
 
namespace message
78
 
{
79
 
class Transaction;
80
 
class Statement;
81
 
class Resultset;
82
 
}
83
 
 
84
 
namespace internal
85
 
{
86
 
struct st_my_thread_var;
87
 
}
88
 
 
89
 
namespace table
90
 
{
91
 
class Placeholder;
92
 
}
93
 
 
94
46
class Lex_input_stream;
95
47
class user_var_entry;
96
48
class CopyField;
97
49
class Table_ident;
98
50
 
99
 
class TableShareInstance;
100
 
 
101
51
extern char internal_table_name[2];
102
52
extern char empty_c_string[1];
103
53
extern const char **errmesg;
107
57
extern uint32_t tc_heuristic_recover;
108
58
 
109
59
/**
110
 
  @brief
111
 
  Local storage for proto that are tmp table. This should be enlarged
112
 
  to hande the entire table-share for a local table. Once Hash is done,
113
 
  we should consider exchanging the map for it.
114
 
*/
115
 
typedef std::map <std::string, message::Table> ProtoCache;
116
 
 
117
 
/**
118
60
  The COPY_INFO structure is used by INSERT/REPLACE code.
119
61
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
120
62
  UPDATE code:
126
68
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
127
69
      was actually changed or not.
128
70
*/
129
 
class CopyInfo 
 
71
typedef struct st_copy_info 
130
72
{
131
 
public:
132
73
  ha_rows records; /**< Number of processed records */
133
74
  ha_rows deleted; /**< Number of deleted records */
134
75
  ha_rows updated; /**< Number of updated records */
142
83
  List<Item> *update_fields;
143
84
  List<Item> *update_values;
144
85
  /* for VIEW ... WITH CHECK OPTION */
145
 
 
146
 
  CopyInfo() :
147
 
    records(0),
148
 
    deleted(0),
149
 
    updated(0),
150
 
    copied(0),
151
 
    error_count(0),
152
 
    touched(0),
153
 
    escape_char(0),
154
 
    last_errno(0),
155
 
    ignore(0),
156
 
    update_fields(0),
157
 
    update_values(0)
158
 
  { }
159
 
 
160
 
};
161
 
 
162
 
} /* namespace drizzled */
163
 
 
164
 
/** @TODO why is this in the middle of the file */
 
86
} COPY_INFO;
 
87
 
 
88
typedef struct drizzled_lock_st
 
89
{
 
90
  Table **table;
 
91
  uint32_t table_count;
 
92
  uint32_t lock_count;
 
93
  THR_LOCK_DATA **locks;
 
94
} DRIZZLE_LOCK;
 
95
 
165
96
#include <drizzled/lex_column.h>
166
97
 
167
 
namespace drizzled
168
 
{
169
 
 
170
98
class select_result;
171
99
class Time_zone;
172
100
 
173
101
#define Session_SENTRY_MAGIC 0xfeedd1ff
174
102
#define Session_SENTRY_GONE  0xdeadbeef
175
103
 
176
 
struct drizzle_system_variables
 
104
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
 
105
 
 
106
struct system_variables
177
107
{
178
 
  drizzle_system_variables()
179
 
  {}
 
108
  system_variables() {};
180
109
  /*
181
110
    How dynamically allocated system variables are handled:
182
111
 
201
130
  uint64_t bulk_insert_buff_size;
202
131
  uint64_t join_buff_size;
203
132
  uint32_t max_allowed_packet;
 
133
  uint32_t myisam_stats_method;
204
134
  uint64_t max_error_count;
205
135
  uint64_t max_length_for_sort_data;
206
136
  size_t max_sort_length;
207
137
  uint64_t min_examined_row_limit;
 
138
  uint32_t net_buffer_length;
 
139
  uint32_t net_read_timeout;
 
140
  uint32_t net_retry_count;
 
141
  uint32_t net_wait_timeout;
 
142
  uint32_t net_write_timeout;
208
143
  bool optimizer_prune_level;
209
144
  bool log_warnings;
 
145
  bool engine_condition_pushdown;
210
146
 
211
147
  uint32_t optimizer_search_depth;
 
148
  /*
 
149
    Controls use of Engine-MRR:
 
150
      0 - auto, based on cost
 
151
      1 - force MRR when the storage engine is capable of doing it
 
152
      2 - disable MRR.
 
153
  */
 
154
  uint32_t optimizer_use_mrr;
 
155
  /* A bitmap for switching optimizations on/off */
 
156
  uint32_t optimizer_switch;
212
157
  uint32_t div_precincrement;
213
158
  uint64_t preload_buff_size;
214
159
  uint32_t read_buff_size;
215
160
  uint32_t read_rnd_buff_size;
216
 
  bool replicate_query;
217
161
  size_t sortbuff_size;
218
162
  uint32_t thread_handling;
219
163
  uint32_t tx_isolation;
220
 
  size_t transaction_message_threshold;
221
164
  uint32_t completion_type;
222
165
  /* Determines which non-standard SQL behaviour should be enabled */
223
166
  uint32_t sql_mode;
225
168
  size_t range_alloc_block_size;
226
169
  uint32_t query_alloc_block_size;
227
170
  uint32_t query_prealloc_size;
 
171
  uint32_t trans_alloc_block_size;
 
172
  uint32_t trans_prealloc_size;
228
173
  uint64_t group_concat_max_len;
 
174
  /* TODO: change this to my_thread_id - but have to fix set_var first */
229
175
  uint64_t pseudo_thread_id;
230
176
 
231
 
  plugin::StorageEngine *storage_engine;
 
177
  StorageEngine *storage_engine;
232
178
 
233
179
  /* Only charset part of these variables is sensible */
234
180
  const CHARSET_INFO  *character_set_filesystem;
247
193
  Time_zone *time_zone;
248
194
};
249
195
 
250
 
extern struct drizzle_system_variables global_system_variables;
251
 
 
252
 
} /* namespace drizzled */
253
 
 
254
 
#include "drizzled/sql_lex.h"
255
 
 
256
 
namespace drizzled
 
196
extern struct system_variables global_system_variables;
 
197
 
 
198
#include "sql_lex.h"
 
199
 
 
200
/**
 
201
 * Per-session local status counters
 
202
 */
 
203
typedef struct system_status_var
257
204
{
 
205
  uint64_t bytes_received;
 
206
  uint64_t bytes_sent;
 
207
  ulong com_other;
 
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;
 
226
 
 
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 */
 
235
 
 
236
  ulong net_big_packet_count;
 
237
  ulong opened_tables;
 
238
  ulong opened_shares;
 
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;
 
247
  ulong filesort_rows;
 
248
  ulong filesort_scan_count;
 
249
  /*
 
250
    Number of statements sent from the client
 
251
  */
 
252
  ulong questions;
 
253
 
 
254
  /*
 
255
    IMPORTANT!
 
256
    SEE last_system_status_var DEFINITION BELOW.
 
257
 
 
258
    Below 'last_system_status_var' are all variables which doesn't make any
 
259
    sense to add to the /global/ status variable counter.
 
260
  */
 
261
  double last_query_cost;
 
262
} STATUS_VAR;
 
263
 
 
264
/*
 
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
 
267
  counter
 
268
*/
 
269
 
 
270
#define last_system_status_var questions
258
271
 
259
272
void mark_transaction_to_rollback(Session *session, bool all);
260
273
 
261
274
/**
262
 
  Storage engine specific thread local data.
263
 
*/
264
 
struct Ha_data
265
 
{
266
 
  /**
267
 
    Storage engine specific thread local data.
268
 
    Lifetime: one user connection.
269
 
  */
270
 
  void *ha_ptr;
271
 
  /**
272
 
   * Resource contexts for both the "statement" and "normal"
273
 
   * transactions.
274
 
   *
275
 
   * Resource context at index 0:
276
 
   *
277
 
   * Life time: one statement within a transaction. If @@autocommit is
278
 
   * on, also represents the entire transaction.
279
 
   *
280
 
   * Resource context at index 1:
281
 
   *
282
 
   * Life time: one transaction within a connection. 
283
 
   *
284
 
   * @note
285
 
   *
286
 
   * If the storage engine does not participate in a transaction, 
287
 
   * there will not be a resource context.
288
 
   */
289
 
  drizzled::ResourceContext resource_context[2];
290
 
 
291
 
  Ha_data() :ha_ptr(NULL) {}
292
 
};
293
 
 
294
 
/**
295
 
 * Represents a client connection to the database server.
296
 
 *
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.
300
 
 *
301
 
 * @todo
302
 
 *
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.
306
 
 *
307
 
 * @todo
308
 
 *
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
311
 
 * session object.
 
275
 * Single command executed against this connection.
 
276
 *
 
277
 * @details
 
278
 *
 
279
 * One connection can contain a lot of simultaneously running statements,
 
280
 * some of which could be prepared, that is, contain placeholders.
 
281
 *
 
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.
 
286
 *
 
287
 * @todo
 
288
 *
 
289
 * The above comment is bullshit in Drizzle. See TODO markers on Session to
 
290
 * completely detach the inheritance of Session from Statement.
312
291
 */
313
 
typedef int64_t session_id_t;
314
 
 
315
 
class Session : public Open_tables_state
 
292
class Statement
316
293
{
 
294
  Statement(const Statement &rhs);              /* not implemented: */
 
295
  Statement &operator=(const Statement &rhs);   /* non-copyable */
317
296
public:
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;
 
297
  /**
 
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))
 
300
   */
 
301
  Item *free_list;
 
302
  MEM_ROOT *mem_root; /**< Pointer to current memroot */
 
303
  /**
 
304
   * Uniquely identifies each statement object in thread scope; change during
 
305
   * statement lifetime.
 
306
   *
 
307
   * @todo should be const
 
308
   */
 
309
   uint32_t id;
322
310
 
323
311
  /*
324
312
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
332
320
                        and update_row.
333
321
  */
334
322
  enum enum_mark_columns mark_used_columns;
 
323
 
 
324
  LEX *lex; /**< parse tree descriptor */
 
325
  /**
 
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.
 
329
 
 
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
 
341
      for it.
 
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
 
345
    STATUS.
 
346
  */
 
347
  char *query;
 
348
  uint32_t query_length; /**< current query length */
 
349
 
 
350
  /**
 
351
    Name of the current (default) database.
 
352
 
 
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
 
356
    valid database name.
 
357
 
 
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.
 
361
  */
 
362
  char *db;
 
363
  uint32_t db_length; /**< Length of current schema name */
 
364
 
 
365
public:
 
366
 
 
367
  /* This constructor is called for backup statements */
 
368
  Statement() {}
 
369
 
 
370
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, uint32_t id_arg)
 
371
  :
 
372
    free_list(NULL), 
 
373
    mem_root(mem_root_arg),
 
374
    id(id_arg),
 
375
    mark_used_columns(MARK_COLUMNS_READ),
 
376
    lex(lex_arg),
 
377
    query(NULL),
 
378
    query_length(0),
 
379
    db(NULL),
 
380
    db_length(0)
 
381
  {}
 
382
  virtual ~Statement() {}
335
383
  inline void* alloc(size_t size)
336
384
  {
337
 
    return mem_root->alloc_root(size);
 
385
    return alloc_root(mem_root,size);
338
386
  }
339
387
  inline void* calloc(size_t size)
340
388
  {
341
389
    void *ptr;
342
 
    if ((ptr= mem_root->alloc_root(size)))
 
390
    if ((ptr= alloc_root(mem_root,size)))
343
391
      memset(ptr, 0, size);
344
392
    return ptr;
345
393
  }
346
394
  inline char *strdup(const char *str)
347
395
  {
348
 
    return mem_root->strdup_root(str);
 
396
    return strdup_root(mem_root,str);
349
397
  }
350
398
  inline char *strmake(const char *str, size_t size)
351
399
  {
352
 
    return mem_root->strmake_root(str,size);
 
400
    return strmake_root(mem_root,str,size);
353
401
  }
354
402
  inline void *memdup(const void *str, size_t size)
355
403
  {
356
 
    return mem_root->memdup_root(str, size);
 
404
    return memdup_root(mem_root,str,size);
357
405
  }
358
406
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
359
407
  {
360
408
    void *ptr;
361
 
    if ((ptr= mem_root->alloc_root(size + gap)))
 
409
    if ((ptr= alloc_root(mem_root,size+gap)))
362
410
      memcpy(ptr,str,size);
363
411
    return ptr;
364
412
  }
365
413
  /** Frees all items attached to this Statement */
366
414
  void free_items();
367
 
  /**
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))
370
 
   */
371
 
  Item *free_list;
372
 
  memory::Root *mem_root; /**< Pointer to current memroot */
373
 
 
374
 
 
375
 
  memory::Root *getMemRoot()
376
 
  {
377
 
    return mem_root;
378
 
  }
379
 
 
380
 
  uint64_t xa_id;
381
 
 
382
 
  uint64_t getXaId()
383
 
  {
384
 
    return xa_id;
385
 
  }
386
 
 
387
 
  void setXaId(uint64_t in_xa_id)
388
 
  {
389
 
    xa_id= in_xa_id; 
390
 
  }
391
 
 
392
 
  /**
393
 
   * Uniquely identifies each statement object in thread scope; change during
394
 
   * statement lifetime.
395
 
   *
396
 
   * @todo should be const
397
 
   */
398
 
  uint32_t id;
399
 
  LEX *lex; /**< parse tree descriptor */
400
 
 
401
 
  LEX *getLex() 
402
 
  {
403
 
    return lex;
404
 
  }
405
 
  /** query associated with this statement */
406
 
  typedef boost::shared_ptr<const std::string> QueryString;
407
 
private:
408
 
  boost::shared_ptr<std::string> query;
409
 
 
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
412
 
  // order to use it.
413
 
public:
414
 
  QueryString getQueryString() const
415
 
  {
416
 
    return query;
417
 
  }
418
 
 
419
 
  void resetQueryString()
420
 
  {
421
 
    query.reset();
422
 
    _state.reset();
423
 
  }
424
 
 
425
 
  /*
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).
429
 
  */
430
 
  const char *getQueryStringCopy(size_t &length)
431
 
  {
432
 
    QueryString tmp_string(getQueryString());
433
 
 
434
 
    assert(tmp_string);
435
 
    if (not tmp_string)
436
 
    {
437
 
      length= 0;
438
 
      return 0;
439
 
    }
440
 
 
441
 
    length= tmp_string->length();
442
 
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
443
 
    return to_return;
444
 
  }
445
 
 
446
 
  class State {
447
 
    std::vector <char> _query;
448
 
 
449
 
  public:
450
 
    typedef boost::shared_ptr<State> const_shared_ptr;
451
 
 
452
 
    State(const char *in_packet, size_t in_packet_length)
453
 
    {
454
 
      if (in_packet_length)
455
 
      {
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);
459
 
      }
460
 
      else
461
 
      {
462
 
        _query.resize(0);
463
 
      }
464
 
    }
465
 
 
466
 
    const char *query() const
467
 
    {
468
 
      if (_query.size())
469
 
        return &_query[0];
470
 
 
471
 
      return "";
472
 
    }
473
 
 
474
 
    const char *query(size_t &size) const
475
 
    {
476
 
      if (_query.size())
477
 
      {
478
 
        size= _query.size() -1;
479
 
        return &_query[0];
480
 
      }
481
 
 
482
 
      size= 0;
483
 
      return "";
484
 
    }
485
 
  protected:
486
 
    friend class Session;
487
 
    typedef boost::shared_ptr<State> shared_ptr;
488
 
  };
489
 
private:
490
 
  State::shared_ptr  _state; 
491
 
public:
492
 
 
493
 
  State::const_shared_ptr state()
494
 
  {
495
 
    return _state;
496
 
  }
497
 
 
498
 
  /**
499
 
    Name of the current (default) database.
500
 
 
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
504
 
    valid database name.
505
 
 
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.
509
 
  */
510
 
private:
511
 
  util::string::shared_ptr _schema;
512
 
public:
513
 
 
514
 
  util::string::const_shared_ptr schema() const
515
 
  {
516
 
    if (_schema)
517
 
      return _schema;
518
 
 
519
 
    return util::string::const_shared_ptr(new std::string(""));
520
 
  }
521
 
  std::string catalog;
522
 
  /* current cache key */
523
 
  std::string query_cache_key;
 
415
};
 
416
 
 
417
struct st_savepoint 
 
418
{
 
419
  struct st_savepoint *prev;
 
420
  char *name;
 
421
  uint32_t length;
 
422
  Ha_trx_info *ha_list;
 
423
};
 
424
 
 
425
extern pthread_mutex_t LOCK_xid_cache;
 
426
extern HASH xid_cache;
 
427
 
 
428
#include <drizzled/security_context.h>
 
429
#include <drizzled/open_tables_state.h>
 
430
 
 
431
#include <drizzled/internal_error_handler.h> 
 
432
#include <drizzled/diagnostics_area.h> 
 
433
 
 
434
/**
 
435
  Storage engine specific thread local data.
 
436
*/
 
437
struct Ha_data
 
438
{
 
439
  /**
 
440
    Storage engine specific thread local data.
 
441
    Lifetime: one user connection.
 
442
  */
 
443
  void *ha_ptr;
 
444
  /**
 
445
    0: Life time: one statement within a transaction. If @@autocommit is
 
446
    on, also represents the entire transaction.
 
447
    @sa trans_register_ha()
 
448
 
 
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()
 
453
  */
 
454
  Ha_trx_info ha_info[2];
 
455
 
 
456
  Ha_data() :ha_ptr(NULL) {}
 
457
};
 
458
 
 
459
/**
 
460
 * Represents a client connection to the database server.
 
461
 *
 
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.
 
465
 *
 
466
 * @todo
 
467
 *
 
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.
 
472
 *
 
473
 * @todo
 
474
 *
 
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
 
477
 * session object.
 
478
 */
 
479
class Session :public Statement, public Open_tables_state
 
480
{
 
481
public:
524
482
  /**
525
483
    Constant for Session::where initialization in the beginning of every query.
526
484
 
529
487
  */
530
488
  static const char * const DEFAULT_WHERE;
531
489
 
532
 
  memory::Root warn_root; /**< Allocation area for warnings and errors */
533
 
  plugin::Client *client; /**< Pointer to client object */
534
 
 
535
 
  void setClient(plugin::Client *client_arg);
536
 
 
537
 
  plugin::Client *getClient()
538
 
  {
539
 
    return client;
540
 
  }
541
 
 
542
 
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
543
 
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
544
 
 
545
 
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
546
 
private:
547
 
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
548
 
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
549
 
 
550
 
public:
551
 
 
552
 
  const UserVars &getUserVariables() const
553
 
  {
554
 
    return user_vars;
555
 
  }
556
 
 
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. */
562
 
 
563
 
  /**
564
 
   * A pointer to the stack frame of the scheduler thread
 
501
  pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
 
502
 
 
503
  /**
 
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.
 
506
   */
 
507
  char process_list_info[PROCESS_LIST_WIDTH+1];
 
508
 
 
509
  /**
 
510
   * A pointer to the stack frame of handle_one_connection(),
565
511
   * which is called first in the thread for handling a client
566
512
   */
567
513
  char *thread_stack;
568
514
 
569
 
private:
570
 
  SecurityContext security_ctx;
571
 
 
572
 
  int32_t scoreboard_index;
573
 
 
574
 
  inline void checkSentry() const
575
 
  {
576
 
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
577
 
  }
578
 
public:
579
 
  const SecurityContext& getSecurityContext() const
580
 
  {
581
 
    return security_ctx;
582
 
  }
583
 
 
584
 
  SecurityContext& getSecurityContext()
585
 
  {
586
 
    return security_ctx;
587
 
  }
588
 
 
589
 
  int32_t getScoreboardIndex()
590
 
  {
591
 
    return scoreboard_index;
592
 
  }
593
 
 
594
 
  void setScoreboardIndex(int32_t in_scoreboard_index)
595
 
  {
596
 
    scoreboard_index= in_scoreboard_index;
597
 
  }
598
 
 
599
515
  /**
600
 
   * Is this session viewable by the current user?
601
 
   */
602
 
  bool isViewable() const;
 
516
    @note
 
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.
 
524
 
 
525
    @see handle_slave_sql
 
526
  */
 
527
  Security_context security_ctx;
603
528
 
604
529
  /**
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.
615
540
  */
616
541
  uint32_t dbug_sentry; /**< watch for memory corruption */
617
 
private:
618
 
  boost::thread::id boost_thread_id;
619
 
  boost_thread_shared_ptr _thread;
620
 
  boost::this_thread::disable_interruption *interrupt;
621
 
 
622
 
  internal::st_my_thread_var *mysys_var;
623
 
public:
624
 
 
625
 
  boost_thread_shared_ptr &getThread()
626
 
  {
627
 
    return _thread;
628
 
  }
629
 
 
630
 
  void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
631
 
  {
632
 
    interrupt= interrupt_arg;
633
 
  }
634
 
 
635
 
  boost::this_thread::disable_interruption &getThreadInterupt()
636
 
  {
637
 
    assert(interrupt);
638
 
    return *interrupt;
639
 
  }
640
 
 
641
 
  internal::st_my_thread_var *getThreadVar()
642
 
  {
643
 
    return mysys_var;
644
 
  }
645
 
 
 
542
  struct st_my_thread_var *mysys_var;
646
543
  /**
647
544
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
648
545
   * first byte of the packet in executeStatement()
649
546
   */
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.
664
564
  */
665
565
 
666
 
private:
667
566
  /* container for handler's private per-connection data */
668
 
  std::vector<Ha_data> ha_data;
669
 
  /*
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).
676
 
  */
677
 
  query_id_t query_id;
678
 
  query_id_t warn_query_id;
679
 
public:
680
 
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
681
 
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
682
 
                                      size_t index= 0);
683
 
 
684
 
  /**
685
 
   * Structure used to manage "statement transactions" and
686
 
   * "normal transactions". In autocommit mode, the normal transaction is
687
 
   * equivalent to the statement transaction.
688
 
   *
689
 
   * Storage engines will be registered here when they participate in
690
 
   * a transaction. No engine is registered more than once.
691
 
   */
 
567
  Ha_data ha_data[MAX_HA];
 
568
 
 
569
  /* container for replication data */
 
570
  void *replication_data;
 
571
 
692
572
  struct st_transactions {
693
 
    std::deque<NamedSavepoint> savepoints;
694
 
 
695
 
    /**
696
 
     * The normal transaction (since BEGIN WORK).
697
 
     *
698
 
     * Contains a list of all engines that have participated in any of the
699
 
     * statement transactions started within the context of the normal
700
 
     * transaction.
701
 
     *
702
 
     * @note In autocommit mode, this is empty.
703
 
     */
704
 
    TransactionContext all;
705
 
 
706
 
    /**
707
 
     * The statment transaction.
708
 
     *
709
 
     * Contains a list of all engines participating in the given statement.
710
 
     *
711
 
     * @note In autocommit mode, this will be used to commit/rollback the
712
 
     * normal transaction.
713
 
     */
714
 
    TransactionContext stmt;
715
 
 
 
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;
717
578
 
 
579
    /*
 
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).
 
583
    */
 
584
    CHANGED_TableList* changed_tables;
 
585
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
718
586
    void cleanup()
719
587
    {
720
 
      savepoints.clear();
721
 
    }
722
 
    st_transactions() :
723
 
      savepoints(),
724
 
      all(),
725
 
      stmt(),
726
 
      xid_state()
727
 
    { }
 
588
      changed_tables= 0;
 
589
      savepoints= 0;
 
590
      free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
 
591
    }
 
592
    st_transactions()
 
593
    {
 
594
      memset(this, 0, sizeof(*this));
 
595
      xid_state.xid.null();
 
596
      init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
 
597
    }
728
598
  } transaction;
729
 
 
730
599
  Field *dup_field;
731
600
  sigset_t signals;
732
601
 
733
 
  // As of right now we do not allow a concurrent execute to launch itself
734
 
private:
735
 
  bool concurrent_execute_allowed;
736
 
public:
737
 
 
738
 
  void setConcurrentExecute(bool arg)
739
 
  {
740
 
    concurrent_execute_allowed= arg;
741
 
  }
742
 
 
743
 
  bool isConcurrentExecuteAllowed() const
744
 
  {
745
 
    return concurrent_execute_allowed;
746
 
  }
747
 
 
748
602
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
749
603
  bool arg_of_last_insert_id_function;
750
 
 
751
604
  /*
752
605
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
753
606
    insertion into an auto_increment column".
838
691
  uint32_t total_warn_count;
839
692
  Diagnostics_area main_da;
840
693
 
 
694
  /*
 
695
    Id of current query. Statement can be reused to execute several queries
 
696
    query_id is global in context of the whole MySQL server.
 
697
    ID is automatically generated from mutex-protected counter.
 
698
    It's used in handler code for various purposes: to check which columns
 
699
    from table are necessary for this select, to check if it's necessary to
 
700
    update auto-updatable fields (like auto_increment and timestamp).
 
701
  */
 
702
  query_id_t query_id;
 
703
  query_id_t warn_id;
841
704
  ulong col_access;
842
705
 
 
706
#ifdef ERROR_INJECT_SUPPORT
 
707
  ulong error_inject_value;
 
708
#endif
843
709
  /* Statement id is thread-wide. This counter is used to generate ids */
844
710
  uint32_t statement_id_counter;
845
711
  uint32_t rand_saved_seed1;
849
715
    create_sort_index(); may differ from examined_row_count.
850
716
  */
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
855
 
  {
856
 
    NONE= 0,
857
 
    GOT_GLOBAL_READ_LOCK= 1,
858
 
    MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
859
 
  };
860
 
private:
861
 
  global_read_lock_t _global_read_lock;
862
 
 
863
 
public:
864
 
 
865
 
  global_read_lock_t isGlobalReadLock() const
866
 
  {
867
 
    return _global_read_lock;
868
 
  }
869
 
 
870
 
  void setGlobalReadLock(global_read_lock_t arg)
871
 
  {
872
 
    _global_read_lock= arg;
873
 
  }
874
 
 
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();
890
 
 
891
 
private:
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);
897
 
public:
898
 
 
 
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) */
903
726
  enum_tx_isolation session_tx_isolation;
904
727
  enum_check_fields count_cuted_fields;
905
728
 
906
 
  enum killed_state_t
 
729
  enum killed_state
907
730
  {
908
731
    NOT_KILLED,
909
732
    KILL_BAD_DATA,
911
734
    KILL_QUERY,
912
735
    KILLED_NO_VALUE /* means none of the above states apply */
913
736
  };
914
 
private:
915
 
  killed_state_t volatile _killed;
916
 
 
917
 
public:
918
 
 
919
 
  void setKilled(killed_state_t arg)
920
 
  {
921
 
    _killed= arg;
922
 
  }
923
 
 
924
 
  killed_state_t getKilled()
925
 
  {
926
 
    return _killed;
927
 
  }
928
 
 
929
 
  volatile killed_state_t *getKilledPtr() // Do not use this method, it is here for historical convience.
930
 
  {
931
 
    return &_killed;
932
 
  }
933
 
 
934
 
  bool is_admin_connection;
 
737
  killed_state volatile killed;
 
738
 
935
739
  bool some_tables_deleted;
936
740
  bool no_errors;
937
741
  bool password;
990
794
  */
991
795
  Lex_input_stream *m_lip;
992
796
  
 
797
  /** session_scheduler for events */
 
798
  void *scheduler;
 
799
 
993
800
  /** Place to store various things */
994
801
  void *session_marker;
995
 
 
996
802
  /** Keeps a copy of the previous table around in case we are just slamming on particular table */
997
803
  Table *cached_table;
998
804
 
1013
819
    return proc_info;
1014
820
  }
1015
821
 
1016
 
  /** Sets this Session's current query ID */
1017
 
  inline void setQueryId(query_id_t in_query_id)
1018
 
  {
1019
 
    query_id= in_query_id;
 
822
  inline void setReplicationData (void *data)
 
823
  {
 
824
    replication_data= data;
 
825
  }
 
826
  inline void *getReplicationData () const
 
827
  {
 
828
    return replication_data;
1020
829
  }
1021
830
 
1022
831
  /** Returns the current query ID */
1023
 
  query_id_t getQueryId()  const
 
832
  inline query_id_t getQueryId()  const
1024
833
  {
1025
834
    return query_id;
1026
835
  }
1027
836
 
1028
 
 
1029
 
  /** Sets this Session's warning query ID */
1030
 
  inline void setWarningQueryId(query_id_t in_query_id)
1031
 
  {
1032
 
    warn_query_id= in_query_id;
1033
 
  }
1034
 
 
1035
 
  /** Returns the Session's warning query ID */
1036
 
  inline query_id_t getWarningQueryId()  const
1037
 
  {
1038
 
    return warn_query_id;
1039
 
  }
1040
 
 
1041
 
  /** Accessor method returning the session's ID. */
1042
 
  inline session_id_t getSessionId()  const
1043
 
  {
1044
 
    return thread_id;
 
837
  /** Returns the current query text */
 
838
  inline const char *getQueryString()  const
 
839
  {
 
840
    return query;
 
841
  }
 
842
 
 
843
  /** Returns the length of the current query text */
 
844
  inline size_t getQueryLength() const
 
845
  {
 
846
    return strlen(query);
1045
847
  }
1046
848
 
1047
849
  /** Accessor method returning the server's ID. */
1112
914
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
1113
915
  }
1114
916
 
1115
 
  Session(plugin::Client *client_arg);
1116
 
  virtual ~Session();
 
917
  Session(Protocol *protocol_arg);
 
918
  ~Session();
1117
919
 
 
920
  /**
 
921
    Initialize memory roots necessary for query processing and (!)
 
922
    pre-allocate memory for it. We can't do that in Session constructor because
 
923
    there are use cases (acl_init, watcher threads,
 
924
    killing mysqld) where it's vital to not allocate excessive and not used
 
925
    memory. Note, that we still don't return error from init_for_queries():
 
926
    if preallocation fails, we should notice that at the first call to
 
927
    alloc_root.
 
928
  */
 
929
  void init_for_queries();
1118
930
  void cleanup(void);
1119
931
  /**
1120
932
   * Cleans up after query.
1129
941
   * slave.
1130
942
   */
1131
943
  void cleanup_after_query();
1132
 
  bool storeGlobals();
1133
 
  void awake(Session::killed_state_t state_to_set);
 
944
  bool store_globals();
 
945
  void awake(Session::killed_state state_to_set);
1134
946
  /**
1135
947
   * Pulls thread-specific variables into Session state.
1136
948
   *
1143
955
  bool initGlobals();
1144
956
 
1145
957
  /**
1146
 
    Initialize memory roots necessary for query processing and (!)
1147
 
    pre-allocate memory for it. We can't do that in Session constructor because
1148
 
    there are use cases where it's vital to not allocate excessive and not used
1149
 
    memory.
1150
 
  */
 
958
   * Initializes the Session to handle queries.
 
959
   */
1151
960
  void prepareForQueries();
1152
961
 
1153
962
  /**
1194
1003
   */
1195
1004
  bool endTransaction(enum enum_mysql_completiontype completion);
1196
1005
  bool endActiveTransaction();
1197
 
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
 
1006
  bool startTransaction();
1198
1007
 
1199
1008
  /**
1200
1009
   * Authenticates users, with error reporting.
1203
1012
   */
1204
1013
  bool authenticate();
1205
1014
 
1206
 
  /**
1207
 
   * Run a session.
1208
 
   *
1209
 
   * This will initialize the session and begin the command loop.
1210
 
   */
1211
 
  void run();
1212
 
 
1213
 
  /**
1214
 
   * Schedule a session to be run on the default scheduler.
1215
 
   */
1216
 
  static bool schedule(Session::shared_ptr&);
1217
 
 
1218
 
  static void unlink(Session::shared_ptr&);
1219
 
 
1220
1015
  /*
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().
1224
1019
  */
1225
 
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1226
 
  void exit_cond(const char* old_msg);
1227
 
 
 
1020
  inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
 
1021
  {
 
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);
 
1027
    return old_msg;
 
1028
  }
 
1029
  inline void exit_cond(const char* old_msg)
 
1030
  {
 
1031
    /*
 
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).
 
1036
    */
 
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);
 
1043
  }
1228
1044
  inline time_t query_start() { return start_time; }
1229
1045
  inline void set_time()
1230
1046
  {
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();
1234
 
 
1235
1047
    if (user_time)
1236
1048
    {
1237
1049
      start_time= user_time;
1238
 
      connect_microseconds= start_utime;
 
1050
      start_utime= utime_after_lock= my_micro_time();
1239
1051
    }
1240
 
    else 
1241
 
      start_time= (mytime-epoch).total_seconds();
 
1052
    else
 
1053
      start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1242
1054
  }
1243
1055
  inline void   set_current_time()    { start_time= time(NULL); }
1244
1056
  inline void   set_time(time_t t)
1245
1057
  {
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();
1250
 
 
1251
 
    start_utime= utime_after_lock= t_mark;
1252
 
  }
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();
1257
 
  }
 
1059
    start_utime= utime_after_lock= my_micro_time();
 
1060
  }
 
1061
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
1258
1062
  /**
1259
1063
   * Returns the current micro-timestamp
1260
1064
   */
1261
1065
  inline uint64_t getCurrentTimestamp()  
1262
1066
  { 
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();
1266
 
 
1267
 
    return t_mark; 
 
1067
    return my_micro_time(); 
1268
1068
  }
1269
1069
  inline uint64_t found_rows(void)
1270
1070
  {
1275
1075
  {
1276
1076
    return server_status & SERVER_STATUS_IN_TRANS;
1277
1077
  }
 
1078
  inline bool fill_derived_tables()
 
1079
  {
 
1080
    return !lex->only_view_structure();
 
1081
  }
 
1082
  inline void* trans_alloc(unsigned int size)
 
1083
  {
 
1084
    return alloc_root(&transaction.mem_root,size);
 
1085
  }
 
1086
 
1278
1087
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1279
1088
                              const char* str, uint32_t length,
1280
1089
                              bool allocate_lex_string);
1281
 
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1282
 
                              const std::string &str,
1283
 
                              bool allocate_lex_string);
1284
1090
 
 
1091
  void add_changed_table(Table *table);
 
1092
  void add_changed_table(const char *key, long key_length);
 
1093
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1285
1094
  int send_explain_fields(select_result *result);
1286
1095
  /**
1287
1096
    Clear the current error, if any.
1290
1099
    @todo: To silence an error, one should use Internal_error_handler
1291
1100
    mechanism. In future this function will be removed.
1292
1101
  */
1293
 
  inline void clear_error(bool full= false)
 
1102
  inline void clear_error()
1294
1103
  {
1295
1104
    if (main_da.is_error())
1296
1105
      main_da.reset_diagnostics_area();
1297
 
 
1298
 
    if (full)
1299
 
    {
1300
 
      drizzle_reset_errors(this, true);
1301
 
    }
1302
 
  }
1303
 
 
1304
 
  void clearDiagnostics()
1305
 
  {
1306
 
    main_da.reset_diagnostics_area();
 
1106
    return;
1307
1107
  }
1308
1108
 
1309
1109
  /**
1347
1147
  void end_statement();
1348
1148
  inline int killed_errno() const
1349
1149
  {
1350
 
    killed_state_t killed_val; /* to cache the volatile 'killed' */
1351
 
    return (killed_val= _killed) != KILL_BAD_DATA ? killed_val : 0;
 
1150
    killed_state killed_val; /* to cache the volatile 'killed' */
 
1151
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1352
1152
  }
1353
1153
  void send_kill_message() const;
1354
1154
  /* return true if we will abort query if we make a warning now */
1356
1156
  {
1357
1157
    return (abort_on_warning);
1358
1158
  }
1359
 
 
1360
 
  void setAbort(bool arg);
1361
 
  void lockOnSys();
1362
1159
  void set_status_var_init();
 
1160
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
 
1161
  void restore_backup_open_tables_state(Open_tables_state *backup);
1363
1162
 
1364
1163
  /**
1365
1164
    Set the current database; use deep copy of C-string.
1377
1176
    database usually involves other actions, like switching other database
1378
1177
    attributes including security context. In the future, this operation
1379
1178
    will be made private and more convenient interface will be provided.
1380
 
  */
1381
 
  void set_db(const std::string &new_db);
1382
 
 
 
1179
 
 
1180
    @return Operation status
 
1181
      @retval false Success
 
1182
      @retval true  Out-of-memory error
 
1183
  */
 
1184
  bool set_db(const char *new_db, size_t new_db_len);
 
1185
 
 
1186
  /**
 
1187
    Set the current database; use shallow copy of C-string.
 
1188
 
 
1189
    @param new_db     a pointer to the new database name.
 
1190
    @param new_db_len length of the new database name.
 
1191
 
 
1192
    @note This operation just sets {db, db_length}. Switching the current
 
1193
    database usually involves other actions, like switching other database
 
1194
    attributes including security context. In the future, this operation
 
1195
    will be made private and more convenient interface will be provided.
 
1196
  */
 
1197
  void reset_db(char *new_db, size_t new_db_len)
 
1198
  {
 
1199
    db= new_db;
 
1200
    db_length= new_db_len;
 
1201
  }
1383
1202
  /*
1384
1203
    Copy the current database to the argument. Use the current arena to
1385
1204
    allocate memory for a deep copy: current database may be freed after
1443
1262
   * Current implementation does not depend on that, but future changes
1444
1263
   * should be done with this in mind; 
1445
1264
   *
1446
 
   * @param passwd Scrambled password received from client
1447
 
   * @param db Database name to connect to, may be NULL
1448
 
   */
1449
 
  bool checkUser(const std::string &passwd, const std::string &db);
1450
 
  
1451
 
  /**
1452
 
   * Returns the timestamp (in microseconds) of when the Session 
1453
 
   * connected to the server.
1454
 
   */
1455
 
  inline uint64_t getConnectMicroseconds() const
1456
 
  {
1457
 
    return connect_microseconds;
1458
 
  }
1459
 
 
1460
 
  /**
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.
1464
 
   */
1465
 
  message::Transaction *getTransactionMessage() const
1466
 
  {
1467
 
    return transaction_message;
1468
 
  }
1469
 
 
1470
 
  /**
1471
 
   * Returns a pointer to the active Statement message for this
1472
 
   * Session, or NULL if no active message.
1473
 
   */
1474
 
  message::Statement *getStatementMessage() const
1475
 
  {
1476
 
    return statement_message;
1477
 
  }
1478
 
  
1479
 
  /**
1480
 
   * Returns a pointer to the current Resulset message for this
1481
 
   * Session, or NULL if no active message.
1482
 
   */
1483
 
  message::Resultset *getResultsetMessage() const
1484
 
  {
1485
 
    return resultset;
1486
 
  }
1487
 
  /**
1488
 
   * Sets the active transaction message used by the ReplicationServices
1489
 
   * component.
1490
 
   *
1491
 
   * @param[in] Pointer to the message
1492
 
   */
1493
 
  void setTransactionMessage(message::Transaction *in_message)
1494
 
  {
1495
 
    transaction_message= in_message;
1496
 
  }
1497
 
 
1498
 
  /**
1499
 
   * Sets the active statement message used by the ReplicationServices
1500
 
   * component.
1501
 
   *
1502
 
   * @param[in] Pointer to the message
1503
 
   */
1504
 
  void setStatementMessage(message::Statement *in_message)
1505
 
  {
1506
 
    statement_message= in_message;
1507
 
  }
1508
 
 
1509
 
  /**
1510
 
   * Sets the active Resultset message used by the Query Cache
1511
 
   * plugin.
1512
 
   *
1513
 
   * @param[in] Pointer to the message
1514
 
   */
1515
 
  void setResultsetMessage(message::Resultset *in_message)
1516
 
  {
1517
 
    resultset= in_message;
1518
 
  }
1519
 
  /**
1520
 
   * reset the active Resultset message used by the Query Cache
1521
 
   * plugin.
1522
 
   */
1523
 
 
1524
 
  void resetResultsetMessage()
1525
 
  { 
1526
 
    resultset= NULL;
1527
 
  }
 
1265
   * @param  Scrambled password received from client
 
1266
   * @param  Length of scrambled password
 
1267
   * @param  Database name to connect to, may be NULL
 
1268
   */
 
1269
  bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1528
1270
 
1529
1271
private:
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;
1536
 
  
1537
 
  /* Schema observers are mapped to databases. */
1538
 
  std::map<std::string, plugin::EventObserverList *> schema_event_observers;
1539
 
 
1540
 
 
1541
 
public:
1542
 
  plugin::EventObserverList *getSessionObservers() 
1543
 
  { 
1544
 
    return session_event_observers;
1545
 
  }
1546
 
  
1547
 
  void setSessionObservers(plugin::EventObserverList *observers) 
1548
 
  { 
1549
 
    session_event_observers= observers;
1550
 
  }
1551
 
  
1552
 
  /* For schema event observers there is one set of observers per database. */
1553
 
  plugin::EventObserverList *getSchemaObservers(const std::string &db_name) 
1554
 
  { 
1555
 
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1556
 
    
1557
 
    it= schema_event_observers.find(db_name);
1558
 
    if (it == schema_event_observers.end())
1559
 
      return NULL;
1560
 
      
1561
 
    return it->second;
1562
 
  }
1563
 
  
1564
 
  void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers) 
1565
 
  { 
1566
 
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1567
 
 
1568
 
    it= schema_event_observers.find(db_name);
1569
 
    if (it != schema_event_observers.end())
1570
 
      schema_event_observers.erase(it);;
1571
 
 
1572
 
    if (observers)
1573
 
      schema_event_observers[db_name] = observers;
1574
 
  }
1575
 
  
1576
 
  
1577
 
 private:
1578
 
 /** Microsecond timestamp of when Session connected */
1579
 
  uint64_t connect_microseconds;
1580
1272
  const char *proc_info;
1581
1273
 
1582
1274
  /** The current internal error handler for this thread, or NULL. */
1596
1288
    - for prepared queries, only to allocate runtime data. The parsed
1597
1289
    tree itself is reused between executions and thus is stored elsewhere.
1598
1290
  */
1599
 
  memory::Root main_mem_root;
 
1291
  MEM_ROOT main_mem_root;
1600
1292
 
1601
1293
  /**
1602
1294
   * Marks all tables in the list which were used by current substatement
1617
1309
   * set to query_id of original query.
1618
1310
   */
1619
1311
  void mark_used_tables_as_free_for_reuse(Table *table);
 
1312
  /**
 
1313
    Mark all temporary tables which were used by the current statement or
 
1314
    substatement as free for reuse, but only if the query_id can be cleared.
 
1315
 
 
1316
    @param session thread context
 
1317
 
 
1318
    @remark For temp tables associated with a open SQL HANDLER the query_id
 
1319
            is not reset until the HANDLER is closed.
 
1320
  */
 
1321
  void mark_temp_tables_as_free_for_reuse();
1620
1322
 
1621
1323
public:
1622
1324
 
1623
1325
  /** A short cut for session->main_da.set_ok_status(). */
1624
 
  inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1625
 
                    uint64_t passed_id= 0, const char *message= NULL)
 
1326
  inline void my_ok(ha_rows affected_rows= 0, uint64_t passed_id= 0, const char *message= NULL)
1626
1327
  {
1627
 
    main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
 
1328
    main_da.set_ok_status(this, affected_rows, passed_id, message);
1628
1329
  }
1629
1330
 
1630
1331
 
1658
1359
  }
1659
1360
  void refresh_status();
1660
1361
  user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1661
 
  user_var_entry *getVariable(const std::string  &name, bool create_if_not_exists);
1662
 
  void setVariable(const std::string &name, const std::string &value);
1663
1362
  
1664
1363
  /**
1665
1364
   * Closes all tables used by the current substatement, or all tables
1666
1365
   * used by this thread if we are on the upper level.
1667
1366
   */
1668
1367
  void close_thread_tables();
1669
 
  void close_old_data_files(bool morph_locks= false,
1670
 
                            bool send_refresh= false);
 
1368
  void close_old_data_files(bool morph_locks, bool send_refresh);
1671
1369
  void close_open_tables();
1672
 
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
1673
 
 
1674
 
private:
1675
 
  bool free_cached_table();
1676
 
public:
1677
 
 
 
1370
  void close_data_files_and_morph_locks(const char *db, const char *table_name);
1678
1371
  /**
1679
1372
   * Prepares statement for reopening of tables and recalculation of set of
1680
1373
   * prelocked tables.
1682
1375
   * @param Pointer to a pointer to a list of tables which we were trying to open and lock
1683
1376
   */
1684
1377
  void close_tables_for_reopen(TableList **tables);
1685
 
 
1686
 
 
1687
1378
  /**
1688
1379
   * Open all tables in list, locks them (all, including derived)
1689
1380
   *
1698
1389
   * 
1699
1390
   * The lock will automaticaly be freed by close_thread_tables()
1700
1391
   */
1701
 
  bool openTablesLock(TableList *tables);
1702
 
 
1703
 
  int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1704
 
 
1705
 
  Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1706
 
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1707
 
 
 
1392
  int open_and_lock_tables(TableList *tables);
 
1393
  /**
 
1394
   * Open all tables in list and process derived tables
 
1395
   *
 
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.
 
1400
   *
 
1401
   * @retval
 
1402
   *  false - ok
 
1403
   * @retval
 
1404
   *  true  - error
 
1405
   *
 
1406
   * @note
 
1407
   *
 
1408
   * This is to be used on prepare stage when you don't read any
 
1409
   * data from the tables.
 
1410
   */
 
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);
1711
1419
 
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);
1715
 
 
1716
 
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1717
 
 
1718
 
  class TableMessages
1719
 
  {
1720
 
    TableMessageCache table_message_cache;
1721
 
 
1722
 
  public:
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);
1728
 
 
1729
 
  };
1730
 
private:
1731
 
  TableMessages _table_message_cache;
1732
 
 
1733
 
public:
1734
 
  TableMessages &getMessageCache()
1735
 
  {
1736
 
    return _table_message_cache;
1737
 
  }
1738
 
 
 
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);
 
1424
 
 
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);
 
1431
  
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);
1742
 
 
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);
1746
 
 
1747
 
  drizzled::util::Storable *getProperty(const std::string &arg)
1748
 
  {
1749
 
    return life_properties[arg];
1750
 
  }
1751
 
 
1752
 
  template<class T>
1753
 
  bool setProperty(const std::string &arg, T *value)
1754
 
  {
1755
 
    life_properties[arg]= value;
1756
 
 
1757
 
    return true;
1758
 
  }
1759
 
 
1760
 
  /**
1761
 
    Return the default storage engine
1762
 
 
1763
 
    @param getDefaultStorageEngine()
1764
 
 
1765
 
    @return
1766
 
    pointer to plugin::StorageEngine
1767
 
  */
1768
 
  plugin::StorageEngine *getDefaultStorageEngine()
1769
 
  {
1770
 
    if (variables.storage_engine)
1771
 
      return variables.storage_engine;
1772
 
    return global_system_variables.storage_engine;
1773
 
  }
1774
 
 
1775
 
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1776
 
 
1777
 
  table::Instance *getInstanceTable();
1778
 
  table::Instance *getInstanceTable(List<CreateField> &field_list);
1779
 
 
1780
 
private:
1781
 
  bool resetUsage()
1782
 
  {
1783
 
    if (getrusage(RUSAGE_THREAD, &usage))
1784
 
    {
1785
 
      return false;
1786
 
    }
1787
 
 
1788
 
    return true;
1789
 
  }
1790
 
public:
1791
 
 
1792
 
  void setUsage(bool arg)
1793
 
  {
1794
 
    use_usage= arg;
1795
 
  }
1796
 
 
1797
 
  const struct rusage &getUsage()
1798
 
  {
1799
 
    return usage;
1800
 
  }
1801
 
 
1802
 
private:
1803
 
  // This lives throughout the life of Session
1804
 
  bool use_usage;
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);
 
1435
 
 
1436
  void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1808
1437
};
1809
1438
 
1810
 
class Join;
 
1439
class JOIN;
1811
1440
 
1812
1441
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1813
1442
 
1814
 
} /* namespace drizzled */
1815
 
 
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>
1826
1453
#include <drizzled/select_max_min_finder_subselect.h>
1827
1454
#include <drizzled/select_exists_subselect.h>
1828
1455
 
1829
 
namespace drizzled
1830
 
{
1831
 
 
1832
1456
/**
1833
1457
 * A structure used to describe sort information
1834
1458
 * for a field or item used in ORDER BY.
1835
1459
 */
1836
 
class SortField 
 
1460
typedef struct st_sort_field 
1837
1461
{
1838
 
public:
1839
1462
  Field *field; /**< Field to sort */
1840
1463
  Item  *item; /**< Item if not sorting fields */
1841
1464
  size_t length; /**< Length of sort field */
1843
1466
  Item_result result_type; /**< Type of item */
1844
1467
  bool reverse; /**< if descending sort */
1845
1468
  bool need_strxnfrm;   /**< If we have to use strxnfrm() */
1846
 
 
1847
 
  SortField() :
1848
 
    field(0),
1849
 
    item(0),
1850
 
    length(0),
1851
 
    suffix_length(0),
1852
 
    result_type(STRING_RESULT),
1853
 
    reverse(0),
1854
 
    need_strxnfrm(0)
1855
 
  { }
1856
 
 
1857
 
};
1858
 
 
1859
 
} /* namespace drizzled */
1860
 
 
1861
 
/** @TODO why is this in the middle of the file */
 
1469
} SORT_FIELD;
 
1470
 
 
1471
typedef struct st_sort_buffer 
 
1472
{
 
1473
  uint32_t index;       /* 0 or 1 */
 
1474
  uint32_t sort_orders;
 
1475
  uint32_t change_pos; /* If sort-fields changed */
 
1476
  char **buff;
 
1477
  SORT_FIELD *sortorder;
 
1478
} SORT_BUFFER;
1862
1479
 
1863
1480
#include <drizzled/table_ident.h>
1864
1481
#include <drizzled/user_var_entry.h>
1865
1482
#include <drizzled/unique.h>
1866
 
#include <drizzled/var.h>
 
1483
#include <drizzled/multi_delete.h>
 
1484
#include <drizzled/multi_update.h>
 
1485
#include <drizzled/my_var.h>
1867
1486
#include <drizzled/select_dumpvar.h>
1868
1487
 
1869
 
namespace drizzled
1870
 
{
1871
 
 
1872
1488
/* Bits in sql_command_flags */
1873
1489
 
1874
1490
enum sql_command_flag_bits 
1887
1503
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1888
1504
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1889
1505
 
1890
 
namespace display  {
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 */
 
1506
/* Functions in sql_class.cc */
 
1507
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
1894
1508
 
1895
 
} /* namespace drizzled */
 
1509
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
 
1510
                        STATUS_VAR *dec_var);
1896
1511
 
1897
1512
#endif /* DRIZZLED_SESSION_H */