~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
 
21
20
#ifndef DRIZZLED_SESSION_H
22
21
#define DRIZZLED_SESSION_H
23
22
 
24
 
/* Classes in mysql */
 
23
#include <algorithm>
 
24
#include <bitset>
 
25
#include <boost/make_shared.hpp>
 
26
#include <boost/thread/condition_variable.hpp>
 
27
#include <boost/thread/mutex.hpp>
 
28
#include <boost/thread/shared_mutex.hpp>
 
29
#include <boost/thread/thread.hpp>
 
30
#include <map>
 
31
#include <netdb.h>
 
32
#include <string>
 
33
#include <sys/resource.h>
 
34
#include <sys/time.h>
25
35
 
26
 
#include "drizzled/plugin.h"
27
 
#include <drizzled/sql_locale.h>
28
 
#include "drizzled/resource_context.h"
 
36
#include <drizzled/catalog/instance.h>
 
37
#include <drizzled/catalog/local.h>
 
38
#include <drizzled/copy_info.h>
29
39
#include <drizzled/cursor.h>
30
 
#include <drizzled/current_session.h>
31
 
#include <drizzled/sql_error.h>
 
40
#include <drizzled/diagnostics_area.h>
32
41
#include <drizzled/file_exchange.h>
33
 
#include <drizzled/select_result_interceptor.h>
34
 
#include <drizzled/statistics_variables.h>
35
 
#include <drizzled/xid.h>
36
 
#include "drizzled/query_id.h"
37
 
#include "drizzled/named_savepoint.h"
38
 
#include "drizzled/transaction_context.h"
39
 
#include "drizzled/util/storable.h"
40
 
 
41
 
#include "drizzled/my_hash.h"
42
 
 
43
 
#include <netdb.h>
44
 
#include <map>
45
 
#include <string>
46
 
#include <bitset>
47
 
#include <deque>
48
 
 
49
 
#include "drizzled/internal/getrusage.h"
50
 
 
51
 
#include <drizzled/security_context.h>
 
42
#include <drizzled/ha_data.h>
 
43
#include <drizzled/identifier.h>
 
44
#include <drizzled/lex_column.h>
 
45
#include <drizzled/my_hash.h>
 
46
#include <drizzled/named_savepoint.h>
52
47
#include <drizzled/open_tables_state.h>
53
 
 
54
 
#include <drizzled/internal_error_handler.h>
55
 
#include <drizzled/diagnostics_area.h>
56
 
 
 
48
#include <drizzled/plugin.h>
57
49
#include <drizzled/plugin/authorization.h>
58
 
 
59
 
#include <boost/unordered_map.hpp>
60
 
#include <boost/thread/mutex.hpp>
61
 
#include <boost/thread/shared_mutex.hpp>
62
 
#include <boost/thread/condition_variable.hpp>
 
50
#include <drizzled/pthread_globals.h>
 
51
#include <drizzled/query_id.h>
 
52
#include <drizzled/resource_context.h>
 
53
#include <drizzled/session/property_map.h>
 
54
#include <drizzled/session/state.h>
 
55
#include <drizzled/session/table_messages.h>
 
56
#include <drizzled/session/transactions.h>
 
57
#include <drizzled/sql_error.h>
 
58
#include <drizzled/sql_lex.h>
 
59
#include <drizzled/sql_locale.h>
 
60
#include <drizzled/statistics_variables.h>
 
61
#include <drizzled/system_variables.h>
 
62
#include <drizzled/system_variables.h>
 
63
#include <drizzled/table_ident.h>
 
64
#include <drizzled/transaction_context.h>
 
65
#include <drizzled/util/storable.h>
 
66
#include <drizzled/var.h>
 
67
#include <drizzled/visibility.h>
63
68
 
64
69
#define MIN_HANDSHAKE_SIZE      6
65
70
 
79
84
class Statement;
80
85
class Resultset;
81
86
}
82
 
namespace internal
83
 
{
84
 
struct st_my_thread_var;
85
 
}
86
 
 
 
87
 
 
88
namespace internal { struct st_my_thread_var; }
 
89
namespace table { class Placeholder; }
 
90
 
 
91
class CopyField;
 
92
class DrizzleXid;
 
93
class Internal_error_handler;
87
94
class Lex_input_stream;
 
95
class TableShareInstance;
 
96
class Table_ident;
 
97
class Time_zone;
 
98
class select_result;
88
99
class user_var_entry;
89
 
class CopyField;
90
 
class Table_ident;
91
 
 
92
 
class TableShareInstance;
93
100
 
94
101
extern char internal_table_name[2];
95
102
extern char empty_c_string[1];
99
106
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
100
107
extern uint32_t tc_heuristic_recover;
101
108
 
102
 
/**
103
 
  @brief
104
 
  Local storage for proto that are tmp table. This should be enlarged
105
 
  to hande the entire table-share for a local table. Once Hash is done,
106
 
  we should consider exchanging the map for it.
107
 
*/
108
 
typedef std::map <std::string, message::Table> ProtoCache;
109
 
 
110
 
/**
111
 
  The COPY_INFO structure is used by INSERT/REPLACE code.
112
 
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
113
 
  UPDATE code:
114
 
    If a row is inserted then the copied variable is incremented.
115
 
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
116
 
      new data differs from the old one then the copied and the updated
117
 
      variables are incremented.
118
 
    The touched variable is incremented if a row was touched by the update part
119
 
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
120
 
      was actually changed or not.
121
 
*/
122
 
struct CopyInfo 
123
 
{
124
 
  ha_rows records; /**< Number of processed records */
125
 
  ha_rows deleted; /**< Number of deleted records */
126
 
  ha_rows updated; /**< Number of updated records */
127
 
  ha_rows copied;  /**< Number of copied records */
128
 
  ha_rows error_count;
129
 
  ha_rows touched; /* Number of touched records */
130
 
  enum enum_duplicates handle_duplicates;
131
 
  int escape_char, last_errno;
132
 
  bool ignore;
133
 
  /* for INSERT ... UPDATE */
134
 
  List<Item> *update_fields;
135
 
  List<Item> *update_values;
136
 
  /* for VIEW ... WITH CHECK OPTION */
137
 
 
138
 
  CopyInfo() :
139
 
    records(0),
140
 
    deleted(0),
141
 
    updated(0),
142
 
    copied(0),
143
 
    error_count(0),
144
 
    touched(0),
145
 
    escape_char(0),
146
 
    last_errno(0),
147
 
    ignore(0),
148
 
    update_fields(0),
149
 
    update_values(0)
150
 
  { }
151
 
 
152
 
};
153
 
 
154
 
struct DrizzleLock
155
 
{
156
 
  Table **table;
157
 
  uint32_t table_count;
158
 
  uint32_t lock_count;
159
 
  THR_LOCK_DATA **locks;
160
 
 
161
 
  DrizzleLock() :
162
 
    table(0),
163
 
    table_count(0),
164
 
    lock_count(0),
165
 
    locks(0)
166
 
  { }
167
 
 
168
 
};
169
 
 
170
 
} /* namespace drizzled */
171
 
 
172
 
/** @TODO why is this in the middle of the file */
173
 
#include <drizzled/lex_column.h>
174
 
 
175
 
namespace drizzled
176
 
{
177
 
 
178
 
class select_result;
179
 
class Time_zone;
180
 
 
181
109
#define Session_SENTRY_MAGIC 0xfeedd1ff
182
110
#define Session_SENTRY_GONE  0xdeadbeef
183
111
 
184
 
struct system_variables
185
 
{
186
 
  system_variables() {};
187
 
  /*
188
 
    How dynamically allocated system variables are handled:
189
 
 
190
 
    The global_system_variables and max_system_variables are "authoritative"
191
 
    They both should have the same 'version' and 'size'.
192
 
    When attempting to access a dynamic variable, if the session version
193
 
    is out of date, then the session version is updated and realloced if
194
 
    neccessary and bytes copied from global to make up for missing data.
195
 
  */
196
 
  ulong dynamic_variables_version;
197
 
  char * dynamic_variables_ptr;
198
 
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
199
 
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
200
 
 
201
 
  uint64_t myisam_max_extra_sort_file_size;
202
 
  uint64_t max_heap_table_size;
203
 
  uint64_t tmp_table_size;
204
 
  ha_rows select_limit;
205
 
  ha_rows max_join_size;
206
 
  uint64_t auto_increment_increment;
207
 
  uint64_t auto_increment_offset;
208
 
  uint64_t bulk_insert_buff_size;
209
 
  uint64_t join_buff_size;
210
 
  uint32_t max_allowed_packet;
211
 
  uint64_t max_error_count;
212
 
  uint64_t max_length_for_sort_data;
213
 
  size_t max_sort_length;
214
 
  uint64_t min_examined_row_limit;
215
 
  bool optimizer_prune_level;
216
 
  bool log_warnings;
217
 
 
218
 
  uint32_t optimizer_search_depth;
219
 
  uint32_t div_precincrement;
220
 
  uint64_t preload_buff_size;
221
 
  uint32_t read_buff_size;
222
 
  uint32_t read_rnd_buff_size;
223
 
  size_t sortbuff_size;
224
 
  uint32_t thread_handling;
225
 
  uint32_t tx_isolation;
226
 
  size_t transaction_message_threshold;
227
 
  uint32_t completion_type;
228
 
  /* Determines which non-standard SQL behaviour should be enabled */
229
 
  uint32_t sql_mode;
230
 
  uint64_t max_seeks_for_key;
231
 
  size_t range_alloc_block_size;
232
 
  uint32_t query_alloc_block_size;
233
 
  uint32_t query_prealloc_size;
234
 
  uint64_t group_concat_max_len;
235
 
  uint64_t pseudo_thread_id;
236
 
 
237
 
  plugin::StorageEngine *storage_engine;
238
 
 
239
 
  /* Only charset part of these variables is sensible */
240
 
  const CHARSET_INFO  *character_set_filesystem;
241
 
 
242
 
  /* Both charset and collation parts of these variables are important */
243
 
  const CHARSET_INFO    *collation_server;
244
 
 
245
 
  inline const CHARSET_INFO  *getCollation(void) 
246
 
  {
247
 
    return collation_server;
248
 
  }
249
 
 
250
 
  /* Locale Support */
251
 
  MY_LOCALE *lc_time_names;
252
 
 
253
 
  Time_zone *time_zone;
254
 
};
255
 
 
256
 
extern struct system_variables global_system_variables;
257
 
 
258
 
} /* namespace drizzled */
259
 
 
260
 
#include "drizzled/sql_lex.h"
261
 
 
262
 
namespace drizzled
263
 
{
264
 
 
265
 
void mark_transaction_to_rollback(Session *session, bool all);
266
 
 
267
 
/**
268
 
  Storage engine specific thread local data.
269
 
*/
270
 
struct Ha_data
271
 
{
272
 
  /**
273
 
    Storage engine specific thread local data.
274
 
    Lifetime: one user connection.
275
 
  */
276
 
  void *ha_ptr;
277
 
  /**
278
 
   * Resource contexts for both the "statement" and "normal"
279
 
   * transactions.
280
 
   *
281
 
   * Resource context at index 0:
282
 
   *
283
 
   * Life time: one statement within a transaction. If @@autocommit is
284
 
   * on, also represents the entire transaction.
285
 
   *
286
 
   * Resource context at index 1:
287
 
   *
288
 
   * Life time: one transaction within a connection. 
289
 
   *
290
 
   * @note
291
 
   *
292
 
   * If the storage engine does not participate in a transaction, 
293
 
   * there will not be a resource context.
294
 
   */
295
 
  drizzled::ResourceContext resource_context[2];
296
 
 
297
 
  Ha_data() :ha_ptr(NULL) {}
298
 
};
 
112
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
299
113
 
300
114
/**
301
115
 * Represents a client connection to the database server.
316
130
 * all member variables that are not critical to non-internal operations of the
317
131
 * session object.
318
132
 */
319
 
class Session : public Open_tables_state
 
133
 
 
134
class DRIZZLED_API Session : public Open_tables_state
320
135
{
321
136
public:
322
137
  // Plugin storage in Session.
323
 
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
 
138
  typedef boost::shared_ptr<Session> shared_ptr;
 
139
  typedef Session& reference;
 
140
  typedef const Session& const_reference;
 
141
  typedef const Session* const_pointer;
 
142
  typedef Session* pointer;
 
143
 
 
144
  static shared_ptr make_shared(plugin::Client *client, catalog::Instance::shared_ptr instance_arg)
 
145
  {
 
146
    assert(instance_arg);
 
147
    return boost::make_shared<Session>(client, instance_arg);
 
148
  }
324
149
 
325
150
  /*
326
151
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
334
159
                        and update_row.
335
160
  */
336
161
  enum enum_mark_columns mark_used_columns;
337
 
  inline void* alloc(size_t size)
338
 
  {
339
 
    return mem_root->alloc_root(size);
340
 
  }
341
162
  inline void* calloc(size_t size)
342
163
  {
343
164
    void *ptr;
345
166
      memset(ptr, 0, size);
346
167
    return ptr;
347
168
  }
348
 
  inline char *strdup(const char *str)
349
 
  {
350
 
    return mem_root->strdup_root(str);
351
 
  }
352
169
  inline char *strmake(const char *str, size_t size)
353
170
  {
354
171
    return mem_root->strmake_root(str,size);
355
172
  }
356
 
  inline void *memdup(const void *str, size_t size)
357
 
  {
358
 
    return mem_root->memdup_root(str, size);
359
 
  }
 
173
 
360
174
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
361
175
  {
362
176
    void *ptr;
366
180
  }
367
181
  /** Frees all items attached to this Statement */
368
182
  void free_items();
 
183
 
369
184
  /**
370
185
   * List of items created in the parser for this query. Every item puts
371
186
   * itself to the list on creation (see Item::Item() for details))
378
193
  {
379
194
    return mem_root;
380
195
  }
 
196
 
 
197
  uint64_t xa_id;
 
198
 
 
199
  uint64_t getXaId()
 
200
  {
 
201
    return xa_id;
 
202
  }
 
203
 
 
204
  void setXaId(uint64_t in_xa_id)
 
205
  {
 
206
    xa_id= in_xa_id; 
 
207
  }
 
208
 
381
209
  /**
382
210
   * Uniquely identifies each statement object in thread scope; change during
383
211
   * statement lifetime.
385
213
   * @todo should be const
386
214
   */
387
215
  uint32_t id;
 
216
private:
388
217
  LEX *lex; /**< parse tree descriptor */
389
218
 
 
219
public:
390
220
  LEX *getLex() 
391
221
  {
392
222
    return lex;
393
223
  }
 
224
 
 
225
  enum_sql_command getSqlCommand() const
 
226
  {
 
227
    return lex->sql_command;
 
228
  }
 
229
 
394
230
  /** query associated with this statement */
395
 
  std::string query;
 
231
  typedef boost::shared_ptr<const std::string> QueryString;
 
232
 
 
233
private:
 
234
  boost::shared_ptr<std::string> query;
 
235
 
 
236
  // Never allow for a modification of this outside of the class. c_str()
 
237
  // requires under some setup non const, you must copy the QueryString in
 
238
  // order to use it.
 
239
public:
 
240
  QueryString getQueryString() const
 
241
  {
 
242
    return query;
 
243
  }
 
244
 
 
245
  void resetQueryString()
 
246
  {
 
247
    query.reset();
 
248
    _state.reset();
 
249
  }
 
250
 
 
251
  /*
 
252
    We need to copy the lock on the string in order to make sure we have a stable string.
 
253
    Once this is done we can use it to build a const char* which can be handed off for
 
254
    a method to use (Innodb is currently the only engine using this).
 
255
  */
 
256
  const char *getQueryStringCopy(size_t &length)
 
257
  {
 
258
    QueryString tmp_string(getQueryString());
 
259
 
 
260
    if (not tmp_string)
 
261
    {
 
262
      length= 0;
 
263
      return NULL;
 
264
    }
 
265
 
 
266
    length= tmp_string->length();
 
267
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
 
268
    return to_return;
 
269
  }
 
270
 
 
271
private:
 
272
  session::State::shared_ptr  _state; 
 
273
 
 
274
public:
 
275
 
 
276
  session::State::const_shared_ptr state()
 
277
  {
 
278
    return _state;
 
279
  }
396
280
 
397
281
  /**
398
282
    Name of the current (default) database.
406
290
    the Session of that thread); that thread is (and must remain, for now) the
407
291
    only responsible for freeing this member.
408
292
  */
409
 
  std::string db;
 
293
private:
 
294
  util::string::shared_ptr _schema;
 
295
 
 
296
public:
 
297
 
 
298
  util::string::const_shared_ptr schema() const
 
299
  {
 
300
    if (_schema)
 
301
      return _schema;
 
302
 
 
303
    return util::string::const_shared_ptr(new std::string(""));
 
304
  }
 
305
 
410
306
  /* current cache key */
411
307
  std::string query_cache_key;
412
308
  /**
418
314
  static const char * const DEFAULT_WHERE;
419
315
 
420
316
  memory::Root warn_root; /**< Allocation area for warnings and errors */
 
317
private:
421
318
  plugin::Client *client; /**< Pointer to client object */
 
319
 
 
320
public:
 
321
 
 
322
  void setClient(plugin::Client *client_arg);
 
323
 
 
324
  plugin::Client *getClient()
 
325
  {
 
326
    return client;
 
327
  }
 
328
 
 
329
  plugin::Client *getClient() const
 
330
  {
 
331
    return client;
 
332
  }
 
333
 
422
334
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
423
335
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
424
 
private:
 
336
 
425
337
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
 
338
 
 
339
private:
426
340
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
427
341
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
428
342
 
429
343
public:
430
 
  struct system_variables variables; /**< Mutable local variables local to the session */
 
344
  const UserVars &getUserVariables() const
 
345
  {
 
346
    return user_vars;
 
347
  }
 
348
 
 
349
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
 
350
 
 
351
  enum_tx_isolation getTxIsolation()
 
352
  {
 
353
    return (enum_tx_isolation)variables.tx_isolation;
 
354
  }
 
355
 
431
356
  struct system_status_var status_var; /**< Session-local status counters */
432
357
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
433
358
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
434
359
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
435
 
private:
436
 
  boost::mutex LOCK_delete; /**< Locked before session is deleted */
437
 
public:
438
 
 
439
 
  void lockForDelete()
440
 
  {
441
 
    LOCK_delete.lock();
442
 
  }
443
 
 
444
 
  void unlockForDelete()
445
 
  {
446
 
    LOCK_delete.unlock();
447
 
  }
448
 
 
449
 
  /**
450
 
   * A peek into the query string for the session. This is a best effort
451
 
   * delivery, there is no guarantee whether the content is meaningful.
452
 
   */
453
 
  char process_list_info[PROCESS_LIST_WIDTH+1];
454
360
 
455
361
  /**
456
362
   * A pointer to the stack frame of the scheduler thread
459
365
  char *thread_stack;
460
366
 
461
367
private:
462
 
  SecurityContext security_ctx;
 
368
  identifier::User::shared_ptr security_ctx;
463
369
 
464
370
  int32_t scoreboard_index;
465
371
 
467
373
  {
468
374
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
469
375
  }
 
376
 
470
377
public:
471
 
  const SecurityContext& getSecurityContext() const
 
378
  identifier::User::const_shared_ptr user() const
472
379
  {
473
 
    return security_ctx;
 
380
    if (security_ctx)
 
381
      return security_ctx;
 
382
 
 
383
    return identifier::User::const_shared_ptr();
474
384
  }
475
385
 
476
 
  SecurityContext& getSecurityContext()
 
386
  void setUser(identifier::User::shared_ptr arg)
477
387
  {
478
 
    return security_ctx;
 
388
    security_ctx= arg;
479
389
  }
480
390
 
481
391
  int32_t getScoreboardIndex()
491
401
  /**
492
402
   * Is this session viewable by the current user?
493
403
   */
494
 
  bool isViewable() const
495
 
  {
496
 
    return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
497
 
                                               this,
498
 
                                               false);
499
 
  }
 
404
  bool isViewable(identifier::User::const_reference) const;
500
405
 
 
406
private:
501
407
  /**
502
408
    Used in error messages to tell user in what part of MySQL we found an
503
409
    error. E. g. when where= "having clause", if fix_fields() fails, user
504
410
    will know that the error was in having clause.
505
411
  */
506
 
  const char *where;
 
412
  const char *_where;
 
413
 
 
414
public:
 
415
  const char *where()
 
416
  {
 
417
    return _where;
 
418
  }
 
419
 
 
420
  void setWhere(const char *arg)
 
421
  {
 
422
    _where= arg;
 
423
  }
507
424
 
508
425
  /*
509
426
    One thread can hold up to one named user-level lock. This variable
511
428
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
512
429
  */
513
430
  uint32_t dbug_sentry; /**< watch for memory corruption */
 
431
 
514
432
private:
 
433
  boost::thread::id boost_thread_id;
 
434
  boost_thread_shared_ptr _thread;
 
435
  boost::this_thread::disable_interruption *interrupt;
 
436
 
515
437
  internal::st_my_thread_var *mysys_var;
 
438
 
516
439
public:
 
440
  boost_thread_shared_ptr &getThread()
 
441
  {
 
442
    return _thread;
 
443
  }
 
444
 
 
445
  void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
 
446
  {
 
447
    interrupt= interrupt_arg;
 
448
  }
 
449
 
 
450
  boost::this_thread::disable_interruption &getThreadInterupt()
 
451
  {
 
452
    assert(interrupt);
 
453
    return *interrupt;
 
454
  }
517
455
 
518
456
  internal::st_my_thread_var *getThreadVar()
519
457
  {
520
458
    return mysys_var;
521
459
  }
522
460
 
523
 
  void resetThreadVar()
524
 
  {
525
 
    mysys_var= NULL;
526
 
  }
527
461
  /**
528
462
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
529
463
   * first byte of the packet in executeStatement()
532
466
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
533
467
  /* @note the following three members should likely move to Client */
534
468
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
535
 
  time_t start_time;
536
 
  time_t user_time;
537
 
  uint64_t thr_create_utime; /**< track down slow pthread_create */
538
 
  uint64_t start_utime;
539
 
  uint64_t utime_after_lock;
 
469
 
 
470
private:
 
471
  boost::posix_time::ptime _epoch;
 
472
  boost::posix_time::ptime _connect_time;
 
473
  boost::posix_time::ptime _start_timer;
 
474
  boost::posix_time::ptime _end_timer;
 
475
 
 
476
  boost::posix_time::ptime _user_time;
 
477
public:
 
478
  uint64_t utime_after_lock; // This used by Innodb.
 
479
 
 
480
  void resetUserTime()
 
481
  {
 
482
    _user_time= boost::posix_time::not_a_date_time;
 
483
  }
 
484
 
 
485
  const boost::posix_time::ptime &start_timer() const
 
486
  {
 
487
    return _start_timer;
 
488
  }
 
489
 
 
490
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
 
491
  {
 
492
    result_arg=  arg - _start_timer;
 
493
  }
540
494
 
541
495
  thr_lock_type update_lock_default;
542
496
 
557
511
  */
558
512
  query_id_t query_id;
559
513
  query_id_t warn_query_id;
 
514
 
560
515
public:
561
516
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
562
517
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
563
518
                                      size_t index= 0);
564
519
 
565
 
  struct st_transactions {
566
 
    std::deque<NamedSavepoint> savepoints;
567
 
    TransactionContext all; ///< Trans since BEGIN WORK
568
 
    TransactionContext stmt; ///< Trans for current statement
569
 
    XID_STATE xid_state;
570
 
 
571
 
    void cleanup()
572
 
    {
573
 
      savepoints.clear();
574
 
    }
575
 
    st_transactions() :
576
 
      savepoints(),
577
 
      all(),
578
 
      stmt(),
579
 
      xid_state()
580
 
    { }
581
 
  } transaction;
 
520
  session::Transactions transaction;
582
521
 
583
522
  Field *dup_field;
584
523
  sigset_t signals;
585
524
 
 
525
  // As of right now we do not allow a concurrent execute to launch itself
 
526
private:
 
527
  bool concurrent_execute_allowed;
 
528
 
 
529
public:
 
530
 
 
531
  void setConcurrentExecute(bool arg)
 
532
  {
 
533
    concurrent_execute_allowed= arg;
 
534
  }
 
535
 
 
536
  bool isConcurrentExecuteAllowed() const
 
537
  {
 
538
    return concurrent_execute_allowed;
 
539
  }
 
540
 
586
541
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
587
542
  bool arg_of_last_insert_id_function;
 
543
 
588
544
  /*
589
545
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
590
546
    insertion into an auto_increment column".
638
594
  uint64_t limit_found_rows;
639
595
  uint64_t options; /**< Bitmap of options */
640
596
  int64_t row_count_func; /**< For the ROW_COUNT() function */
 
597
 
 
598
  int64_t rowCount() const
 
599
  {
 
600
    return row_count_func;
 
601
  }
 
602
 
641
603
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
642
604
 
643
605
  /** 
686
648
    create_sort_index(); may differ from examined_row_count.
687
649
  */
688
650
  uint32_t row_count;
689
 
  uint64_t thread_id;
 
651
 
 
652
  uint32_t getRowCount() const
 
653
  {
 
654
    return row_count;
 
655
  }
 
656
 
 
657
  session_id_t thread_id;
690
658
  uint32_t tmp_table;
691
 
  uint32_t global_read_lock;
 
659
  enum global_read_lock_t
 
660
  {
 
661
    NONE= 0,
 
662
    GOT_GLOBAL_READ_LOCK= 1,
 
663
    MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
 
664
  };
 
665
private:
 
666
  global_read_lock_t _global_read_lock;
 
667
 
 
668
public:
 
669
 
 
670
  global_read_lock_t isGlobalReadLock() const
 
671
  {
 
672
    return _global_read_lock;
 
673
  }
 
674
 
 
675
  void setGlobalReadLock(global_read_lock_t arg)
 
676
  {
 
677
    _global_read_lock= arg;
 
678
  }
 
679
 
 
680
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags);
 
681
  bool lockGlobalReadLock();
 
682
  bool lock_table_names(TableList *table_list);
 
683
  bool lock_table_names_exclusively(TableList *table_list);
 
684
  bool makeGlobalReadLockBlockCommit();
 
685
  bool abortLockForThread(Table *table);
 
686
  bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
 
687
  int lock_table_name(TableList *table_list);
 
688
  void abortLock(Table *table);
 
689
  void removeLock(Table *table);
 
690
  void unlockReadTables(DrizzleLock *sql_lock);
 
691
  void unlockSomeTables(Table **table, uint32_t count);
 
692
  void unlockTables(DrizzleLock *sql_lock);
 
693
  void startWaitingGlobalReadLock();
 
694
  void unlockGlobalReadLock();
 
695
 
 
696
private:
 
697
  int unlock_external(Table **table, uint32_t count);
 
698
  int lock_external(Table **tables, uint32_t count);
 
699
  bool wait_for_locked_table_names(TableList *table_list);
 
700
  DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
 
701
                             bool should_lock, Table **write_lock_used);
 
702
public:
 
703
 
692
704
  uint32_t server_status;
693
705
  uint32_t open_options;
694
706
  uint32_t select_number; /**< number of select (used for EXPLAIN) */
696
708
  enum_tx_isolation session_tx_isolation;
697
709
  enum_check_fields count_cuted_fields;
698
710
 
699
 
  enum killed_state
 
711
  enum killed_state_t
700
712
  {
701
713
    NOT_KILLED,
702
714
    KILL_BAD_DATA,
704
716
    KILL_QUERY,
705
717
    KILLED_NO_VALUE /* means none of the above states apply */
706
718
  };
707
 
  killed_state volatile killed;
708
 
 
 
719
private:
 
720
  killed_state_t volatile _killed;
 
721
 
 
722
public:
 
723
 
 
724
  void setKilled(killed_state_t arg)
 
725
  {
 
726
    _killed= arg;
 
727
  }
 
728
 
 
729
  killed_state_t getKilled()
 
730
  {
 
731
    return _killed;
 
732
  }
 
733
 
 
734
  volatile killed_state_t *getKilledPtr() // Do not use this method, it is here for historical convience.
 
735
  {
 
736
    return &_killed;
 
737
  }
 
738
 
 
739
  bool is_admin_connection;
709
740
  bool some_tables_deleted;
710
741
  bool no_errors;
711
742
  bool password;
714
745
    can not continue. In particular, disables activation of
715
746
    CONTINUE or EXIT handlers of stored routines.
716
747
    Reset in the end of processing of the current user request, in
717
 
    @see mysql_reset_session_for_next_command().
 
748
    @see reset_session_for_next_command().
718
749
  */
719
750
  bool is_fatal_error;
720
751
  /**
739
770
  bool substitute_null_with_insert_id;
740
771
  bool cleanup_done;
741
772
 
 
773
private:
742
774
  bool abort_on_warning;
 
775
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
 
776
 
 
777
public:
743
778
  bool got_warning; /**< Set on call to push_warning() */
744
779
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
745
780
  /** set during loop of derived table processing */
746
781
  bool derived_tables_processing;
747
 
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
 
782
 
 
783
  bool doing_tablespace_operation(void)
 
784
  {
 
785
    return tablespace_op;
 
786
  }
 
787
 
 
788
  void setDoingTablespaceOperation(bool doing)
 
789
  {
 
790
    tablespace_op= doing;
 
791
  }
 
792
 
748
793
 
749
794
  /** Used by the sys_var class to store temporary values */
750
795
  union
794
839
  }
795
840
 
796
841
  /** Returns the current query ID */
797
 
  inline query_id_t getQueryId()  const
 
842
  query_id_t getQueryId()  const
798
843
  {
799
844
    return query_id;
800
845
  }
812
857
    return warn_query_id;
813
858
  }
814
859
 
815
 
  /** Returns the current query text */
816
 
  inline const std::string &getQueryString()  const
817
 
  {
818
 
    return query;
819
 
  }
820
 
 
821
 
  /** Returns the length of the current query text */
822
 
  inline size_t getQueryLength() const
823
 
  {
824
 
    if (! query.empty())
825
 
      return query.length();
826
 
    else
827
 
      return 0;
828
 
  }
829
 
 
830
860
  /** Accessor method returning the session's ID. */
831
 
  inline uint64_t getSessionId()  const
 
861
  inline session_id_t getSessionId()  const
832
862
  {
833
863
    return thread_id;
834
864
  }
901
931
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
902
932
  }
903
933
 
904
 
  Session(plugin::Client *client_arg);
 
934
  Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog);
905
935
  virtual ~Session();
906
936
 
907
937
  void cleanup(void);
919
949
   */
920
950
  void cleanup_after_query();
921
951
  bool storeGlobals();
922
 
  void awake(Session::killed_state state_to_set);
 
952
  void awake(Session::killed_state_t state_to_set);
923
953
  /**
924
954
   * Pulls thread-specific variables into Session state.
925
955
   *
984
1014
  bool endTransaction(enum enum_mysql_completiontype completion);
985
1015
  bool endActiveTransaction();
986
1016
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
 
1017
  void markTransactionForRollback(bool all);
987
1018
 
988
1019
  /**
989
1020
   * Authenticates users, with error reporting.
1002
1033
  /**
1003
1034
   * Schedule a session to be run on the default scheduler.
1004
1035
   */
1005
 
  bool schedule();
 
1036
  static bool schedule(Session::shared_ptr&);
 
1037
 
 
1038
  static void unlink(session_id_t &session_id);
 
1039
  static void unlink(Session::shared_ptr&);
1006
1040
 
1007
1041
  /*
1008
1042
    For enter_cond() / exit_cond() to work the mutex must be got before
1012
1046
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1013
1047
  void exit_cond(const char* old_msg);
1014
1048
 
1015
 
  inline time_t query_start() { return start_time; }
1016
 
  inline void set_time()
1017
 
  {
1018
 
    if (user_time)
1019
 
    {
1020
 
      start_time= user_time;
1021
 
      connect_microseconds= start_utime= utime_after_lock= my_micro_time();
1022
 
    }
1023
 
    else
1024
 
      start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1025
 
  }
1026
 
  inline void   set_current_time()    { start_time= time(NULL); }
1027
 
  inline void   set_time(time_t t)
1028
 
  {
1029
 
    start_time= user_time= t;
1030
 
    start_utime= utime_after_lock= my_micro_time();
1031
 
  }
1032
 
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
 
1049
  type::Time::epoch_t query_start()
 
1050
  {
 
1051
    return getCurrentTimestampEpoch();
 
1052
  }
 
1053
 
 
1054
  void set_time()
 
1055
  {
 
1056
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
 
1057
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
 
1058
  }
 
1059
 
 
1060
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
 
1061
  {
 
1062
    _user_time= boost::posix_time::from_time_t(t);
 
1063
  }
 
1064
 
 
1065
  void set_time_after_lock()
 
1066
  { 
 
1067
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
 
1068
    utime_after_lock= (mytime - _epoch).total_microseconds();
 
1069
  }
 
1070
 
 
1071
  void set_end_timer()
 
1072
  {
 
1073
    _end_timer= boost::posix_time::microsec_clock::universal_time();
 
1074
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
 
1075
  }
 
1076
 
 
1077
  uint64_t getElapsedTime() const
 
1078
  {
 
1079
    return (_end_timer - _start_timer).total_microseconds();
 
1080
  }
 
1081
 
1033
1082
  /**
1034
1083
   * Returns the current micro-timestamp
1035
1084
   */
1036
 
  inline uint64_t getCurrentTimestamp()  
1037
 
  { 
1038
 
    return my_micro_time(); 
1039
 
  }
1040
 
  inline uint64_t found_rows(void)
 
1085
  type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
 
1086
  { 
 
1087
    type::Time::epoch_t t_mark;
 
1088
 
 
1089
    if (actual)
 
1090
    {
 
1091
      boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
 
1092
      t_mark= (mytime - _epoch).total_microseconds();
 
1093
    }
 
1094
    else
 
1095
    {
 
1096
      t_mark= (_end_timer - _epoch).total_microseconds();
 
1097
    }
 
1098
 
 
1099
    return t_mark; 
 
1100
  }
 
1101
 
 
1102
  // We may need to set user on this
 
1103
  type::Time::epoch_t getCurrentTimestampEpoch() const
 
1104
  { 
 
1105
    if (not _user_time.is_not_a_date_time())
 
1106
      return (_user_time - _epoch).total_seconds();
 
1107
 
 
1108
    return (_start_timer - _epoch).total_seconds();
 
1109
  }
 
1110
 
 
1111
  type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
 
1112
  { 
 
1113
    if (not _user_time.is_not_a_date_time())
 
1114
    {
 
1115
      fraction_arg= 0;
 
1116
      return (_user_time - _epoch).total_seconds();
 
1117
    }
 
1118
 
 
1119
    fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
 
1120
    return (_start_timer - _epoch).total_seconds();
 
1121
  }
 
1122
 
 
1123
  uint64_t found_rows(void) const
1041
1124
  {
1042
1125
    return limit_found_rows;
1043
1126
  }
 
1127
 
1044
1128
  /** Returns whether the session is currently inside a transaction */
1045
 
  inline bool inTransaction()
 
1129
  bool inTransaction() const
1046
1130
  {
1047
1131
    return server_status & SERVER_STATUS_IN_TRANS;
1048
1132
  }
 
1133
 
1049
1134
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1050
1135
                              const char* str, uint32_t length,
1051
1136
                              bool allocate_lex_string);
 
1137
 
1052
1138
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1053
1139
                              const std::string &str,
1054
1140
                              bool allocate_lex_string);
1055
1141
 
1056
1142
  int send_explain_fields(select_result *result);
 
1143
 
1057
1144
  /**
1058
1145
    Clear the current error, if any.
1059
1146
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
1061
1148
    @todo: To silence an error, one should use Internal_error_handler
1062
1149
    mechanism. In future this function will be removed.
1063
1150
  */
1064
 
  inline void clear_error()
 
1151
  inline void clear_error(bool full= false)
1065
1152
  {
1066
1153
    if (main_da.is_error())
1067
1154
      main_da.reset_diagnostics_area();
1068
 
    return;
 
1155
 
 
1156
    if (full)
 
1157
    {
 
1158
      drizzle_reset_errors(this, true);
 
1159
    }
 
1160
  }
 
1161
 
 
1162
  void clearDiagnostics()
 
1163
  {
 
1164
    main_da.reset_diagnostics_area();
1069
1165
  }
1070
1166
 
1071
1167
  /**
1109
1205
  void end_statement();
1110
1206
  inline int killed_errno() const
1111
1207
  {
1112
 
    killed_state killed_val; /* to cache the volatile 'killed' */
1113
 
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
 
1208
    killed_state_t killed_val; /* to cache the volatile 'killed' */
 
1209
    return (killed_val= _killed) != KILL_BAD_DATA ? killed_val : 0;
1114
1210
  }
1115
1211
  void send_kill_message() const;
1116
1212
  /* return true if we will abort query if we make a warning now */
1117
 
  inline bool really_abort_on_warning()
1118
 
  {
1119
 
    return (abort_on_warning);
 
1213
  inline bool abortOnWarning()
 
1214
  {
 
1215
    return abort_on_warning;
 
1216
  }
 
1217
 
 
1218
  inline void setAbortOnWarning(bool arg)
 
1219
  {
 
1220
    abort_on_warning= arg;
1120
1221
  }
1121
1222
 
1122
1223
  void setAbort(bool arg);
1139
1240
    database usually involves other actions, like switching other database
1140
1241
    attributes including security context. In the future, this operation
1141
1242
    will be made private and more convenient interface will be provided.
1142
 
 
1143
 
    @return Operation status
1144
 
      @retval false Success
1145
 
      @retval true  Out-of-memory error
1146
1243
  */
1147
 
  bool set_db(const std::string &new_db);
 
1244
  void set_db(const std::string &new_db);
1148
1245
 
1149
1246
  /*
1150
1247
    Copy the current database to the argument. Use the current arena to
1166
1263
    @param level the error level
1167
1264
    @return true if the error is handled
1168
1265
  */
1169
 
  virtual bool handle_error(uint32_t sql_errno, const char *message,
 
1266
  virtual bool handle_error(drizzled::error_t sql_errno, const char *message,
1170
1267
                            DRIZZLE_ERROR::enum_warning_level level);
1171
1268
 
1172
1269
  /**
1194
1291
   * updates any status variables necessary.
1195
1292
   *
1196
1293
   * @param errcode     Error code to print to console
1197
 
   * @param should_lock 1 if we have have to lock LOCK_thread_count
1198
1294
   *
1199
1295
   * @note  For the connection that is doing shutdown, this is called twice
1200
1296
   */
1201
 
  void disconnect(uint32_t errcode, bool lock);
 
1297
  void disconnect(enum error_t errcode= EE_OK);
1202
1298
 
1203
1299
  /**
1204
1300
   * Check if user exists and the password supplied is correct.
1209
1305
   * Current implementation does not depend on that, but future changes
1210
1306
   * should be done with this in mind; 
1211
1307
   *
1212
 
   * @param  Scrambled password received from client
1213
 
   * @param  Length of scrambled password
1214
 
   * @param  Database name to connect to, may be NULL
 
1308
   * @param passwd Scrambled password received from client
 
1309
   * @param db Database name to connect to, may be NULL
1215
1310
   */
1216
 
  bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
 
1311
  bool checkUser(const std::string &passwd, const std::string &db);
1217
1312
  
1218
1313
  /**
1219
1314
   * Returns the timestamp (in microseconds) of when the Session 
1220
1315
   * connected to the server.
1221
1316
   */
1222
 
  inline uint64_t getConnectMicroseconds() const
1223
 
  {
1224
 
    return connect_microseconds;
 
1317
  uint64_t getConnectMicroseconds() const
 
1318
  {
 
1319
    return (_connect_time - _epoch).total_microseconds();
 
1320
  }
 
1321
 
 
1322
  uint64_t getConnectSeconds() const
 
1323
  {
 
1324
    return (_connect_time - _epoch).total_seconds();
1225
1325
  }
1226
1326
 
1227
1327
  /**
1342
1442
  
1343
1443
  
1344
1444
 private:
1345
 
 /** Microsecond timestamp of when Session connected */
1346
 
  uint64_t connect_microseconds;
1347
1445
  const char *proc_info;
1348
1446
 
1349
1447
  /** The current internal error handler for this thread, or NULL. */
1384
1482
   * set to query_id of original query.
1385
1483
   */
1386
1484
  void mark_used_tables_as_free_for_reuse(Table *table);
1387
 
  /**
1388
 
    Mark all temporary tables which were used by the current statement or
1389
 
    substatement as free for reuse, but only if the query_id can be cleared.
1390
 
 
1391
 
    @param session thread context
1392
 
 
1393
 
    @remark For temp tables associated with a open SQL HANDLER the query_id
1394
 
            is not reset until the HANDLER is closed.
1395
 
  */
1396
 
  void mark_temp_tables_as_free_for_reuse();
1397
1485
 
1398
1486
public:
1399
1487
 
1435
1523
  }
1436
1524
  void refresh_status();
1437
1525
  user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
 
1526
  user_var_entry *getVariable(const std::string  &name, bool create_if_not_exists);
 
1527
  void setVariable(const std::string &name, const std::string &value);
1438
1528
  
1439
1529
  /**
1440
1530
   * Closes all tables used by the current substatement, or all tables
1444
1534
  void close_old_data_files(bool morph_locks= false,
1445
1535
                            bool send_refresh= false);
1446
1536
  void close_open_tables();
1447
 
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
 
1537
  void close_data_files_and_morph_locks(const identifier::Table &identifier);
1448
1538
 
1449
1539
private:
1450
 
  bool free_cached_table();
 
1540
  bool free_cached_table(boost::mutex::scoped_lock &scopedLock);
 
1541
 
1451
1542
public:
1452
1543
 
1453
1544
  /**
1481
1572
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1482
1573
 
1483
1574
  void unlink_open_table(Table *find);
1484
 
  void drop_open_table(Table *table, TableIdentifier &identifier);
 
1575
  void drop_open_table(Table *table, const identifier::Table &identifier);
1485
1576
  void close_cached_table(Table *table);
1486
1577
 
1487
1578
  /* Create a lock in the cache */
1488
 
  Table *table_cache_insert_placeholder(const char *db_name, const char *table_name);
1489
 
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1490
 
 
1491
 
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1492
 
  TableMessageCache table_message_cache;
1493
 
 
1494
 
  bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1495
 
  bool removeTableMessage(const TableIdentifier &identifier);
1496
 
  bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1497
 
  bool doesTableMessageExist(const TableIdentifier &identifier);
1498
 
  bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1499
 
 
1500
 
  /* Work with temporary tables */
1501
 
  Table *find_temporary_table(TableList *table_list);
1502
 
  Table *find_temporary_table(const char *db, const char *table_name);
1503
 
  Table *find_temporary_table(TableIdentifier &identifier);
1504
 
 
1505
 
  void doGetTableNames(CachedDirectory &directory,
1506
 
                       const SchemaIdentifier &schema_identifier,
1507
 
                       std::set<std::string>& set_of_names);
1508
 
  void doGetTableNames(const SchemaIdentifier &schema_identifier,
1509
 
                       std::set<std::string>& set_of_names);
1510
 
 
1511
 
  void doGetTableIdentifiers(CachedDirectory &directory,
1512
 
                             const SchemaIdentifier &schema_identifier,
1513
 
                             TableIdentifiers &set_of_identifiers);
1514
 
  void doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
1515
 
                             TableIdentifiers &set_of_identifiers);
1516
 
 
1517
 
  int doGetTableDefinition(const drizzled::TableIdentifier &identifier,
1518
 
                           message::Table &table_proto);
1519
 
  bool doDoesTableExist(const drizzled::TableIdentifier &identifier);
1520
 
 
1521
 
  void close_temporary_tables();
1522
 
  void close_temporary_table(Table *table);
1523
 
  // The method below just handles the de-allocation of the table. In
1524
 
  // a better memory type world, this would not be needed.
 
1579
  table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
 
1580
  bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
 
1581
 
1525
1582
private:
1526
 
  void nukeTable(Table *table);
 
1583
  session::TableMessages _table_message_cache;
 
1584
 
1527
1585
public:
1528
 
 
1529
 
  void dumpTemporaryTableNames(const char *id);
1530
 
  int drop_temporary_table(TableList *table_list);
1531
 
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
1532
 
  bool rm_temporary_table(TableIdentifier &identifier, bool best_effort= false);
1533
 
  Table *open_temporary_table(TableIdentifier &identifier,
1534
 
                              bool link_in_list= true);
 
1586
  session::TableMessages &getMessageCache()
 
1587
  {
 
1588
    return _table_message_cache;
 
1589
  }
1535
1590
 
1536
1591
  /* Reopen operations */
1537
 
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
1538
 
  bool reopen_name_locked_table(TableList* table_list, bool link_in);
 
1592
  bool reopen_tables();
1539
1593
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1540
1594
 
1541
1595
  void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1542
1596
  int setup_conds(TableList *leaves, COND **conds);
1543
1597
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1544
1598
 
1545
 
  Table *create_virtual_tmp_table(List<CreateField> &field_list);
1546
 
  
1547
1599
  drizzled::util::Storable *getProperty(const std::string &arg)
1548
1600
  {
1549
 
    return life_properties[arg];
 
1601
    return life_properties.getProperty(arg);
1550
1602
  }
1551
1603
 
1552
1604
  template<class T>
1553
1605
  bool setProperty(const std::string &arg, T *value)
1554
1606
  {
1555
 
    life_properties[arg]= value;
 
1607
    life_properties.setProperty(arg, value);
1556
1608
 
1557
1609
    return true;
1558
1610
  }
1570
1622
    if (variables.storage_engine)
1571
1623
      return variables.storage_engine;
1572
1624
    return global_system_variables.storage_engine;
1573
 
  };
1574
 
 
1575
 
  static void unlink(Session *session);
1576
 
 
1577
 
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1578
 
 
1579
 
  TableShareInstance *getTemporaryShare(TableIdentifier::Type type_arg);
 
1625
  }
 
1626
 
 
1627
  void get_xid(DrizzleXid *xid); // Innodb only
 
1628
 
 
1629
  table::Singular *getInstanceTable();
 
1630
  table::Singular *getInstanceTable(List<CreateField> &field_list);
1580
1631
 
1581
1632
private:
1582
1633
  bool resetUsage()
1588
1639
 
1589
1640
    return true;
1590
1641
  }
 
1642
 
1591
1643
public:
1592
1644
 
1593
1645
  void setUsage(bool arg)
1600
1652
    return usage;
1601
1653
  }
1602
1654
 
 
1655
  catalog::Instance::const_reference catalog() const
 
1656
  {
 
1657
    return *(_catalog.get());
 
1658
  }
 
1659
 
 
1660
  catalog::Instance::reference catalog()
 
1661
  {
 
1662
    return *(_catalog.get());
 
1663
  }
 
1664
 
1603
1665
private:
 
1666
  catalog::Instance::shared_ptr _catalog;
 
1667
 
1604
1668
  // This lives throughout the life of Session
1605
1669
  bool use_usage;
1606
 
  PropertyMap life_properties;
1607
 
  std::vector<TableShareInstance *> temporary_shares;
 
1670
  session::PropertyMap life_properties;
 
1671
  std::vector<table::Singular *> temporary_shares;
1608
1672
  struct rusage usage;
1609
1673
};
1610
1674
 
1611
 
class Join;
1612
 
 
1613
1675
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1614
1676
 
1615
 
} /* namespace drizzled */
1616
 
 
1617
 
/** @TODO why is this in the middle of the file */
1618
 
#include <drizzled/select_to_file.h>
1619
 
#include <drizzled/select_export.h>
1620
 
#include <drizzled/select_dump.h>
1621
 
#include <drizzled/select_insert.h>
1622
 
#include <drizzled/select_create.h>
1623
 
#include <drizzled/tmp_table_param.h>
1624
 
#include <drizzled/select_union.h>
1625
 
#include <drizzled/select_subselect.h>
1626
 
#include <drizzled/select_singlerow_subselect.h>
1627
 
#include <drizzled/select_max_min_finder_subselect.h>
1628
 
#include <drizzled/select_exists_subselect.h>
1629
 
 
1630
 
namespace drizzled
1631
 
{
1632
 
 
1633
 
/**
1634
 
 * A structure used to describe sort information
1635
 
 * for a field or item used in ORDER BY.
1636
 
 */
1637
 
struct SortField 
1638
 
{
1639
 
  Field *field; /**< Field to sort */
1640
 
  Item  *item; /**< Item if not sorting fields */
1641
 
  size_t length; /**< Length of sort field */
1642
 
  uint32_t suffix_length; /**< Length suffix (0-4) */
1643
 
  Item_result result_type; /**< Type of item */
1644
 
  bool reverse; /**< if descending sort */
1645
 
  bool need_strxnfrm;   /**< If we have to use strxnfrm() */
1646
 
 
1647
 
  SortField() :
1648
 
    field(0),
1649
 
    item(0),
1650
 
    length(0),
1651
 
    suffix_length(0),
1652
 
    result_type(STRING_RESULT),
1653
 
    reverse(0),
1654
 
    need_strxnfrm(0)
1655
 
  { }
1656
 
 
1657
 
};
1658
 
 
1659
 
} /* namespace drizzled */
1660
 
 
1661
 
/** @TODO why is this in the middle of the file */
1662
 
 
1663
 
#include <drizzled/table_ident.h>
1664
 
#include <drizzled/user_var_entry.h>
1665
 
#include <drizzled/unique.h>
1666
 
#include <drizzled/var.h>
1667
 
#include <drizzled/select_dumpvar.h>
1668
 
 
1669
 
namespace drizzled
1670
 
{
1671
 
 
1672
1677
/* Bits in sql_command_flags */
1673
1678
 
1674
1679
enum sql_command_flag_bits 
1687
1692
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1688
1693
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1689
1694
 
 
1695
namespace display  {
 
1696
const std::string &type(drizzled::Session::global_read_lock_t type);
 
1697
size_t max_string_length(drizzled::Session::global_read_lock_t type);
 
1698
 
 
1699
} /* namespace display */
 
1700
 
1690
1701
} /* namespace drizzled */
1691
1702
 
1692
1703
#endif /* DRIZZLED_SESSION_H */