~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#pragma once
 
20
#ifndef DRIZZLED_SESSION_H
 
21
#define DRIZZLED_SESSION_H
 
22
 
 
23
#include "drizzled/cursor.h"
 
24
#include "drizzled/diagnostics_area.h"
 
25
#include "drizzled/file_exchange.h"
 
26
#include "drizzled/identifier.h"
 
27
#include "drizzled/internal_error_handler.h"
 
28
#include "drizzled/my_hash.h"
 
29
#include "drizzled/named_savepoint.h"
 
30
#include "drizzled/open_tables_state.h"
 
31
#include "drizzled/plugin.h"
 
32
#include "drizzled/plugin/authorization.h"
 
33
#include "drizzled/pthread_globals.h"
 
34
#include "drizzled/query_id.h"
 
35
#include "drizzled/resource_context.h"
 
36
#include "drizzled/select_result_interceptor.h"
 
37
#include "drizzled/sql_error.h"
 
38
#include "drizzled/sql_locale.h"
 
39
#include "drizzled/statistics_variables.h"
 
40
#include "drizzled/transaction_context.h"
 
41
#include "drizzled/util/storable.h"
 
42
#include "drizzled/xid.h"
 
43
 
 
44
 
 
45
#include <netdb.h>
 
46
#include <sys/time.h>
 
47
#include <sys/resource.h>
21
48
 
22
49
#include <algorithm>
23
50
#include <bitset>
24
 
#include <boost/make_shared.hpp>
25
 
#include <boost/scoped_ptr.hpp>
26
 
#include <boost/thread/condition_variable.hpp>
 
51
#include <map>
 
52
#include <string>
 
53
 
 
54
#include "drizzled/catalog/instance.h"
 
55
#include "drizzled/catalog/local.h"
 
56
 
 
57
#include <drizzled/session/property_map.h>
 
58
#include <drizzled/session/state.h>
 
59
#include <drizzled/session/table_messages.h>
 
60
#include <drizzled/session/transactions.h>
 
61
#include <drizzled/system_variables.h>
 
62
#include <drizzled/copy_info.h>
 
63
#include <drizzled/system_variables.h>
 
64
#include <drizzled/ha_data.h>
 
65
 
 
66
#include <boost/thread/thread.hpp>
27
67
#include <boost/thread/mutex.hpp>
28
68
#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>
35
 
 
36
 
#include <drizzled/charset.h>
37
 
#include <drizzled/base.h>
38
 
#include <drizzled/error.h>
39
 
#include <drizzled/lock.h>
40
 
#include <drizzled/pthread_globals.h>
41
 
#include <drizzled/sql_error.h>
42
 
#include <drizzled/sql_locale.h>
43
 
#include <drizzled/visibility.h>
44
 
#include <drizzled/util/find_ptr.h>
45
 
#include <drizzled/util/string.h>
46
 
#include <drizzled/type/time.h>
47
 
 
48
 
namespace drizzled {
 
69
#include <boost/thread/condition_variable.hpp>
 
70
#include <boost/make_shared.hpp>
 
71
 
 
72
#include <drizzled/lex_column.h>
 
73
#include "drizzled/sql_lex.h"
 
74
 
 
75
#include "drizzled/visibility.h"
 
76
 
 
77
#define MIN_HANDSHAKE_SIZE      6
 
78
 
 
79
namespace drizzled
 
80
{
 
81
 
 
82
namespace plugin
 
83
{
 
84
class Client;
 
85
class Scheduler;
 
86
class EventObserverList;
 
87
}
 
88
 
 
89
namespace message
 
90
{
 
91
class Transaction;
 
92
class Statement;
 
93
class Resultset;
 
94
}
 
95
 
 
96
namespace internal { struct st_my_thread_var; }
 
97
 
 
98
namespace table { class Placeholder; }
 
99
 
 
100
class Lex_input_stream;
 
101
class user_var_entry;
 
102
class CopyField;
 
103
class Table_ident;
 
104
 
 
105
class TableShareInstance;
49
106
 
50
107
extern char internal_table_name[2];
51
108
extern char empty_c_string[1];
52
109
extern const char **errmesg;
53
 
extern uint32_t server_id;
54
 
extern std::string server_uuid;
55
110
 
56
111
#define TC_HEURISTIC_RECOVER_COMMIT   1
57
112
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
58
113
extern uint32_t tc_heuristic_recover;
59
114
 
 
115
class select_result;
 
116
class Time_zone;
 
117
 
 
118
#define Session_SENTRY_MAGIC 0xfeedd1ff
 
119
#define Session_SENTRY_GONE  0xdeadbeef
 
120
 
60
121
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
61
122
 
62
123
/**
79
140
 * session object.
80
141
 */
81
142
 
82
 
class Open_tables_state;
83
 
 
84
 
class DRIZZLED_API Session
 
143
class DRIZZLED_API Session : public Open_tables_state
85
144
{
86
 
private:
87
 
  class impl_c;
88
 
 
89
 
  boost::scoped_ptr<impl_c> impl_;
90
145
public:
 
146
  // Plugin storage in Session.
91
147
  typedef boost::shared_ptr<Session> shared_ptr;
 
148
  typedef Session& reference;
 
149
  typedef const Session& const_reference;
 
150
  typedef const Session* const_pointer;
 
151
  typedef Session* pointer;
92
152
 
93
 
  static shared_ptr make_shared(plugin::Client *client, boost::shared_ptr<catalog::Instance> instance_arg)
 
153
  static shared_ptr make_shared(plugin::Client *client, catalog::Instance::shared_ptr instance_arg)
94
154
  {
95
155
    assert(instance_arg);
96
156
    return boost::make_shared<Session>(client, instance_arg);
107
167
                        that it needs to update this field in write_row
108
168
                        and update_row.
109
169
  */
110
 
  enum_mark_columns mark_used_columns;
 
170
  enum enum_mark_columns mark_used_columns;
111
171
  inline void* calloc(size_t size)
112
172
  {
113
 
    void *ptr= mem_root->alloc_root(size);
114
 
    if (ptr)
 
173
    void *ptr;
 
174
    if ((ptr= mem_root->alloc_root(size)))
115
175
      memset(ptr, 0, size);
116
176
    return ptr;
117
177
  }
122
182
 
123
183
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
124
184
  {
125
 
    void *ptr= mem_root->alloc_root(size + gap);
126
 
    if (ptr)
127
 
      memcpy(ptr, str, size);
 
185
    void *ptr;
 
186
    if ((ptr= mem_root->alloc_root(size + gap)))
 
187
      memcpy(ptr,str,size);
128
188
    return ptr;
129
189
  }
130
190
  /** Frees all items attached to this Statement */
137
197
  Item *free_list;
138
198
  memory::Root *mem_root; /**< Pointer to current memroot */
139
199
 
 
200
 
140
201
  memory::Root *getMemRoot()
141
202
  {
142
203
    return mem_root;
143
204
  }
144
205
 
 
206
  uint64_t xa_id;
 
207
 
145
208
  uint64_t getXaId()
146
209
  {
147
210
    return xa_id;
149
212
 
150
213
  void setXaId(uint64_t in_xa_id)
151
214
  {
152
 
    xa_id= in_xa_id;
153
 
  }
154
 
 
155
 
public:
156
 
  Diagnostics_area& main_da();
157
 
  const LEX& lex() const;
158
 
  LEX& lex();
159
 
  enum_sql_command getSqlCommand() const;
 
215
    xa_id= in_xa_id; 
 
216
  }
 
217
 
 
218
  /**
 
219
   * Uniquely identifies each statement object in thread scope; change during
 
220
   * statement lifetime.
 
221
   *
 
222
   * @todo should be const
 
223
   */
 
224
  uint32_t id;
 
225
  LEX *lex; /**< parse tree descriptor */
 
226
 
 
227
  LEX *getLex() 
 
228
  {
 
229
    return lex;
 
230
  }
 
231
 
 
232
  enum_sql_command getSqlCommand() const
 
233
  {
 
234
    return lex->sql_command;
 
235
  }
160
236
 
161
237
  /** query associated with this statement */
162
238
  typedef boost::shared_ptr<const std::string> QueryString;
168
244
  // requires under some setup non const, you must copy the QueryString in
169
245
  // order to use it.
170
246
public:
171
 
  void resetQueryString();
172
 
  const boost::shared_ptr<session::State>& state();
173
 
 
174
247
  QueryString getQueryString() const
175
248
  {
176
249
    return query;
177
250
  }
178
251
 
179
 
  const char* getQueryStringCopy(size_t &length)
 
252
  void resetQueryString()
 
253
  {
 
254
    query.reset();
 
255
    _state.reset();
 
256
  }
 
257
 
 
258
  /*
 
259
    We need to copy the lock on the string in order to make sure we have a stable string.
 
260
    Once this is done we can use it to build a const char* which can be handed off for
 
261
    a method to use (Innodb is currently the only engine using this).
 
262
  */
 
263
  const char *getQueryStringCopy(size_t &length)
180
264
  {
181
265
    QueryString tmp_string(getQueryString());
 
266
 
182
267
    if (not tmp_string)
183
268
    {
184
269
      length= 0;
185
270
      return NULL;
186
271
    }
 
272
 
187
273
    length= tmp_string->length();
188
 
    return strmake(tmp_string->c_str(), tmp_string->length());
189
 
  }
190
 
 
191
 
  util::string::ptr schema() const;
 
274
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
 
275
    return to_return;
 
276
  }
 
277
 
 
278
private:
 
279
  session::State::shared_ptr  _state; 
 
280
 
 
281
public:
 
282
 
 
283
  session::State::const_shared_ptr state()
 
284
  {
 
285
    return _state;
 
286
  }
 
287
 
 
288
  /**
 
289
    Name of the current (default) database.
 
290
 
 
291
    If there is the current (default) database, "db" contains its name. If
 
292
    there is no current (default) database, "db" is NULL and "db_length" is
 
293
    0. In other words, "db", "db_length" must either be NULL, or contain a
 
294
    valid database name.
 
295
 
 
296
    @note this attribute is set and alloced by the slave SQL thread (for
 
297
    the Session of that thread); that thread is (and must remain, for now) the
 
298
    only responsible for freeing this member.
 
299
  */
 
300
private:
 
301
  util::string::shared_ptr _schema;
 
302
 
 
303
public:
 
304
 
 
305
  util::string::const_shared_ptr schema() const
 
306
  {
 
307
    if (_schema)
 
308
      return _schema;
 
309
 
 
310
    return util::string::const_shared_ptr(new std::string(""));
 
311
  }
192
312
 
193
313
  /* current cache key */
194
314
  std::string query_cache_key;
201
321
  static const char * const DEFAULT_WHERE;
202
322
 
203
323
  memory::Root warn_root; /**< Allocation area for warnings and errors */
 
324
private:
 
325
  plugin::Client *client; /**< Pointer to client object */
 
326
 
204
327
public:
 
328
 
205
329
  void setClient(plugin::Client *client_arg);
206
330
 
 
331
  plugin::Client *getClient()
 
332
  {
 
333
    return client;
 
334
  }
 
335
 
207
336
  plugin::Client *getClient() const
208
337
  {
209
338
    return client;
224
353
    return user_vars;
225
354
  }
226
355
 
227
 
  drizzle_system_variables& variables; /**< Mutable local variables local to the session */
228
 
  enum_tx_isolation getTxIsolation();
229
 
  system_status_var& status_var;
230
 
 
 
356
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
 
357
 
 
358
  enum_tx_isolation getTxIsolation()
 
359
  {
 
360
    return (enum_tx_isolation)variables.tx_isolation;
 
361
  }
 
362
 
 
363
  struct system_status_var status_var; /**< Session-local status counters */
231
364
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
232
365
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
233
366
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
238
371
   */
239
372
  char *thread_stack;
240
373
 
241
 
  identifier::user::ptr user() const
242
 
  {
243
 
    return security_ctx ? security_ctx : identifier::user::ptr();
244
 
  }
245
 
 
246
 
  void setUser(identifier::user::mptr arg)
 
374
private:
 
375
  identifier::User::shared_ptr security_ctx;
 
376
 
 
377
  int32_t scoreboard_index;
 
378
 
 
379
  inline void checkSentry() const
 
380
  {
 
381
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
 
382
  }
 
383
 
 
384
public:
 
385
  identifier::User::const_shared_ptr user() const
 
386
  {
 
387
    if (security_ctx)
 
388
      return security_ctx;
 
389
 
 
390
    return identifier::User::const_shared_ptr();
 
391
  }
 
392
 
 
393
  void setUser(identifier::User::shared_ptr arg)
247
394
  {
248
395
    security_ctx= arg;
249
396
  }
258
405
    scoreboard_index= in_scoreboard_index;
259
406
  }
260
407
 
261
 
  bool isOriginatingServerUUIDSet()
262
 
  {
263
 
    return originating_server_uuid_set;
264
 
  }
265
 
 
266
 
  void setOriginatingServerUUID(std::string in_originating_server_uuid)
267
 
  {
268
 
    originating_server_uuid= in_originating_server_uuid;
269
 
    originating_server_uuid_set= true;
270
 
  }
271
 
 
272
 
  std::string &getOriginatingServerUUID()
273
 
  {
274
 
    return originating_server_uuid;
275
 
  }
276
 
 
277
 
  void setOriginatingCommitID(uint64_t in_originating_commit_id)
278
 
  {
279
 
    originating_commit_id= in_originating_commit_id;
280
 
  }
281
 
 
282
 
  uint64_t getOriginatingCommitID()
283
 
  {
284
 
    return originating_commit_id;
285
 
  }
286
 
 
287
408
  /**
288
409
   * Is this session viewable by the current user?
289
410
   */
290
 
  bool isViewable(const identifier::User&) const;
 
411
  bool isViewable(identifier::User::const_reference) const;
291
412
 
292
413
private:
293
414
  /**
313
434
    points to a lock object if the lock is present. See item_func.cc and
314
435
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
315
436
  */
 
437
  uint32_t dbug_sentry; /**< watch for memory corruption */
316
438
 
317
439
private:
318
440
  boost::thread::id boost_thread_id;
319
 
  thread_ptr _thread;
 
441
  boost_thread_shared_ptr _thread;
320
442
  boost::this_thread::disable_interruption *interrupt;
321
443
 
322
444
  internal::st_my_thread_var *mysys_var;
323
445
 
324
446
public:
325
 
  thread_ptr &getThread()
 
447
  boost_thread_shared_ptr &getThread()
326
448
  {
327
449
    return _thread;
328
450
  }
347
469
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
348
470
   * first byte of the packet in executeStatement()
349
471
   */
350
 
  enum_server_command command;
 
472
  enum enum_server_command command;
 
473
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
 
474
  /* @note the following three members should likely move to Client */
 
475
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
 
476
 
 
477
private:
 
478
  boost::posix_time::ptime _epoch;
 
479
  boost::posix_time::ptime _connect_time;
 
480
  boost::posix_time::ptime _start_timer;
 
481
  boost::posix_time::ptime _end_timer;
 
482
 
 
483
  boost::posix_time::ptime _user_time;
 
484
public:
 
485
  uint64_t utime_after_lock; // This used by Innodb.
 
486
 
 
487
  void resetUserTime()
 
488
  {
 
489
    _user_time= boost::posix_time::not_a_date_time;
 
490
  }
 
491
 
 
492
  const boost::posix_time::ptime &start_timer() const
 
493
  {
 
494
    return _start_timer;
 
495
  }
 
496
 
 
497
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
 
498
  {
 
499
    result_arg=  arg - _start_timer;
 
500
  }
351
501
 
352
502
  thr_lock_type update_lock_default;
353
503
 
371
521
 
372
522
public:
373
523
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
374
 
  ResourceContext& getResourceContext(const plugin::MonitoredInTransaction&, size_t index= 0);
 
524
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
 
525
                                      size_t index= 0);
375
526
 
376
 
  session::Transactions& transaction;
377
 
  Open_tables_state& open_tables;
378
 
        session::Times& times;
 
527
  session::Transactions transaction;
379
528
 
380
529
  Field *dup_field;
381
530
  sigset_t signals;
382
531
 
383
 
public:
384
532
  // As of right now we do not allow a concurrent execute to launch itself
 
533
private:
 
534
  bool concurrent_execute_allowed;
 
535
 
 
536
public:
 
537
 
385
538
  void setConcurrentExecute(bool arg)
386
539
  {
387
540
    concurrent_execute_allowed= arg;
392
545
    return concurrent_execute_allowed;
393
546
  }
394
547
 
 
548
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
 
549
  bool arg_of_last_insert_id_function;
 
550
 
395
551
  /*
396
552
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
397
553
    insertion into an auto_increment column".
438
594
    (first_successful_insert_id_in_cur_stmt == 0), but storing "INSERT_ID=3"
439
595
    in the binlog is still needed; the list's minimum will contain 3.
440
596
  */
 
597
  Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
 
598
  /** Used by replication and SET INSERT_ID */
 
599
  Discrete_intervals_list auto_inc_intervals_forced;
441
600
 
442
601
  uint64_t limit_found_rows;
443
602
  uint64_t options; /**< Bitmap of options */
450
609
 
451
610
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
452
611
 
453
 
  /**
 
612
  /** 
454
613
   * Number of rows we actually sent to the client, including "synthetic"
455
614
   * rows in ROLLUP etc.
456
615
   */
466
625
   * of the query.
467
626
   *
468
627
   * @todo
469
 
   *
 
628
   * 
470
629
   * Possibly this it is incorrect to have used tables in Session because
471
630
   * with more than one subquery, it is not clear what does the field mean.
472
631
   */
474
633
 
475
634
  /**
476
635
    @todo
477
 
 
 
636
    
478
637
    This, and some other variables like 'count_cuted_fields'
479
638
    maybe should be statement/cursor local, that is, moved to Statement
480
639
    class. With current implementation warnings produced in each prepared
481
640
    statement/cursor settle here.
482
641
  */
 
642
  List<DRIZZLE_ERROR> warn_list;
483
643
  uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
484
644
  uint32_t total_warn_count;
485
 
 
 
645
  Diagnostics_area main_da;
 
646
 
 
647
  ulong col_access;
 
648
 
 
649
  /* Statement id is thread-wide. This counter is used to generate ids */
 
650
  uint32_t statement_id_counter;
 
651
  uint32_t rand_saved_seed1;
 
652
  uint32_t rand_saved_seed2;
486
653
  /**
487
654
    Row counter, mainly for errors and warnings. Not increased in
488
655
    create_sort_index(); may differ from examined_row_count.
489
656
  */
490
657
  uint32_t row_count;
491
658
 
 
659
  uint32_t getRowCount() const
 
660
  {
 
661
    return row_count;
 
662
  }
 
663
 
492
664
  session_id_t thread_id;
493
665
  uint32_t tmp_table;
494
666
  enum global_read_lock_t
572
744
  }
573
745
 
574
746
  bool is_admin_connection;
 
747
  bool some_tables_deleted;
575
748
  bool no_errors;
 
749
  bool password;
576
750
  /**
577
751
    Set to true if execution of the current compound statement
578
752
    can not continue. In particular, disables activation of
603
777
  bool substitute_null_with_insert_id;
604
778
  bool cleanup_done;
605
779
 
 
780
private:
 
781
  bool abort_on_warning;
 
782
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
 
783
 
606
784
public:
607
785
  bool got_warning; /**< Set on call to push_warning() */
608
786
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
609
787
  /** set during loop of derived table processing */
610
788
  bool derived_tables_processing;
611
789
 
612
 
  bool doing_tablespace_operation()
 
790
  bool doing_tablespace_operation(void)
613
791
  {
614
792
    return tablespace_op;
615
793
  }
637
815
    and may point to invalid memory after that.
638
816
  */
639
817
  Lex_input_stream *m_lip;
640
 
 
 
818
  
641
819
  /** Place to store various things */
642
820
  void *session_marker;
643
821
 
 
822
  /** Keeps a copy of the previous table around in case we are just slamming on particular table */
 
823
  Table *cached_table;
 
824
 
644
825
  /**
645
826
    Points to info-string that we show in SHOW PROCESSLIST
646
827
    You are supposed to call Session_SET_PROC_INFO only if you have coded
650
831
    macro/function.
651
832
  */
652
833
  inline void set_proc_info(const char *info)
653
 
  {
 
834
  { 
654
835
    proc_info= info;
655
836
  }
656
837
  inline const char* get_proc_info() const
696
877
    return server_id;
697
878
  }
698
879
 
699
 
  inline std::string &getServerUUID() const
 
880
  /** Returns the current transaction ID for the session's current statement */
 
881
  inline my_xid getTransactionId()
700
882
  {
701
 
    return server_uuid;
 
883
    return transaction.xid_state.xid.quick_get_my_xid();
702
884
  }
703
 
 
704
885
  /**
705
886
    There is BUG#19630 where statement-based replication of stored
706
887
    functions/triggers with two auto_increment columns breaks.
742
923
    if (first_successful_insert_id_in_cur_stmt == 0)
743
924
      first_successful_insert_id_in_cur_stmt= id_arg;
744
925
  }
745
 
  inline uint64_t read_first_successful_insert_id_in_prev_stmt()
 
926
  inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
746
927
  {
747
928
    return first_successful_insert_id_in_prev_stmt;
748
929
  }
 
930
  /**
 
931
    Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#"
 
932
    (mysqlbinlog). We'll soon add a variant which can take many intervals in
 
933
    argument.
 
934
  */
 
935
  inline void force_one_auto_inc_interval(uint64_t next_id)
 
936
  {
 
937
    auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
 
938
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
 
939
  }
749
940
 
750
 
  Session(plugin::Client *client_arg, boost::shared_ptr<catalog::Instance> catalog);
 
941
  Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog);
751
942
  virtual ~Session();
752
943
 
753
 
  void cleanup();
 
944
  void cleanup(void);
754
945
  /**
755
946
   * Cleans up after query.
756
947
   *
764
955
   * slave.
765
956
   */
766
957
  void cleanup_after_query();
767
 
  void storeGlobals();
 
958
  bool storeGlobals();
768
959
  void awake(Session::killed_state_t state_to_set);
 
960
  /**
 
961
   * Pulls thread-specific variables into Session state.
 
962
   *
 
963
   * Returns true most times, or false if there was a problem
 
964
   * allocating resources for thread-specific storage.
 
965
   *
 
966
   * @TODO Kill this.  It's not necessary once my_thr_init() is bye bye.
 
967
   *
 
968
   */
 
969
  bool initGlobals();
769
970
 
770
971
  /**
771
972
    Initialize memory roots necessary for query processing and (!)
776
977
  void prepareForQueries();
777
978
 
778
979
  /**
779
 
   * Executes a single statement received from the
 
980
   * Executes a single statement received from the 
780
981
   * client connection.
781
982
   *
782
 
   * Returns true if the statement was successful, or false
 
983
   * Returns true if the statement was successful, or false 
783
984
   * otherwise.
784
985
   *
785
986
   * @note
794
995
  /**
795
996
   * Reads a query from packet and stores it.
796
997
   *
797
 
   * Returns true if query is read and allocated successfully,
 
998
   * Returns true if query is read and allocated successfully, 
798
999
   * false otherwise.  On a return of false, Session::fatal_error
799
1000
   * is set.
800
1001
   *
807
1008
   * @param The packet pointer to read from
808
1009
   * @param The length of the query to read
809
1010
   */
810
 
  void readAndStoreQuery(const char *in_packet, uint32_t in_packet_length);
 
1011
  bool readAndStoreQuery(const char *in_packet, uint32_t in_packet_length);
811
1012
 
812
1013
  /**
813
1014
   * Ends the current transaction and (maybe) begins the next.
814
1015
   *
815
 
   * Returns true if the transaction completed successfully,
 
1016
   * Returns true if the transaction completed successfully, 
816
1017
   * otherwise false.
817
1018
   *
818
1019
   * @param Completion type
828
1029
   * Returns true on success, or false on failure.
829
1030
   */
830
1031
  bool authenticate();
 
1032
 
 
1033
  /**
 
1034
   * Run a session.
 
1035
   *
 
1036
   * This will initialize the session and begin the command loop.
 
1037
   */
831
1038
  void run();
 
1039
 
 
1040
  /**
 
1041
   * Schedule a session to be run on the default scheduler.
 
1042
   */
832
1043
  static bool schedule(Session::shared_ptr&);
833
 
  static void unlink(session_id_t&);
 
1044
 
 
1045
  static void unlink(session_id_t &session_id);
834
1046
  static void unlink(Session::shared_ptr&);
835
1047
 
836
1048
  /*
841
1053
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
842
1054
  void exit_cond(const char* old_msg);
843
1055
 
844
 
  uint64_t found_rows() const
 
1056
  type::Time::epoch_t query_start()
 
1057
  {
 
1058
    return getCurrentTimestampEpoch();
 
1059
  }
 
1060
 
 
1061
  void set_time()
 
1062
  {
 
1063
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
 
1064
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
 
1065
  }
 
1066
 
 
1067
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
 
1068
  {
 
1069
    _user_time= boost::posix_time::from_time_t(t);
 
1070
  }
 
1071
 
 
1072
  void set_time_after_lock()
 
1073
  { 
 
1074
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
 
1075
    utime_after_lock= (mytime - _epoch).total_microseconds();
 
1076
  }
 
1077
 
 
1078
  void set_end_timer()
 
1079
  {
 
1080
    _end_timer= boost::posix_time::microsec_clock::universal_time();
 
1081
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
 
1082
  }
 
1083
 
 
1084
  uint64_t getElapsedTime() const
 
1085
  {
 
1086
    return (_end_timer - _start_timer).total_microseconds();
 
1087
  }
 
1088
 
 
1089
  /**
 
1090
   * Returns the current micro-timestamp
 
1091
   */
 
1092
  type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
 
1093
  { 
 
1094
    type::Time::epoch_t t_mark;
 
1095
 
 
1096
    if (actual)
 
1097
    {
 
1098
      boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
 
1099
      t_mark= (mytime - _epoch).total_microseconds();
 
1100
    }
 
1101
    else
 
1102
    {
 
1103
      t_mark= (_end_timer - _epoch).total_microseconds();
 
1104
    }
 
1105
 
 
1106
    return t_mark; 
 
1107
  }
 
1108
 
 
1109
  // We may need to set user on this
 
1110
  type::Time::epoch_t getCurrentTimestampEpoch() const
 
1111
  { 
 
1112
    if (not _user_time.is_not_a_date_time())
 
1113
      return (_user_time - _epoch).total_seconds();
 
1114
 
 
1115
    return (_start_timer - _epoch).total_seconds();
 
1116
  }
 
1117
 
 
1118
  type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
 
1119
  { 
 
1120
    if (not _user_time.is_not_a_date_time())
 
1121
    {
 
1122
      fraction_arg= 0;
 
1123
      return (_user_time - _epoch).total_seconds();
 
1124
    }
 
1125
 
 
1126
    fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
 
1127
    return (_start_timer - _epoch).total_seconds();
 
1128
  }
 
1129
 
 
1130
  uint64_t found_rows(void) const
845
1131
  {
846
1132
    return limit_found_rows;
847
1133
  }
862
1148
 
863
1149
  int send_explain_fields(select_result *result);
864
1150
 
865
 
  void clear_error(bool full= false);
866
 
  void clearDiagnostics();
867
 
  bool is_error() const;
868
 
 
869
 
  static const charset_info_st *charset() { return default_charset_info; }
870
 
 
 
1151
  /**
 
1152
    Clear the current error, if any.
 
1153
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
 
1154
    assume this is never called if the fatal error is set.
 
1155
    @todo: To silence an error, one should use Internal_error_handler
 
1156
    mechanism. In future this function will be removed.
 
1157
  */
 
1158
  inline void clear_error(bool full= false)
 
1159
  {
 
1160
    if (main_da.is_error())
 
1161
      main_da.reset_diagnostics_area();
 
1162
 
 
1163
    if (full)
 
1164
    {
 
1165
      drizzle_reset_errors(this, true);
 
1166
    }
 
1167
  }
 
1168
 
 
1169
  void clearDiagnostics()
 
1170
  {
 
1171
    main_da.reset_diagnostics_area();
 
1172
  }
 
1173
 
 
1174
  /**
 
1175
    Mark the current error as fatal. Warning: this does not
 
1176
    set any error, it sets a property of the error, so must be
 
1177
    followed or prefixed with my_error().
 
1178
  */
 
1179
  inline void fatal_error()
 
1180
  {
 
1181
    assert(main_da.is_error());
 
1182
    is_fatal_error= true;
 
1183
  }
 
1184
  /**
 
1185
    true if there is an error in the error stack.
 
1186
 
 
1187
    Please use this method instead of direct access to
 
1188
    net.report_error.
 
1189
 
 
1190
    If true, the current (sub)-statement should be aborted.
 
1191
    The main difference between this member and is_fatal_error
 
1192
    is that a fatal error can not be handled by a stored
 
1193
    procedure continue handler, whereas a normal error can.
 
1194
 
 
1195
    To raise this flag, use my_error().
 
1196
  */
 
1197
  inline bool is_error() const { return main_da.is_error(); }
 
1198
  inline const CHARSET_INFO *charset() { return default_charset_info; }
 
1199
 
 
1200
  void change_item_tree(Item **place, Item *new_value)
 
1201
  {
 
1202
    *place= new_value;
 
1203
  }
871
1204
  /**
872
1205
    Cleanup statement parse state (parse tree, lex) and execution
873
1206
    state after execution of a non-prepared SQL statement.
897
1230
  void setAbort(bool arg);
898
1231
  void lockOnSys();
899
1232
  void set_status_var_init();
 
1233
 
900
1234
  /**
901
1235
    Set the current database; use deep copy of C-string.
902
1236
 
914
1248
    attributes including security context. In the future, this operation
915
1249
    will be made private and more convenient interface will be provided.
916
1250
  */
917
 
  void set_db(const std::string&);
 
1251
  void set_db(const std::string &new_db);
918
1252
 
919
1253
  /*
920
1254
    Copy the current database to the argument. Use the current arena to
924
1258
  bool copy_db_to(char **p_db, size_t *p_db_length);
925
1259
 
926
1260
public:
 
1261
  /**
 
1262
    Add an internal error handler to the thread execution context.
 
1263
    @param handler the exception handler to add
 
1264
  */
 
1265
  void push_internal_handler(Internal_error_handler *handler);
 
1266
 
 
1267
  /**
 
1268
    Handle an error condition.
 
1269
    @param sql_errno the error number
 
1270
    @param level the error level
 
1271
    @return true if the error is handled
 
1272
  */
 
1273
  virtual bool handle_error(drizzled::error_t sql_errno, const char *message,
 
1274
                            DRIZZLE_ERROR::enum_warning_level level);
 
1275
 
 
1276
  /**
 
1277
    Remove the error handler last pushed.
 
1278
  */
 
1279
  void pop_internal_handler();
927
1280
 
928
1281
  /**
929
1282
    Resets Session part responsible for command processing state.
957
1310
   *
958
1311
   * @note Host, user and passwd may point to communication buffer.
959
1312
   * Current implementation does not depend on that, but future changes
960
 
   * should be done with this in mind;
 
1313
   * should be done with this in mind; 
961
1314
   *
962
1315
   * @param passwd Scrambled password received from client
963
1316
   * @param db Database name to connect to, may be NULL
964
1317
   */
965
1318
  bool checkUser(const std::string &passwd, const std::string &db);
 
1319
  
 
1320
  /**
 
1321
   * Returns the timestamp (in microseconds) of when the Session 
 
1322
   * connected to the server.
 
1323
   */
 
1324
  uint64_t getConnectMicroseconds() const
 
1325
  {
 
1326
    return (_connect_time - _epoch).total_microseconds();
 
1327
  }
 
1328
 
 
1329
  uint64_t getConnectSeconds() const
 
1330
  {
 
1331
    return (_connect_time - _epoch).total_seconds();
 
1332
  }
966
1333
 
967
1334
  /**
968
1335
   * Returns a pointer to the active Transaction message for this
982
1349
  {
983
1350
    return statement_message;
984
1351
  }
985
 
 
 
1352
  
986
1353
  /**
987
1354
   * Returns a pointer to the current Resulset message for this
988
1355
   * Session, or NULL if no active message.
1029
1396
   */
1030
1397
 
1031
1398
  void resetResultsetMessage()
1032
 
  {
 
1399
  { 
1033
1400
    resultset= NULL;
1034
1401
  }
1035
1402
 
1036
 
  plugin::EventObserverList *getSessionObservers()
1037
 
  {
 
1403
private:
 
1404
  /** Pointers to memory managed by the ReplicationServices component */
 
1405
  message::Transaction *transaction_message;
 
1406
  message::Statement *statement_message;
 
1407
  /* Pointer to the current resultset of Select query */
 
1408
  message::Resultset *resultset;
 
1409
  plugin::EventObserverList *session_event_observers;
 
1410
  
 
1411
  /* Schema observers are mapped to databases. */
 
1412
  std::map<std::string, plugin::EventObserverList *> schema_event_observers;
 
1413
 
 
1414
 
 
1415
public:
 
1416
  plugin::EventObserverList *getSessionObservers() 
 
1417
  { 
1038
1418
    return session_event_observers;
1039
1419
  }
1040
 
 
1041
 
  void setSessionObservers(plugin::EventObserverList *observers)
1042
 
  {
 
1420
  
 
1421
  void setSessionObservers(plugin::EventObserverList *observers) 
 
1422
  { 
1043
1423
    session_event_observers= observers;
1044
1424
  }
1045
 
 
1046
 
  plugin::EventObserverList* getSchemaObservers(const std::string& schema);
1047
 
  plugin::EventObserverList* setSchemaObservers(const std::string& schema, plugin::EventObserverList*);
 
1425
  
 
1426
  /* For schema event observers there is one set of observers per database. */
 
1427
  plugin::EventObserverList *getSchemaObservers(const std::string &db_name) 
 
1428
  { 
 
1429
    std::map<std::string, plugin::EventObserverList *>::iterator it;
 
1430
    
 
1431
    it= schema_event_observers.find(db_name);
 
1432
    if (it == schema_event_observers.end())
 
1433
      return NULL;
 
1434
      
 
1435
    return it->second;
 
1436
  }
 
1437
  
 
1438
  void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers) 
 
1439
  { 
 
1440
    std::map<std::string, plugin::EventObserverList *>::iterator it;
 
1441
 
 
1442
    it= schema_event_observers.find(db_name);
 
1443
    if (it != schema_event_observers.end())
 
1444
      schema_event_observers.erase(it);;
 
1445
 
 
1446
    if (observers)
 
1447
      schema_event_observers[db_name] = observers;
 
1448
  }
 
1449
  
 
1450
  
 
1451
 private:
 
1452
  const char *proc_info;
 
1453
 
 
1454
  /** The current internal error handler for this thread, or NULL. */
 
1455
  Internal_error_handler *m_internal_handler;
 
1456
  /**
 
1457
    The lex to hold the parsed tree of conventional (non-prepared) queries.
 
1458
    Whereas for prepared and stored procedure statements we use an own lex
 
1459
    instance for each new query, for conventional statements we reuse
 
1460
    the same lex. (@see mysql_parse for details).
 
1461
  */
 
1462
  LEX main_lex;
 
1463
  /**
 
1464
    This memory root is used for two purposes:
 
1465
    - for conventional queries, to allocate structures stored in main_lex
 
1466
    during parsing, and allocate runtime data (execution plan, etc.)
 
1467
    during execution.
 
1468
    - for prepared queries, only to allocate runtime data. The parsed
 
1469
    tree itself is reused between executions and thus is stored elsewhere.
 
1470
  */
 
1471
  memory::Root main_mem_root;
 
1472
 
 
1473
  /**
 
1474
   * Marks all tables in the list which were used by current substatement
 
1475
   * as free for reuse.
 
1476
   *
 
1477
   * @param Head of the list of tables
 
1478
   *
 
1479
   * @note
 
1480
   *
 
1481
   * The reason we reset query_id is that it's not enough to just test
 
1482
   * if table->query_id != session->query_id to know if a table is in use.
 
1483
   *
 
1484
   * For example
 
1485
   * 
 
1486
   *  SELECT f1_that_uses_t1() FROM t1;
 
1487
   *  
 
1488
   * In f1_that_uses_t1() we will see one instance of t1 where query_id is
 
1489
   * set to query_id of original query.
 
1490
   */
 
1491
  void mark_used_tables_as_free_for_reuse(Table *table);
1048
1492
 
1049
1493
public:
1050
 
  void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0, uint64_t passed_id= 0, const char *message= NULL);
1051
 
  void my_eof();
1052
 
  bool add_item_to_list(Item *item);
1053
 
  bool add_value_to_list(Item *value);
1054
 
  bool add_order_to_list(Item *item, bool asc);
1055
 
  bool add_group_to_list(Item *item, bool asc);
1056
 
 
 
1494
 
 
1495
  /** A short cut for session->main_da.set_ok_status(). */
 
1496
  inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
 
1497
                    uint64_t passed_id= 0, const char *message= NULL)
 
1498
  {
 
1499
    main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
 
1500
  }
 
1501
 
 
1502
 
 
1503
  /** A short cut for session->main_da.set_eof_status(). */
 
1504
 
 
1505
  inline void my_eof()
 
1506
  {
 
1507
    main_da.set_eof_status(this);
 
1508
  }
 
1509
 
 
1510
  /* Some inline functions for more speed */
 
1511
 
 
1512
  inline bool add_item_to_list(Item *item)
 
1513
  {
 
1514
    return lex->current_select->add_item_to_list(this, item);
 
1515
  }
 
1516
 
 
1517
  inline bool add_value_to_list(Item *value)
 
1518
  {
 
1519
    return lex->value_list.push_back(value);
 
1520
  }
 
1521
 
 
1522
  inline bool add_order_to_list(Item *item, bool asc)
 
1523
  {
 
1524
    return lex->current_select->add_order_to_list(this, item, asc);
 
1525
  }
 
1526
 
 
1527
  inline bool add_group_to_list(Item *item, bool asc)
 
1528
  {
 
1529
    return lex->current_select->add_group_to_list(this, item, asc);
 
1530
  }
1057
1531
  void refresh_status();
1058
1532
  user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1059
1533
  user_var_entry *getVariable(const std::string  &name, bool create_if_not_exists);
1060
1534
  void setVariable(const std::string &name, const std::string &value);
1061
 
 
 
1535
  
1062
1536
  /**
1063
1537
   * Closes all tables used by the current substatement, or all tables
1064
1538
   * used by this thread if we are on the upper level.
1066
1540
  void close_thread_tables();
1067
1541
  void close_old_data_files(bool morph_locks= false,
1068
1542
                            bool send_refresh= false);
 
1543
  void close_open_tables();
1069
1544
  void close_data_files_and_morph_locks(const identifier::Table &identifier);
1070
1545
 
 
1546
private:
 
1547
  bool free_cached_table(boost::mutex::scoped_lock &scopedLock);
 
1548
 
 
1549
public:
 
1550
 
1071
1551
  /**
1072
1552
   * Prepares statement for reopening of tables and recalculation of set of
1073
1553
   * prelocked tables.
1088
1568
   *  true  - error
1089
1569
   *
1090
1570
   * @note
1091
 
   *
 
1571
   * 
1092
1572
   * The lock will automaticaly be freed by close_thread_tables()
1093
1573
   */
1094
 
  bool openTablesLock(TableList*);
1095
 
  Table *open_temporary_table(const identifier::Table &identifier, bool link_in_list= true);
 
1574
  bool openTablesLock(TableList *tables);
1096
1575
 
1097
1576
  int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1098
1577
 
1104
1583
  void close_cached_table(Table *table);
1105
1584
 
1106
1585
  /* Create a lock in the cache */
1107
 
  table::Placeholder& table_cache_insert_placeholder(const identifier::Table&);
1108
 
  Table* lock_table_name_if_not_cached(const identifier::Table&);
1109
 
 
1110
 
  session::TableMessages &getMessageCache();
 
1586
  table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
 
1587
  bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
 
1588
 
 
1589
private:
 
1590
  session::TableMessages _table_message_cache;
 
1591
 
 
1592
public:
 
1593
  session::TableMessages &getMessageCache()
 
1594
  {
 
1595
    return _table_message_cache;
 
1596
  }
1111
1597
 
1112
1598
  /* Reopen operations */
1113
1599
  bool reopen_tables();
1117
1603
  int setup_conds(TableList *leaves, COND **conds);
1118
1604
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1119
1605
 
1120
 
  template <class T>
1121
 
  T* getProperty(const std::string& name)
 
1606
  drizzled::util::Storable *getProperty(const std::string &arg)
1122
1607
  {
1123
 
    return static_cast<T*>(getProperty0(name));
 
1608
    return life_properties.getProperty(arg);
1124
1609
  }
1125
1610
 
1126
 
  template <class T>
1127
 
  T setProperty(const std::string& name, T value)
 
1611
  template<class T>
 
1612
  bool setProperty(const std::string &arg, T *value)
1128
1613
  {
1129
 
    setProperty0(name, value);
1130
 
    return value;
 
1614
    life_properties.setProperty(arg, value);
 
1615
 
 
1616
    return true;
1131
1617
  }
1132
1618
 
1133
1619
  /**
1138
1624
    @return
1139
1625
    pointer to plugin::StorageEngine
1140
1626
  */
1141
 
  plugin::StorageEngine *getDefaultStorageEngine();
1142
 
  void get_xid(DrizzleXid *xid); // Innodb only
1143
 
 
1144
 
  table::Singular& getInstanceTable();
1145
 
  table::Singular& getInstanceTable(std::list<CreateField>&);
 
1627
  plugin::StorageEngine *getDefaultStorageEngine()
 
1628
  {
 
1629
    if (variables.storage_engine)
 
1630
      return variables.storage_engine;
 
1631
    return global_system_variables.storage_engine;
 
1632
  }
 
1633
 
 
1634
  void get_xid(DRIZZLE_XID *xid); // Innodb only
 
1635
 
 
1636
  table::Singular *getInstanceTable();
 
1637
  table::Singular *getInstanceTable(List<CreateField> &field_list);
 
1638
 
 
1639
private:
 
1640
  bool resetUsage()
 
1641
  {
 
1642
    if (getrusage(RUSAGE_THREAD, &usage))
 
1643
    {
 
1644
      return false;
 
1645
    }
 
1646
 
 
1647
    return true;
 
1648
  }
 
1649
 
 
1650
public:
1146
1651
 
1147
1652
  void setUsage(bool arg)
1148
1653
  {
1149
1654
    use_usage= arg;
1150
1655
  }
1151
1656
 
1152
 
  const rusage &getUsage()
 
1657
  const struct rusage &getUsage()
1153
1658
  {
1154
1659
    return usage;
1155
1660
  }
1156
1661
 
1157
 
  const catalog::Instance& catalog() const
1158
 
  {
1159
 
    return *_catalog;
1160
 
  }
1161
 
 
1162
 
  catalog::Instance& catalog()
1163
 
  {
1164
 
    return *_catalog;
1165
 
  }
1166
 
 
1167
 
  bool arg_of_last_insert_id_function; // Tells if LAST_INSERT_ID(#) was called for the current statement
 
1662
  catalog::Instance::const_reference catalog() const
 
1663
  {
 
1664
    return *(_catalog.get());
 
1665
  }
 
1666
 
 
1667
  catalog::Instance::reference catalog()
 
1668
  {
 
1669
    return *(_catalog.get());
 
1670
  }
 
1671
 
1168
1672
private:
1169
 
  drizzled::util::Storable* getProperty0(const std::string&);
1170
 
  void setProperty0(const std::string&, drizzled::util::Storable*);
1171
 
 
1172
 
  bool resetUsage()
1173
 
  {
1174
 
    return not getrusage(RUSAGE_THREAD, &usage);
1175
 
  }
1176
 
 
1177
 
  boost::shared_ptr<catalog::Instance> _catalog;
1178
 
 
1179
 
  /** Pointers to memory managed by the ReplicationServices component */
1180
 
  message::Transaction *transaction_message;
1181
 
  message::Statement *statement_message;
1182
 
  /* Pointer to the current resultset of Select query */
1183
 
  message::Resultset *resultset;
1184
 
  plugin::EventObserverList *session_event_observers;
1185
 
 
1186
 
  uint64_t xa_id;
1187
 
  const char *proc_info;
1188
 
  bool abort_on_warning;
1189
 
  bool concurrent_execute_allowed;
1190
 
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
 
1673
  catalog::Instance::shared_ptr _catalog;
 
1674
 
 
1675
  // This lives throughout the life of Session
1191
1676
  bool use_usage;
1192
 
  rusage usage;
1193
 
  identifier::user::mptr security_ctx;
1194
 
  int32_t scoreboard_index;
1195
 
  bool originating_server_uuid_set;
1196
 
  std::string originating_server_uuid;
1197
 
  uint64_t originating_commit_id;
1198
 
  plugin::Client *client;
 
1677
  session::PropertyMap life_properties;
 
1678
  std::vector<table::Singular *> temporary_shares;
 
1679
  struct rusage usage;
1199
1680
};
1200
1681
 
 
1682
class Join;
 
1683
 
1201
1684
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1202
1685
 
 
1686
} /* namespace drizzled */
 
1687
 
 
1688
/** @TODO why is this in the middle of the file */
 
1689
#include <drizzled/select_to_file.h>
 
1690
#include <drizzled/select_export.h>
 
1691
#include <drizzled/select_dump.h>
 
1692
#include <drizzled/select_insert.h>
 
1693
#include <drizzled/select_create.h>
 
1694
#include <drizzled/tmp_table_param.h>
 
1695
#include <drizzled/select_union.h>
 
1696
#include <drizzled/select_subselect.h>
 
1697
#include <drizzled/select_singlerow_subselect.h>
 
1698
#include <drizzled/select_max_min_finder_subselect.h>
 
1699
#include <drizzled/select_exists_subselect.h>
 
1700
 
 
1701
namespace drizzled
 
1702
{
 
1703
 
 
1704
/**
 
1705
 * A structure used to describe sort information
 
1706
 * for a field or item used in ORDER BY.
 
1707
 */
 
1708
class SortField 
 
1709
{
 
1710
public:
 
1711
  Field *field; /**< Field to sort */
 
1712
  Item  *item; /**< Item if not sorting fields */
 
1713
  size_t length; /**< Length of sort field */
 
1714
  uint32_t suffix_length; /**< Length suffix (0-4) */
 
1715
  Item_result result_type; /**< Type of item */
 
1716
  bool reverse; /**< if descending sort */
 
1717
  bool need_strxnfrm;   /**< If we have to use strxnfrm() */
 
1718
 
 
1719
  SortField() :
 
1720
    field(0),
 
1721
    item(0),
 
1722
    length(0),
 
1723
    suffix_length(0),
 
1724
    result_type(STRING_RESULT),
 
1725
    reverse(0),
 
1726
    need_strxnfrm(0)
 
1727
  { }
 
1728
 
 
1729
};
 
1730
 
 
1731
} /* namespace drizzled */
 
1732
 
 
1733
/** @TODO why is this in the middle of the file */
 
1734
 
 
1735
#include <drizzled/table_ident.h>
 
1736
#include <drizzled/user_var_entry.h>
 
1737
#include <drizzled/unique.h>
 
1738
#include <drizzled/var.h>
 
1739
#include <drizzled/select_dumpvar.h>
 
1740
 
 
1741
namespace drizzled
 
1742
{
 
1743
 
1203
1744
/* Bits in sql_command_flags */
1204
1745
 
1205
 
enum sql_command_flag_bits
 
1746
enum sql_command_flag_bits 
1206
1747
{
1207
1748
  CF_BIT_CHANGES_DATA,
1208
1749
  CF_BIT_HAS_ROW_COUNT,
1218
1759
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1219
1760
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1220
1761
 
1221
 
namespace display  
1222
 
{
1223
 
  const std::string &type(Session::global_read_lock_t);
1224
 
  size_t max_string_length(Session::global_read_lock_t);
 
1762
namespace display  {
 
1763
const std::string &type(drizzled::Session::global_read_lock_t type);
 
1764
size_t max_string_length(drizzled::Session::global_read_lock_t type);
 
1765
 
1225
1766
} /* namespace display */
1226
1767
 
1227
1768
} /* namespace drizzled */
1228
1769
 
 
1770
#endif /* DRIZZLED_SESSION_H */