~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
/* Classes in mysql */
25
25
 
26
 
#include "drizzled/plugin.h"
 
26
#include "drizzled/sql_plugin.h"
 
27
#include <drizzled/plugin/protocol.h>
 
28
#include <drizzled/plugin/scheduler.h>
27
29
#include <drizzled/sql_locale.h>
28
 
#include "drizzled/resource_context.h"
29
 
#include <drizzled/cursor.h>
 
30
#include <drizzled/ha_trx_info.h>
 
31
#include <mysys/my_alloc.h>
 
32
#include <mysys/my_tree.h>
 
33
#include <drizzled/handler.h>
30
34
#include <drizzled/current_session.h>
31
35
#include <drizzled/sql_error.h>
32
36
#include <drizzled/file_exchange.h>
33
37
#include <drizzled/select_result_interceptor.h>
 
38
#include <drizzled/authentication.h>
 
39
#include <drizzled/db.h>
34
40
#include <drizzled/xid.h>
35
 
#include "drizzled/query_id.h"
36
 
#include "drizzled/named_savepoint.h"
37
 
#include "drizzled/transaction_context.h"
38
41
 
39
42
#include <netdb.h>
40
 
#include <map>
41
43
#include <string>
42
44
#include <bitset>
43
 
#include <deque>
44
 
 
45
 
#include <drizzled/security_context.h>
46
 
#include <drizzled/open_tables_state.h>
47
 
 
48
 
#include <drizzled/internal_error_handler.h>
49
 
#include <drizzled/diagnostics_area.h>
50
 
 
51
 
#include <drizzled/plugin/authorization.h>
52
45
 
53
46
#define MIN_HANDSHAKE_SIZE      6
54
47
 
55
 
namespace drizzled
56
 
{
57
 
 
58
 
namespace plugin
59
 
{
60
 
class Client;
61
 
class Scheduler;
62
 
}
63
 
namespace message
64
 
{
65
 
class Transaction;
66
 
class Statement;
67
 
}
68
 
namespace internal
69
 
{
70
 
struct st_my_thread_var;
71
 
}
72
 
 
73
48
class Lex_input_stream;
74
49
class user_var_entry;
75
50
class CopyField;
84
59
extern uint32_t tc_heuristic_recover;
85
60
 
86
61
/**
87
 
  @brief
88
 
  Local storage for proto that are tmp table. This should be enlarged
89
 
  to hande the entire table-share for a local table. Once Hash is done,
90
 
  we should consider exchanging the map for it.
91
 
*/
92
 
typedef std::map <std::string, message::Table> ProtoCache;
93
 
 
94
 
/**
95
62
  The COPY_INFO structure is used by INSERT/REPLACE code.
96
63
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
97
64
  UPDATE code:
128
95
  THR_LOCK_DATA **locks;
129
96
} DRIZZLE_LOCK;
130
97
 
131
 
} /* namespace drizzled */
132
 
 
133
 
/** @TODO why is this in the middle of the file */
134
98
#include <drizzled/lex_column.h>
135
99
 
136
 
namespace drizzled
137
 
{
138
 
 
139
100
class select_result;
140
101
class Time_zone;
141
102
 
142
103
#define Session_SENTRY_MAGIC 0xfeedd1ff
143
104
#define Session_SENTRY_GONE  0xdeadbeef
144
105
 
 
106
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
 
107
 
145
108
struct system_variables
146
109
{
147
110
  system_variables() {};
173
136
  uint64_t max_length_for_sort_data;
174
137
  size_t max_sort_length;
175
138
  uint64_t min_examined_row_limit;
 
139
  uint32_t net_buffer_length;
176
140
  bool optimizer_prune_level;
177
141
  bool log_warnings;
178
142
 
179
143
  uint32_t optimizer_search_depth;
 
144
  /* A bitmap for switching optimizations on/off */
 
145
  uint32_t optimizer_switch;
180
146
  uint32_t div_precincrement;
181
147
  uint64_t preload_buff_size;
182
148
  uint32_t read_buff_size;
191
157
  size_t range_alloc_block_size;
192
158
  uint32_t query_alloc_block_size;
193
159
  uint32_t query_prealloc_size;
 
160
  uint32_t trans_alloc_block_size;
 
161
  uint32_t trans_prealloc_size;
194
162
  uint64_t group_concat_max_len;
 
163
  /* TODO: change this to my_thread_id - but have to fix set_var first */
195
164
  uint64_t pseudo_thread_id;
196
165
 
197
 
  plugin::StorageEngine *storage_engine;
 
166
  StorageEngine *storage_engine;
198
167
 
199
168
  /* Only charset part of these variables is sensible */
200
169
  const CHARSET_INFO  *character_set_filesystem;
215
184
 
216
185
extern struct system_variables global_system_variables;
217
186
 
218
 
} /* namespace drizzled */
219
 
 
220
 
#include "drizzled/sql_lex.h"
221
 
 
222
 
namespace drizzled
223
 
{
 
187
#include "sql_lex.h"
224
188
 
225
189
/**
226
190
 * Per-session local status counters
259
223
  /* END OF KEY_CACHE parts */
260
224
 
261
225
  ulong net_big_packet_count;
 
226
  ulong opened_tables;
 
227
  ulong opened_shares;
262
228
  ulong select_full_join_count;
263
229
  ulong select_full_range_join_count;
264
230
  ulong select_range_count;
282
248
    sense to add to the /global/ status variable counter.
283
249
  */
284
250
  double last_query_cost;
285
 
} system_status_var;
 
251
} STATUS_VAR;
286
252
 
287
253
/*
288
254
  This is used for 'SHOW STATUS'. It must be updated to the last ulong
294
260
 
295
261
void mark_transaction_to_rollback(Session *session, bool all);
296
262
 
 
263
struct st_savepoint 
 
264
{
 
265
  struct st_savepoint *prev;
 
266
  char *name;
 
267
  uint32_t length;
 
268
  Ha_trx_info *ha_list;
 
269
};
 
270
 
297
271
extern pthread_mutex_t LOCK_xid_cache;
298
272
extern HASH xid_cache;
299
273
 
 
274
#include <drizzled/security_context.h>
 
275
#include <drizzled/open_tables_state.h>
 
276
 
 
277
#include <drizzled/internal_error_handler.h> 
 
278
#include <drizzled/diagnostics_area.h> 
300
279
 
301
280
/**
302
281
  Storage engine specific thread local data.
309
288
  */
310
289
  void *ha_ptr;
311
290
  /**
312
 
   * Resource contexts for both the "statement" and "normal"
313
 
   * transactions.
314
 
   *
315
 
   * Resource context at index 0:
316
 
   *
317
 
   * Life time: one statement within a transaction. If @@autocommit is
318
 
   * on, also represents the entire transaction.
319
 
   *
320
 
   * Resource context at index 1:
321
 
   *
322
 
   * Life time: one transaction within a connection. 
323
 
   *
324
 
   * @note
325
 
   *
326
 
   * If the storage engine does not participate in a transaction, 
327
 
   * there will not be a resource context.
328
 
   */
329
 
  drizzled::ResourceContext resource_context[2];
 
291
    0: Life time: one statement within a transaction. If @@autocommit is
 
292
    on, also represents the entire transaction.
 
293
    @sa trans_register_ha()
 
294
 
 
295
    1: Life time: one transaction within a connection.
 
296
    If the storage engine does not participate in a transaction,
 
297
    this should not be used.
 
298
    @sa trans_register_ha()
 
299
  */
 
300
  Ha_trx_info ha_info[2];
330
301
 
331
302
  Ha_data() :ha_ptr(NULL) {}
332
303
};
402
373
   * itself to the list on creation (see Item::Item() for details))
403
374
   */
404
375
  Item *free_list;
405
 
  memory::Root *mem_root; /**< Pointer to current memroot */
 
376
  MEM_ROOT *mem_root; /**< Pointer to current memroot */
406
377
  /**
407
378
   * Uniquely identifies each statement object in thread scope; change during
408
379
   * statement lifetime.
411
382
   */
412
383
  uint32_t id;
413
384
  LEX *lex; /**< parse tree descriptor */
414
 
  /** query associated with this statement */
415
 
  std::string query;
 
385
  /**
 
386
    Points to the query associated with this statement. It's const, but
 
387
    we need to declare it char * because all table handlers are written
 
388
    in C and need to point to it.
 
389
 
 
390
    Note that (A) if we set query = NULL, we must at the same time set
 
391
    query_length = 0, and protect the whole operation with the
 
392
    LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
 
393
    non-NULL value if its previous value is NULL. We do not need to protect
 
394
    operation (B) with any mutex. To avoid crashes in races, if we do not
 
395
    know that session->query cannot change at the moment, one should print
 
396
    session->query like this:
 
397
      (1) reserve the LOCK_thread_count mutex;
 
398
      (2) check if session->query is NULL;
 
399
      (3) if not NULL, then print at most session->query_length characters from
 
400
      it. We will see the query_length field as either 0, or the right value
 
401
      for it.
 
402
    Assuming that the write and read of an n-bit memory field in an n-bit
 
403
    computer is atomic, we can avoid races in the above way.
 
404
    This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
 
405
    STATUS.
 
406
  */
 
407
  char *query;
 
408
  uint32_t query_length; /**< current query length */
416
409
 
417
410
  /**
418
411
    Name of the current (default) database.
426
419
    the Session of that thread); that thread is (and must remain, for now) the
427
420
    only responsible for freeing this member.
428
421
  */
429
 
  std::string db;
 
422
  char *db;
 
423
  uint32_t db_length; /**< Length of current schema name */
430
424
 
431
425
  /**
432
426
    Constant for Session::where initialization in the beginning of every query.
436
430
  */
437
431
  static const char * const DEFAULT_WHERE;
438
432
 
439
 
  memory::Root warn_root; /**< Allocation area for warnings and errors */
440
 
  plugin::Client *client; /**< Pointer to client object */
441
 
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
 
433
  MEM_ROOT warn_root; /**< Allocation area for warnings and errors */
 
434
  drizzled::plugin::Protocol *protocol; /**< Pointer to protocol object */
 
435
  drizzled::plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
442
436
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
443
437
  HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
 
438
  String packet; /**< dynamic buffer for network I/O */
 
439
  String convert_buffer; /**< A buffer for charset conversions */
444
440
  struct system_variables variables; /**< Mutable local variables local to the session */
445
441
  struct system_status_var status_var; /**< Session-local status counters */
446
442
  struct system_status_var *initial_status_var; /* used by show status */
461
457
   */
462
458
  char *thread_stack;
463
459
 
464
 
private:
465
 
  SecurityContext security_ctx;
466
 
 
467
 
  inline void checkSentry() const
468
 
  {
469
 
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
470
 
  }
471
 
public:
472
 
  const SecurityContext& getSecurityContext() const
473
 
  {
474
 
    return security_ctx;
475
 
  }
476
 
 
477
 
  SecurityContext& getSecurityContext()
478
 
  {
479
 
    return security_ctx;
480
 
  }
481
 
 
482
460
  /**
483
 
   * Is this session viewable by the current user?
484
 
   */
485
 
  bool isViewable() const
486
 
  {
487
 
    return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
488
 
                                               this,
489
 
                                               false);
490
 
  }
 
461
    @note
 
462
    Some members of Session (currently 'Statement::db',
 
463
    'query')  are set and alloced by the slave SQL thread
 
464
    (for the Session of that thread); that thread is (and must remain, for now)
 
465
    the only responsible for freeing these 3 members. If you add members
 
466
    here, and you add code to set them in replication, don't forget to
 
467
    free_them_and_set_them_to_0 in replication properly. For details see
 
468
    the 'err:' label of the handle_slave_sql() in sql/slave.cc.
 
469
 
 
470
    @see handle_slave_sql
 
471
  */
 
472
  Security_context security_ctx;
491
473
 
492
474
  /**
493
475
    Used in error messages to tell user in what part of MySQL we found an
502
484
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
503
485
  */
504
486
  uint32_t dbug_sentry; /**< watch for memory corruption */
505
 
  internal::st_my_thread_var *mysys_var;
 
487
  struct st_my_thread_var *mysys_var;
506
488
  /**
507
489
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
508
490
   * first byte of the packet in executeStatement()
509
491
   */
510
492
  enum enum_server_command command;
511
493
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
512
 
  /* @note the following three members should likely move to Client */
 
494
  /* @note the following three members should likely move to Protocol */
 
495
  uint16_t peer_port; /**< The remote (peer) port */
513
496
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
514
497
  time_t start_time;
515
498
  time_t user_time;
523
506
    Both of the following container points in session will be converted to an API.
524
507
  */
525
508
 
526
 
private:
527
509
  /* container for handler's private per-connection data */
528
 
  std::vector<Ha_data> ha_data;
529
 
  /*
530
 
    Id of current query. Statement can be reused to execute several queries
531
 
    query_id is global in context of the whole MySQL server.
532
 
    ID is automatically generated from an atomic counter.
533
 
    It's used in Cursor code for various purposes: to check which columns
534
 
    from table are necessary for this select, to check if it's necessary to
535
 
    update auto-updatable fields (like auto_increment and timestamp).
536
 
  */
537
 
  query_id_t query_id;
538
 
  query_id_t warn_query_id;
539
 
public:
540
 
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
541
 
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
542
 
                                      size_t index= 0);
 
510
  Ha_data ha_data[MAX_HA];
 
511
 
 
512
  /* container for replication data */
 
513
  void *replication_data;
543
514
 
544
515
  struct st_transactions {
545
 
    std::deque<NamedSavepoint> savepoints;
546
 
    TransactionContext all; ///< Trans since BEGIN WORK
547
 
    TransactionContext stmt; ///< Trans for current statement
 
516
    SAVEPOINT *savepoints;
 
517
    Session_TRANS all;                  // Trans since BEGIN WORK
 
518
    Session_TRANS stmt;                 // Trans for current statement
 
519
    bool on;                            // see ha_enable_transaction()
548
520
    XID_STATE xid_state;
549
521
 
 
522
    /*
 
523
       Tables changed in transaction (that must be invalidated in query cache).
 
524
       List contain only transactional tables, that not invalidated in query
 
525
       cache (instead of full list of changed in transaction tables).
 
526
    */
 
527
    CHANGED_TableList* changed_tables;
 
528
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
550
529
    void cleanup()
551
530
    {
552
 
      savepoints.clear();
553
 
    }
554
 
    st_transactions() :
555
 
      savepoints(),
556
 
      all(),
557
 
      stmt(),
558
 
      xid_state()
559
 
    { }
 
531
      changed_tables= 0;
 
532
      savepoints= 0;
 
533
      free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
 
534
    }
 
535
    st_transactions()
 
536
    {
 
537
      memset(this, 0, sizeof(*this));
 
538
      xid_state.xid.null();
 
539
      init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
 
540
    }
560
541
  } transaction;
561
 
 
562
542
  Field *dup_field;
563
543
  sigset_t signals;
564
544
 
654
634
  uint32_t total_warn_count;
655
635
  Diagnostics_area main_da;
656
636
 
 
637
  /*
 
638
    Id of current query. Statement can be reused to execute several queries
 
639
    query_id is global in context of the whole MySQL server.
 
640
    ID is automatically generated from mutex-protected counter.
 
641
    It's used in handler code for various purposes: to check which columns
 
642
    from table are necessary for this select, to check if it's necessary to
 
643
    update auto-updatable fields (like auto_increment and timestamp).
 
644
  */
 
645
  query_id_t query_id;
 
646
  query_id_t warn_id;
657
647
  ulong col_access;
658
648
 
 
649
#ifdef ERROR_INJECT_SUPPORT
 
650
  ulong error_inject_value;
 
651
#endif
659
652
  /* Statement id is thread-wide. This counter is used to generate ids */
660
653
  uint32_t statement_id_counter;
661
654
  uint32_t rand_saved_seed1;
666
659
  */
667
660
  uint32_t row_count;
668
661
  pthread_t real_id; /**< For debugging */
669
 
  uint64_t thread_id;
 
662
  my_thread_id thread_id;
670
663
  uint32_t tmp_table;
671
664
  uint32_t global_read_lock;
672
665
  uint32_t server_status;
746
739
  
747
740
  /** Place to store various things */
748
741
  void *session_marker;
749
 
 
750
742
  /** Keeps a copy of the previous table around in case we are just slamming on particular table */
751
743
  Table *cached_table;
752
744
 
767
759
    return proc_info;
768
760
  }
769
761
 
770
 
  /** Sets this Session's current query ID */
771
 
  inline void setQueryId(query_id_t in_query_id)
772
 
  {
773
 
    query_id= in_query_id;
 
762
  inline void setReplicationData (void *data)
 
763
  {
 
764
    replication_data= data;
 
765
  }
 
766
  inline void *getReplicationData () const
 
767
  {
 
768
    return replication_data;
774
769
  }
775
770
 
776
771
  /** Returns the current query ID */
779
774
    return query_id;
780
775
  }
781
776
 
782
 
 
783
 
  /** Sets this Session's warning query ID */
784
 
  inline void setWarningQueryId(query_id_t in_query_id)
785
 
  {
786
 
    warn_query_id= in_query_id;
787
 
  }
788
 
 
789
 
  /** Returns the Session's warning query ID */
790
 
  inline query_id_t getWarningQueryId()  const
791
 
  {
792
 
    return warn_query_id;
793
 
  }
794
 
 
795
777
  /** Returns the current query text */
796
 
  inline const std::string &getQueryString()  const
 
778
  inline const char *getQueryString()  const
797
779
  {
798
780
    return query;
799
781
  }
801
783
  /** Returns the length of the current query text */
802
784
  inline size_t getQueryLength() const
803
785
  {
804
 
    if (! query.empty())
805
 
      return query.length();
806
 
    else
807
 
      return 0;
808
 
  }
809
 
 
810
 
  /** Accessor method returning the session's ID. */
811
 
  inline uint64_t getSessionId()  const
812
 
  {
813
 
    return thread_id;
 
786
    return strlen(query);
814
787
  }
815
788
 
816
789
  /** Accessor method returning the server's ID. */
881
854
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
882
855
  }
883
856
 
884
 
  Session(plugin::Client *client_arg);
 
857
  Session(drizzled::plugin::Protocol *protocol_arg);
885
858
  virtual ~Session();
886
859
 
887
860
  void cleanup(void);
963
936
   */
964
937
  bool endTransaction(enum enum_mysql_completiontype completion);
965
938
  bool endActiveTransaction();
966
 
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
 
939
  bool startTransaction();
967
940
 
968
941
  /**
969
942
   * Authenticates users, with error reporting.
989
962
    enter_cond(); this mutex is then released by exit_cond().
990
963
    Usage must be: lock mutex; enter_cond(); your code; exit_cond().
991
964
  */
992
 
  const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg);
993
 
  void exit_cond(const char* old_msg);
994
 
 
 
965
  inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
 
966
  {
 
967
    const char* old_msg = get_proc_info();
 
968
    safe_mutex_assert_owner(mutex);
 
969
    mysys_var->current_mutex = mutex;
 
970
    mysys_var->current_cond = cond;
 
971
    this->set_proc_info(msg);
 
972
    return old_msg;
 
973
  }
 
974
  inline void exit_cond(const char* old_msg)
 
975
  {
 
976
    /*
 
977
      Putting the mutex unlock in exit_cond() ensures that
 
978
      mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
 
979
      locked (if that would not be the case, you'll get a deadlock if someone
 
980
      does a Session::awake() on you).
 
981
    */
 
982
    pthread_mutex_unlock(mysys_var->current_mutex);
 
983
    pthread_mutex_lock(&mysys_var->mutex);
 
984
    mysys_var->current_mutex = 0;
 
985
    mysys_var->current_cond = 0;
 
986
    this->set_proc_info(old_msg);
 
987
    pthread_mutex_unlock(&mysys_var->mutex);
 
988
  }
995
989
  inline time_t query_start() { return start_time; }
996
990
  inline void set_time()
997
991
  {
1030
1024
  {
1031
1025
    return !lex->only_view_structure();
1032
1026
  }
 
1027
  inline void* trans_alloc(unsigned int size)
 
1028
  {
 
1029
    return alloc_root(&transaction.mem_root,size);
 
1030
  }
1033
1031
 
1034
1032
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1035
1033
                              const char* str, uint32_t length,
1036
1034
                              bool allocate_lex_string);
1037
 
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1038
 
                              const std::string &str,
1039
 
                              bool allocate_lex_string);
1040
1035
 
 
1036
  void add_changed_table(Table *table);
 
1037
  void add_changed_table(const char *key, long key_length);
 
1038
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1041
1039
  int send_explain_fields(select_result *result);
1042
1040
  /**
1043
1041
    Clear the current error, if any.
1128
1126
      @retval false Success
1129
1127
      @retval true  Out-of-memory error
1130
1128
  */
1131
 
  bool set_db(const std::string &new_db);
1132
 
 
 
1129
  bool set_db(const char *new_db, size_t new_db_len);
 
1130
 
 
1131
  /**
 
1132
    Set the current database; use shallow copy of C-string.
 
1133
 
 
1134
    @param new_db     a pointer to the new database name.
 
1135
    @param new_db_len length of the new database name.
 
1136
 
 
1137
    @note This operation just sets {db, db_length}. Switching the current
 
1138
    database usually involves other actions, like switching other database
 
1139
    attributes including security context. In the future, this operation
 
1140
    will be made private and more convenient interface will be provided.
 
1141
  */
 
1142
  void reset_db(char *new_db, size_t new_db_len)
 
1143
  {
 
1144
    db= new_db;
 
1145
    db_length= new_db_len;
 
1146
  }
1133
1147
  /*
1134
1148
    Copy the current database to the argument. Use the current arena to
1135
1149
    allocate memory for a deep copy: current database may be freed after
1208
1222
    return connect_microseconds;
1209
1223
  }
1210
1224
 
1211
 
  /**
1212
 
   * Returns a pointer to the active Transaction message for this
1213
 
   * Session being managed by the ReplicationServices component, or
1214
 
   * NULL if no active message.
1215
 
   */
1216
 
  message::Transaction *getTransactionMessage() const
1217
 
  {
1218
 
    return transaction_message;
1219
 
  }
1220
 
 
1221
 
  /**
1222
 
   * Returns a pointer to the active Statement message for this
1223
 
   * Session, or NULL if no active message.
1224
 
   */
1225
 
  message::Statement *getStatementMessage() const
1226
 
  {
1227
 
    return statement_message;
1228
 
  }
1229
 
 
1230
 
  /**
1231
 
   * Sets the active transaction message used by the ReplicationServices
1232
 
   * component.
1233
 
   *
1234
 
   * @param[in] Pointer to the message
1235
 
   */
1236
 
  void setTransactionMessage(message::Transaction *in_message)
1237
 
  {
1238
 
    transaction_message= in_message;
1239
 
  }
1240
 
 
1241
 
  /**
1242
 
   * Sets the active statement message used by the ReplicationServices
1243
 
   * component.
1244
 
   *
1245
 
   * @param[in] Pointer to the message
1246
 
   */
1247
 
  void setStatementMessage(message::Statement *in_message)
1248
 
  {
1249
 
    statement_message= in_message;
1250
 
  }
1251
1225
private:
1252
 
  /** Pointers to memory managed by the ReplicationServices component */
1253
 
  message::Transaction *transaction_message;
1254
 
  message::Statement *statement_message;
1255
1226
  /** Microsecond timestamp of when Session connected */
1256
1227
  uint64_t connect_microseconds;
1257
1228
  const char *proc_info;
1273
1244
    - for prepared queries, only to allocate runtime data. The parsed
1274
1245
    tree itself is reused between executions and thus is stored elsewhere.
1275
1246
  */
1276
 
  memory::Root main_mem_root;
 
1247
  MEM_ROOT main_mem_root;
1277
1248
 
1278
1249
  /**
1279
1250
   * Marks all tables in the list which were used by current substatement
1354
1325
  void close_old_data_files(bool morph_locks= false,
1355
1326
                            bool send_refresh= false);
1356
1327
  void close_open_tables();
1357
 
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
1358
1328
  void close_data_files_and_morph_locks(const char *db, const char *table_name);
1359
1329
 
1360
1330
private:
1412
1382
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1413
1383
 
1414
1384
  void unlink_open_table(Table *find);
1415
 
  void drop_open_table(Table *table, TableIdentifier &identifier);
 
1385
  void drop_open_table(Table *table, const char *db_name,
 
1386
                       const char *table_name);
1416
1387
  void close_cached_table(Table *table);
1417
1388
 
1418
1389
  /* Create a lock in the cache */
1419
1390
  Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1420
 
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1421
 
  bool lock_table_name_if_not_cached(const char *db,
 
1391
  bool lock_table_name_if_not_cached(const char *db, 
1422
1392
                                     const char *table_name, Table **table);
1423
1393
 
1424
 
  typedef drizzled::hash_map<std::string, message::Table> TableMessageCache;
1425
 
  TableMessageCache table_message_cache;
1426
 
 
1427
 
  bool storeTableMessage(TableIdentifier &identifier, message::Table &table_message);
1428
 
  bool removeTableMessage(TableIdentifier &identifier);
1429
 
  bool getTableMessage(TableIdentifier &identifier, message::Table &table_message);
1430
 
  bool doesTableMessageExist(TableIdentifier &identifier);
1431
 
  bool renameTableMessage(TableIdentifier &from, TableIdentifier &to);
1432
 
 
1433
1394
  /* Work with temporary tables */
1434
1395
  Table *find_temporary_table(TableList *table_list);
1435
1396
  Table *find_temporary_table(const char *db, const char *table_name);
1436
 
  Table *find_temporary_table(TableIdentifier &identifier);
1437
 
 
1438
 
  void doGetTableNames(CachedDirectory &directory,
1439
 
                       SchemaIdentifier &schema_identifier,
1440
 
                       std::set<std::string>& set_of_names);
1441
 
  void doGetTableNames(SchemaIdentifier &schema_identifier,
1442
 
                       std::set<std::string>& set_of_names);
1443
 
 
1444
 
  void doGetTableIdentifiers(CachedDirectory &directory,
1445
 
                             SchemaIdentifier &schema_identifier,
1446
 
                             TableIdentifiers &set_of_identifiers);
1447
 
  void doGetTableIdentifiers(SchemaIdentifier &schema_identifier,
1448
 
                             TableIdentifiers &set_of_identifiers);
1449
 
 
1450
 
  int doGetTableDefinition(drizzled::TableIdentifier &identifier,
1451
 
                           message::Table &table_proto);
1452
 
  bool doDoesTableExist(TableIdentifier &identifier);
1453
 
 
1454
1397
  void close_temporary_tables();
1455
 
  void close_temporary_table(Table *table);
1456
 
  // The method below just handles the de-allocation of the table. In
1457
 
  // a better memory type world, this would not be needed.
1458
 
private:
1459
 
  void nukeTable(Table *table);
1460
 
public:
1461
 
 
1462
 
  void dumpTemporaryTableNames(const char *id);
 
1398
  void close_temporary_table(Table *table, bool free_share, bool delete_table);
 
1399
  void close_temporary(Table *table, bool free_share, bool delete_table);
1463
1400
  int drop_temporary_table(TableList *table_list);
1464
 
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
1465
 
  bool rm_temporary_table(TableIdentifier &identifier);
1466
 
  Table *open_temporary_table(TableIdentifier &identifier,
1467
 
                              bool link_in_list= true);
1468
 
 
 
1401
  bool rm_temporary_table(StorageEngine *base, char *path);
 
1402
  Table *open_temporary_table(const char *path, const char *db,
 
1403
                              const char *table_name, bool link_in_list,
 
1404
                              open_table_mode open_mode);
 
1405
  
1469
1406
  /* Reopen operations */
1470
1407
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
1471
1408
  bool reopen_name_locked_table(TableList* table_list, bool link_in);
1474
1411
  void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1475
1412
  int setup_conds(TableList *leaves, COND **conds);
1476
1413
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1477
 
 
1478
 
 
1479
 
  /**
1480
 
    Return the default storage engine
1481
 
 
1482
 
    @param getDefaultStorageEngine()
1483
 
 
1484
 
    @return
1485
 
    pointer to plugin::StorageEngine
1486
 
  */
1487
 
  plugin::StorageEngine *getDefaultStorageEngine()
1488
 
  {
1489
 
    if (variables.storage_engine)
1490
 
      return variables.storage_engine;
1491
 
    return global_system_variables.storage_engine;
1492
 
  };
1493
 
 
1494
 
  static void unlink(Session *session);
1495
 
 
1496
1414
};
1497
1415
 
1498
1416
class JOIN;
1499
1417
 
1500
1418
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1501
1419
 
1502
 
} /* namespace drizzled */
1503
 
 
1504
 
/** @TODO why is this in the middle of the file */
1505
1420
#include <drizzled/select_to_file.h>
1506
1421
#include <drizzled/select_export.h>
1507
1422
#include <drizzled/select_dump.h>
1508
1423
#include <drizzled/select_insert.h>
1509
1424
#include <drizzled/select_create.h>
 
1425
#include <plugin/myisam/myisam.h>
1510
1426
#include <drizzled/tmp_table_param.h>
1511
1427
#include <drizzled/select_union.h>
1512
1428
#include <drizzled/select_subselect.h>
1514
1430
#include <drizzled/select_max_min_finder_subselect.h>
1515
1431
#include <drizzled/select_exists_subselect.h>
1516
1432
 
1517
 
namespace drizzled
1518
 
{
1519
 
 
1520
1433
/**
1521
1434
 * A structure used to describe sort information
1522
1435
 * for a field or item used in ORDER BY.
1541
1454
  SORT_FIELD *sortorder;
1542
1455
} SORT_BUFFER;
1543
1456
 
1544
 
} /* namespace drizzled */
1545
 
 
1546
 
/** @TODO why is this in the middle of the file */
1547
 
 
1548
1457
#include <drizzled/table_ident.h>
1549
1458
#include <drizzled/user_var_entry.h>
1550
1459
#include <drizzled/unique.h>
1551
 
#include <drizzled/var.h>
 
1460
#include <drizzled/my_var.h>
1552
1461
#include <drizzled/select_dumpvar.h>
1553
1462
 
1554
 
namespace drizzled
1555
 
{
1556
 
 
1557
1463
/* Bits in sql_command_flags */
1558
1464
 
1559
1465
enum sql_command_flag_bits 
1573
1479
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1574
1480
 
1575
1481
/* Functions in sql_class.cc */
1576
 
void add_to_status(system_status_var *to_var, system_status_var *from_var);
1577
 
 
1578
 
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
1579
 
                        system_status_var *dec_var);
1580
 
 
1581
 
} /* namespace drizzled */
 
1482
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
 
1483
 
 
1484
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
 
1485
                        STATUS_VAR *dec_var);
1582
1486
 
1583
1487
#endif /* DRIZZLED_SESSION_H */