~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2010-10-21 17:52:54 UTC
  • mto: This revision was merged to the branch mainline in revision 1885.
  • Revision ID: brian@tangent.org-20101021175254-l9nv1iio8713xtzc
Switched columns to use AllFields.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_SESSION_H
22
22
#define DRIZZLED_SESSION_H
23
23
 
 
24
/* Classes in mysql */
 
25
 
24
26
#include "drizzled/plugin.h"
25
 
#include "drizzled/sql_locale.h"
 
27
#include <drizzled/sql_locale.h>
26
28
#include "drizzled/resource_context.h"
27
 
#include "drizzled/cursor.h"
28
 
#include "drizzled/current_session.h"
29
 
#include "drizzled/sql_error.h"
30
 
#include "drizzled/file_exchange.h"
31
 
#include "drizzled/select_result_interceptor.h"
32
 
#include "drizzled/statistics_variables.h"
33
 
#include "drizzled/xid.h"
 
29
#include <drizzled/cursor.h>
 
30
#include <drizzled/current_session.h>
 
31
#include <drizzled/sql_error.h>
 
32
#include <drizzled/file_exchange.h>
 
33
#include <drizzled/select_result_interceptor.h>
 
34
#include <drizzled/statistics_variables.h>
 
35
#include <drizzled/xid.h>
34
36
#include "drizzled/query_id.h"
35
37
#include "drizzled/named_savepoint.h"
36
38
#include "drizzled/transaction_context.h"
37
39
#include "drizzled/util/storable.h"
 
40
 
38
41
#include "drizzled/my_hash.h"
39
 
#include "drizzled/pthread_globals.h"
 
42
 
40
43
#include <netdb.h>
41
 
#include <sys/time.h>
42
 
#include <sys/resource.h>
43
 
 
44
 
#include <algorithm>
 
44
#include <map>
 
45
#include <string>
45
46
#include <bitset>
46
47
#include <deque>
47
 
#include <map>
48
 
#include <string>
49
 
 
50
 
#include "drizzled/identifier.h"
51
 
#include "drizzled/open_tables_state.h"
52
 
#include "drizzled/internal_error_handler.h"
53
 
#include "drizzled/diagnostics_area.h"
54
 
#include "drizzled/plugin/authorization.h"
 
48
 
 
49
#include "drizzled/internal/getrusage.h"
 
50
 
 
51
#include <drizzled/security_context.h>
 
52
#include <drizzled/open_tables_state.h>
 
53
 
 
54
#include <drizzled/internal_error_handler.h>
 
55
#include <drizzled/diagnostics_area.h>
 
56
 
 
57
#include <drizzled/plugin/authorization.h>
55
58
 
56
59
#include <boost/unordered_map.hpp>
57
 
 
58
 
#include <boost/thread/thread.hpp>
59
60
#include <boost/thread/mutex.hpp>
60
61
#include <boost/thread/shared_mutex.hpp>
61
62
#include <boost/thread/condition_variable.hpp>
62
 
#include <boost/make_shared.hpp>
63
 
 
64
63
 
65
64
#define MIN_HANDSHAKE_SIZE      6
66
65
 
80
79
class Statement;
81
80
class Resultset;
82
81
}
83
 
 
84
82
namespace internal
85
83
{
86
84
struct st_my_thread_var;
87
85
}
88
86
 
89
 
namespace table
90
 
{
91
 
class Placeholder;
92
 
}
93
 
 
94
87
class Lex_input_stream;
95
88
class user_var_entry;
96
89
class CopyField;
126
119
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
127
120
      was actually changed or not.
128
121
*/
129
 
class CopyInfo 
 
122
struct CopyInfo 
130
123
{
131
 
public:
132
124
  ha_rows records; /**< Number of processed records */
133
125
  ha_rows deleted; /**< Number of deleted records */
134
126
  ha_rows updated; /**< Number of updated records */
159
151
 
160
152
};
161
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
 
162
170
} /* namespace drizzled */
163
171
 
164
172
/** @TODO why is this in the middle of the file */
173
181
#define Session_SENTRY_MAGIC 0xfeedd1ff
174
182
#define Session_SENTRY_GONE  0xdeadbeef
175
183
 
176
 
struct drizzle_system_variables
 
184
struct system_variables
177
185
{
178
 
  drizzle_system_variables()
179
 
  {}
 
186
  system_variables() {};
180
187
  /*
181
188
    How dynamically allocated system variables are handled:
182
189
 
213
220
  uint64_t preload_buff_size;
214
221
  uint32_t read_buff_size;
215
222
  uint32_t read_rnd_buff_size;
216
 
  bool replicate_query;
217
223
  size_t sortbuff_size;
218
224
  uint32_t thread_handling;
219
225
  uint32_t tx_isolation;
247
253
  Time_zone *time_zone;
248
254
};
249
255
 
250
 
extern struct drizzle_system_variables global_system_variables;
 
256
extern struct system_variables global_system_variables;
251
257
 
252
258
} /* namespace drizzled */
253
259
 
317
323
public:
318
324
  // Plugin storage in Session.
319
325
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
320
 
  typedef Session* Ptr;
321
 
  typedef boost::shared_ptr<Session> shared_ptr;
322
326
 
323
327
  /*
324
328
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
376
380
  {
377
381
    return mem_root;
378
382
  }
379
 
 
380
 
  uint64_t xa_id;
381
 
 
382
 
  uint64_t getXaId()
383
 
  {
384
 
    return xa_id;
385
 
  }
386
 
 
387
 
  void setXaId(uint64_t in_xa_id)
388
 
  {
389
 
    xa_id= in_xa_id; 
390
 
  }
391
 
 
392
383
  /**
393
384
   * Uniquely identifies each statement object in thread scope; change during
394
385
   * statement lifetime.
403
394
    return lex;
404
395
  }
405
396
  /** query associated with this statement */
406
 
  typedef boost::shared_ptr<const std::string> QueryString;
407
 
private:
408
 
  boost::shared_ptr<std::string> query;
409
 
 
410
 
  // Never allow for a modification of this outside of the class. c_str()
411
 
  // requires under some setup non const, you must copy the QueryString in
412
 
  // order to use it.
413
 
public:
414
 
  QueryString getQueryString() const
415
 
  {
416
 
    return query;
417
 
  }
418
 
 
419
 
  void resetQueryString()
420
 
  {
421
 
    query.reset();
422
 
    _state.reset();
423
 
  }
424
 
 
425
 
  /*
426
 
    We need to copy the lock on the string in order to make sure we have a stable string.
427
 
    Once this is done we can use it to build a const char* which can be handed off for
428
 
    a method to use (Innodb is currently the only engine using this).
429
 
  */
430
 
  const char *getQueryStringCopy(size_t &length)
431
 
  {
432
 
    QueryString tmp_string(getQueryString());
433
 
 
434
 
    assert(tmp_string);
435
 
    if (not tmp_string)
436
 
    {
437
 
      length= 0;
438
 
      return 0;
439
 
    }
440
 
 
441
 
    length= tmp_string->length();
442
 
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
443
 
    return to_return;
444
 
  }
445
 
 
446
 
  class State {
447
 
    std::vector <char> _query;
448
 
 
449
 
  public:
450
 
    typedef boost::shared_ptr<State> const_shared_ptr;
451
 
 
452
 
    State(const char *in_packet, size_t in_packet_length)
453
 
    {
454
 
      if (in_packet_length)
455
 
      {
456
 
        size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
457
 
        _query.resize(minimum + 1);
458
 
        memcpy(&_query[0], in_packet, minimum);
459
 
      }
460
 
      else
461
 
      {
462
 
        _query.resize(0);
463
 
      }
464
 
    }
465
 
 
466
 
    const char *query() const
467
 
    {
468
 
      if (_query.size())
469
 
        return &_query[0];
470
 
 
471
 
      return "";
472
 
    }
473
 
 
474
 
    const char *query(size_t &size) const
475
 
    {
476
 
      if (_query.size())
477
 
      {
478
 
        size= _query.size() -1;
479
 
        return &_query[0];
480
 
      }
481
 
 
482
 
      size= 0;
483
 
      return "";
484
 
    }
485
 
  protected:
486
 
    friend class Session;
487
 
    typedef boost::shared_ptr<State> shared_ptr;
488
 
  };
489
 
private:
490
 
  State::shared_ptr  _state; 
491
 
public:
492
 
 
493
 
  State::const_shared_ptr state()
494
 
  {
495
 
    return _state;
496
 
  }
 
397
  std::string query;
497
398
 
498
399
  /**
499
400
    Name of the current (default) database.
507
408
    the Session of that thread); that thread is (and must remain, for now) the
508
409
    only responsible for freeing this member.
509
410
  */
510
 
private:
511
 
  util::string::shared_ptr _schema;
512
 
public:
513
 
 
514
 
  util::string::const_shared_ptr schema() const
515
 
  {
516
 
    if (_schema)
517
 
      return _schema;
518
 
 
519
 
    return util::string::const_shared_ptr(new std::string(""));
520
 
  }
521
 
  std::string catalog;
 
411
  std::string db;
522
412
  /* current cache key */
523
413
  std::string query_cache_key;
524
414
  /**
531
421
 
532
422
  memory::Root warn_root; /**< Allocation area for warnings and errors */
533
423
  plugin::Client *client; /**< Pointer to client object */
534
 
 
535
 
  void setClient(plugin::Client *client_arg);
536
 
 
537
 
  plugin::Client *getClient()
538
 
  {
539
 
    return client;
540
 
  }
541
 
 
542
424
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
543
425
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
544
 
 
 
426
private:
545
427
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
546
 
private:
547
428
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
548
429
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
549
430
 
550
431
public:
551
 
 
552
 
  const UserVars &getUserVariables() const
553
 
  {
554
 
    return user_vars;
555
 
  }
556
 
 
557
 
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
 
432
  struct system_variables variables; /**< Mutable local variables local to the session */
558
433
  struct system_status_var status_var; /**< Session-local status counters */
559
434
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
560
435
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
561
436
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
 
437
private:
 
438
  boost::mutex LOCK_delete; /**< Locked before session is deleted */
 
439
public:
 
440
 
 
441
  void lockForDelete()
 
442
  {
 
443
    LOCK_delete.lock();
 
444
  }
 
445
 
 
446
  void unlockForDelete()
 
447
  {
 
448
    LOCK_delete.unlock();
 
449
  }
 
450
 
 
451
  /**
 
452
   * A peek into the query string for the session. This is a best effort
 
453
   * delivery, there is no guarantee whether the content is meaningful.
 
454
   */
 
455
  char process_list_info[PROCESS_LIST_WIDTH+1];
562
456
 
563
457
  /**
564
458
   * A pointer to the stack frame of the scheduler thread
567
461
  char *thread_stack;
568
462
 
569
463
private:
570
 
  identifier::User::shared_ptr security_ctx;
 
464
  SecurityContext security_ctx;
571
465
 
572
466
  int32_t scoreboard_index;
573
467
 
576
470
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
577
471
  }
578
472
public:
579
 
  identifier::User::const_shared_ptr user() const
 
473
  const SecurityContext& getSecurityContext() const
580
474
  {
581
 
    if (security_ctx)
582
 
      return security_ctx;
583
 
 
584
 
    return identifier::User::const_shared_ptr();
 
475
    return security_ctx;
585
476
  }
586
477
 
587
 
  void setUser(identifier::User::shared_ptr arg)
 
478
  SecurityContext& getSecurityContext()
588
479
  {
589
 
    security_ctx= arg;
 
480
    return security_ctx;
590
481
  }
591
482
 
592
483
  int32_t getScoreboardIndex()
602
493
  /**
603
494
   * Is this session viewable by the current user?
604
495
   */
605
 
  bool isViewable() const;
 
496
  bool isViewable() const
 
497
  {
 
498
    return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
 
499
                                               this,
 
500
                                               false);
 
501
  }
606
502
 
607
503
  /**
608
504
    Used in error messages to tell user in what part of MySQL we found an
618
514
  */
619
515
  uint32_t dbug_sentry; /**< watch for memory corruption */
620
516
private:
621
 
  boost::thread::id boost_thread_id;
622
 
  boost_thread_shared_ptr _thread;
623
 
  boost::this_thread::disable_interruption *interrupt;
624
 
 
625
517
  internal::st_my_thread_var *mysys_var;
626
518
public:
627
519
 
628
 
  boost_thread_shared_ptr &getThread()
629
 
  {
630
 
    return _thread;
631
 
  }
632
 
 
633
 
  void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
634
 
  {
635
 
    interrupt= interrupt_arg;
636
 
  }
637
 
 
638
 
  boost::this_thread::disable_interruption &getThreadInterupt()
639
 
  {
640
 
    assert(interrupt);
641
 
    return *interrupt;
642
 
  }
643
 
 
644
520
  internal::st_my_thread_var *getThreadVar()
645
521
  {
646
522
    return mysys_var;
647
523
  }
648
524
 
 
525
  void resetThreadVar()
 
526
  {
 
527
    mysys_var= NULL;
 
528
  }
649
529
  /**
650
530
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
651
531
   * first byte of the packet in executeStatement()
684
564
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
685
565
                                      size_t index= 0);
686
566
 
687
 
  /**
688
 
   * Structure used to manage "statement transactions" and
689
 
   * "normal transactions". In autocommit mode, the normal transaction is
690
 
   * equivalent to the statement transaction.
691
 
   *
692
 
   * Storage engines will be registered here when they participate in
693
 
   * a transaction. No engine is registered more than once.
694
 
   */
695
567
  struct st_transactions {
696
568
    std::deque<NamedSavepoint> savepoints;
697
 
 
698
 
    /**
699
 
     * The normal transaction (since BEGIN WORK).
700
 
     *
701
 
     * Contains a list of all engines that have participated in any of the
702
 
     * statement transactions started within the context of the normal
703
 
     * transaction.
704
 
     *
705
 
     * @note In autocommit mode, this is empty.
706
 
     */
707
 
    TransactionContext all;
708
 
 
709
 
    /**
710
 
     * The statment transaction.
711
 
     *
712
 
     * Contains a list of all engines participating in the given statement.
713
 
     *
714
 
     * @note In autocommit mode, this will be used to commit/rollback the
715
 
     * normal transaction.
716
 
     */
717
 
    TransactionContext stmt;
718
 
 
 
569
    TransactionContext all; ///< Trans since BEGIN WORK
 
570
    TransactionContext stmt; ///< Trans for current statement
719
571
    XID_STATE xid_state;
720
572
 
721
573
    void cleanup()
733
585
  Field *dup_field;
734
586
  sigset_t signals;
735
587
 
736
 
  // As of right now we do not allow a concurrent execute to launch itself
737
 
private:
738
 
  bool concurrent_execute_allowed;
739
 
public:
740
 
 
741
 
  void setConcurrentExecute(bool arg)
742
 
  {
743
 
    concurrent_execute_allowed= arg;
744
 
  }
745
 
 
746
 
  bool isConcurrentExecuteAllowed() const
747
 
  {
748
 
    return concurrent_execute_allowed;
749
 
  }
750
 
 
751
588
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
752
589
  bool arg_of_last_insert_id_function;
753
 
 
754
590
  /*
755
591
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
756
592
    insertion into an auto_increment column".
854
690
  uint32_t row_count;
855
691
  session_id_t thread_id;
856
692
  uint32_t tmp_table;
857
 
  enum global_read_lock_t
858
 
  {
859
 
    NONE= 0,
860
 
    GOT_GLOBAL_READ_LOCK= 1,
861
 
    MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
862
 
  };
863
 
private:
864
 
  global_read_lock_t _global_read_lock;
865
 
 
866
 
public:
867
 
 
868
 
  global_read_lock_t isGlobalReadLock() const
869
 
  {
870
 
    return _global_read_lock;
871
 
  }
872
 
 
873
 
  void setGlobalReadLock(global_read_lock_t arg)
874
 
  {
875
 
    _global_read_lock= arg;
876
 
  }
877
 
 
878
 
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags, bool *need_reopen);
879
 
  bool lockGlobalReadLock();
880
 
  bool lock_table_names(TableList *table_list);
881
 
  bool lock_table_names_exclusively(TableList *table_list);
882
 
  bool makeGlobalReadLockBlockCommit();
883
 
  bool abortLockForThread(Table *table);
884
 
  bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
885
 
  int lock_table_name(TableList *table_list);
886
 
  void abortLock(Table *table);
887
 
  void removeLock(Table *table);
888
 
  void unlockReadTables(DrizzleLock *sql_lock);
889
 
  void unlockSomeTables(Table **table, uint32_t count);
890
 
  void unlockTables(DrizzleLock *sql_lock);
891
 
  void startWaitingGlobalReadLock();
892
 
  void unlockGlobalReadLock();
893
 
 
894
 
private:
895
 
  int unlock_external(Table **table, uint32_t count);
896
 
  int lock_external(Table **tables, uint32_t count);
897
 
  bool wait_for_locked_table_names(TableList *table_list);
898
 
  DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
899
 
                             bool should_lock, Table **write_lock_used);
900
 
public:
901
 
 
 
693
  uint32_t global_read_lock;
902
694
  uint32_t server_status;
903
695
  uint32_t open_options;
904
696
  uint32_t select_number; /**< number of select (used for EXPLAIN) */
906
698
  enum_tx_isolation session_tx_isolation;
907
699
  enum_check_fields count_cuted_fields;
908
700
 
909
 
  enum killed_state_t
 
701
  enum killed_state
910
702
  {
911
703
    NOT_KILLED,
912
704
    KILL_BAD_DATA,
914
706
    KILL_QUERY,
915
707
    KILLED_NO_VALUE /* means none of the above states apply */
916
708
  };
917
 
private:
918
 
  killed_state_t volatile _killed;
919
 
 
920
 
public:
921
 
 
922
 
  void setKilled(killed_state_t arg)
923
 
  {
924
 
    _killed= arg;
925
 
  }
926
 
 
927
 
  killed_state_t getKilled()
928
 
  {
929
 
    return _killed;
930
 
  }
931
 
 
932
 
  volatile killed_state_t *getKilledPtr() // Do not use this method, it is here for historical convience.
933
 
  {
934
 
    return &_killed;
935
 
  }
936
 
 
937
 
  bool is_admin_connection;
 
709
  killed_state volatile killed;
 
710
 
938
711
  bool some_tables_deleted;
939
712
  bool no_errors;
940
713
  bool password;
1023
796
  }
1024
797
 
1025
798
  /** Returns the current query ID */
1026
 
  query_id_t getQueryId()  const
 
799
  inline query_id_t getQueryId()  const
1027
800
  {
1028
801
    return query_id;
1029
802
  }
1041
814
    return warn_query_id;
1042
815
  }
1043
816
 
 
817
  /** Returns the current query text */
 
818
  inline const std::string &getQueryString()  const
 
819
  {
 
820
    return query;
 
821
  }
 
822
 
 
823
  /** Returns the length of the current query text */
 
824
  inline size_t getQueryLength() const
 
825
  {
 
826
    if (! query.empty())
 
827
      return query.length();
 
828
    else
 
829
      return 0;
 
830
  }
 
831
 
1044
832
  /** Accessor method returning the session's ID. */
1045
833
  inline session_id_t getSessionId()  const
1046
834
  {
1133
921
   */
1134
922
  void cleanup_after_query();
1135
923
  bool storeGlobals();
1136
 
  void awake(Session::killed_state_t state_to_set);
 
924
  void awake(Session::killed_state state_to_set);
1137
925
  /**
1138
926
   * Pulls thread-specific variables into Session state.
1139
927
   *
1216
1004
  /**
1217
1005
   * Schedule a session to be run on the default scheduler.
1218
1006
   */
1219
 
  static bool schedule(Session::shared_ptr&);
1220
 
 
1221
 
  static void unlink(Session::shared_ptr&);
 
1007
  bool schedule();
1222
1008
 
1223
1009
  /*
1224
1010
    For enter_cond() / exit_cond() to work the mutex must be got before
1231
1017
  inline time_t query_start() { return start_time; }
1232
1018
  inline void set_time()
1233
1019
  {
1234
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1235
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1236
 
    start_utime= utime_after_lock= (mytime-epoch).total_microseconds();
1237
 
 
1238
1020
    if (user_time)
1239
1021
    {
1240
1022
      start_time= user_time;
1241
 
      connect_microseconds= start_utime;
 
1023
      connect_microseconds= start_utime= utime_after_lock= my_micro_time();
1242
1024
    }
1243
 
    else 
1244
 
      start_time= (mytime-epoch).total_seconds();
 
1025
    else
 
1026
      start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
1245
1027
  }
1246
1028
  inline void   set_current_time()    { start_time= time(NULL); }
1247
1029
  inline void   set_time(time_t t)
1248
1030
  {
1249
1031
    start_time= user_time= t;
1250
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1251
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1252
 
    uint64_t t_mark= (mytime-epoch).total_microseconds();
1253
 
 
1254
 
    start_utime= utime_after_lock= t_mark;
1255
 
  }
1256
 
  void set_time_after_lock()  { 
1257
 
     boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1258
 
     boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1259
 
     utime_after_lock= (mytime-epoch).total_microseconds();
1260
 
  }
 
1032
    start_utime= utime_after_lock= my_micro_time();
 
1033
  }
 
1034
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
1261
1035
  /**
1262
1036
   * Returns the current micro-timestamp
1263
1037
   */
1264
1038
  inline uint64_t getCurrentTimestamp()  
1265
1039
  { 
1266
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
1267
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
1268
 
    uint64_t t_mark= (mytime-epoch).total_microseconds();
1269
 
 
1270
 
    return t_mark; 
 
1040
    return my_micro_time(); 
1271
1041
  }
1272
1042
  inline uint64_t found_rows(void)
1273
1043
  {
1293
1063
    @todo: To silence an error, one should use Internal_error_handler
1294
1064
    mechanism. In future this function will be removed.
1295
1065
  */
1296
 
  inline void clear_error(bool full= false)
 
1066
  inline void clear_error()
1297
1067
  {
1298
1068
    if (main_da.is_error())
1299
1069
      main_da.reset_diagnostics_area();
1300
 
 
1301
 
    if (full)
1302
 
    {
1303
 
      drizzle_reset_errors(this, true);
1304
 
    }
1305
 
  }
1306
 
 
1307
 
  void clearDiagnostics()
1308
 
  {
1309
 
    main_da.reset_diagnostics_area();
 
1070
    return;
1310
1071
  }
1311
1072
 
1312
1073
  /**
1350
1111
  void end_statement();
1351
1112
  inline int killed_errno() const
1352
1113
  {
1353
 
    killed_state_t killed_val; /* to cache the volatile 'killed' */
1354
 
    return (killed_val= _killed) != KILL_BAD_DATA ? killed_val : 0;
 
1114
    killed_state killed_val; /* to cache the volatile 'killed' */
 
1115
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1355
1116
  }
1356
1117
  void send_kill_message() const;
1357
1118
  /* return true if we will abort query if we make a warning now */
1380
1141
    database usually involves other actions, like switching other database
1381
1142
    attributes including security context. In the future, this operation
1382
1143
    will be made private and more convenient interface will be provided.
 
1144
 
 
1145
    @return Operation status
 
1146
      @retval false Success
 
1147
      @retval true  Out-of-memory error
1383
1148
  */
1384
 
  void set_db(const std::string &new_db);
 
1149
  bool set_db(const std::string &new_db);
1385
1150
 
1386
1151
  /*
1387
1152
    Copy the current database to the argument. Use the current arena to
1446
1211
   * Current implementation does not depend on that, but future changes
1447
1212
   * should be done with this in mind; 
1448
1213
   *
1449
 
   * @param passwd Scrambled password received from client
1450
 
   * @param db Database name to connect to, may be NULL
 
1214
   * @param  Scrambled password received from client
 
1215
   * @param  Length of scrambled password
 
1216
   * @param  Database name to connect to, may be NULL
1451
1217
   */
1452
1218
  bool checkUser(const std::string &passwd, const std::string &db);
1453
1219
  
1620
1386
   * set to query_id of original query.
1621
1387
   */
1622
1388
  void mark_used_tables_as_free_for_reuse(Table *table);
 
1389
  /**
 
1390
    Mark all temporary tables which were used by the current statement or
 
1391
    substatement as free for reuse, but only if the query_id can be cleared.
 
1392
 
 
1393
    @param session thread context
 
1394
 
 
1395
    @remark For temp tables associated with a open SQL HANDLER the query_id
 
1396
            is not reset until the HANDLER is closed.
 
1397
  */
 
1398
  void mark_temp_tables_as_free_for_reuse();
1623
1399
 
1624
1400
public:
1625
1401
 
1672
1448
  void close_old_data_files(bool morph_locks= false,
1673
1449
                            bool send_refresh= false);
1674
1450
  void close_open_tables();
1675
 
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
 
1451
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
1676
1452
 
1677
1453
private:
1678
1454
  bool free_cached_table();
1709
1485
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1710
1486
 
1711
1487
  void unlink_open_table(Table *find);
1712
 
  void drop_open_table(Table *table, const TableIdentifier &identifier);
 
1488
  void drop_open_table(Table *table, TableIdentifier &identifier);
1713
1489
  void close_cached_table(Table *table);
1714
1490
 
1715
1491
  /* Create a lock in the cache */
1716
 
  table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
1717
 
  bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
 
1492
  Table *table_cache_insert_placeholder(const char *db_name, const char *table_name);
 
1493
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1718
1494
 
1719
1495
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1720
 
 
1721
 
  class TableMessages
1722
 
  {
1723
 
    TableMessageCache table_message_cache;
1724
 
 
1725
 
  public:
1726
 
    bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1727
 
    bool removeTableMessage(const TableIdentifier &identifier);
1728
 
    bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
1729
 
    bool doesTableMessageExist(const TableIdentifier &identifier);
1730
 
    bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1731
 
 
1732
 
  };
 
1496
  TableMessageCache table_message_cache;
 
1497
 
 
1498
  bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1499
  bool removeTableMessage(const TableIdentifier &identifier);
 
1500
  bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1501
  bool doesTableMessageExist(const TableIdentifier &identifier);
 
1502
  bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
 
1503
 
 
1504
  /* Work with temporary tables */
 
1505
  Table *find_temporary_table(TableList *table_list);
 
1506
  Table *find_temporary_table(const char *db, const char *table_name);
 
1507
  Table *find_temporary_table(TableIdentifier &identifier);
 
1508
 
 
1509
  void doGetTableNames(CachedDirectory &directory,
 
1510
                       const SchemaIdentifier &schema_identifier,
 
1511
                       std::set<std::string>& set_of_names);
 
1512
  void doGetTableNames(const SchemaIdentifier &schema_identifier,
 
1513
                       std::set<std::string>& set_of_names);
 
1514
 
 
1515
  void doGetTableIdentifiers(CachedDirectory &directory,
 
1516
                             const SchemaIdentifier &schema_identifier,
 
1517
                             TableIdentifiers &set_of_identifiers);
 
1518
  void doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
 
1519
                             TableIdentifiers &set_of_identifiers);
 
1520
 
 
1521
  int doGetTableDefinition(const drizzled::TableIdentifier &identifier,
 
1522
                           message::Table &table_proto);
 
1523
  bool doDoesTableExist(const drizzled::TableIdentifier &identifier);
 
1524
 
 
1525
  void close_temporary_tables();
 
1526
  void close_temporary_table(Table *table);
 
1527
  // The method below just handles the de-allocation of the table. In
 
1528
  // a better memory type world, this would not be needed.
1733
1529
private:
1734
 
  TableMessages _table_message_cache;
1735
 
 
 
1530
  void nukeTable(Table *table);
1736
1531
public:
1737
 
  TableMessages &getMessageCache()
1738
 
  {
1739
 
    return _table_message_cache;
1740
 
  }
 
1532
 
 
1533
  void dumpTemporaryTableNames(const char *id);
 
1534
  int drop_temporary_table(TableList *table_list);
 
1535
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
 
1536
  bool rm_temporary_table(TableIdentifier &identifier, bool best_effort= false);
 
1537
  Table *open_temporary_table(TableIdentifier &identifier,
 
1538
                              bool link_in_list= true);
1741
1539
 
1742
1540
  /* Reopen operations */
1743
1541
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
 
1542
  bool reopen_name_locked_table(TableList* table_list, bool link_in);
1744
1543
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1745
1544
 
1746
1545
  void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1747
1546
  int setup_conds(TableList *leaves, COND **conds);
1748
1547
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1749
1548
 
 
1549
  Table *create_virtual_tmp_table(List<CreateField> &field_list);
 
1550
  
1750
1551
  drizzled::util::Storable *getProperty(const std::string &arg)
1751
1552
  {
1752
1553
    return life_properties[arg];
1773
1574
    if (variables.storage_engine)
1774
1575
      return variables.storage_engine;
1775
1576
    return global_system_variables.storage_engine;
1776
 
  }
 
1577
  };
 
1578
 
 
1579
  static void unlink(Session *session);
1777
1580
 
1778
1581
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1779
1582
 
1780
1583
  table::Instance *getInstanceTable();
1781
 
  table::Instance *getInstanceTable(List<CreateField> &field_list);
1782
1584
 
1783
1585
private:
1784
1586
  bool resetUsage()
1836
1638
 * A structure used to describe sort information
1837
1639
 * for a field or item used in ORDER BY.
1838
1640
 */
1839
 
class SortField 
 
1641
struct SortField 
1840
1642
{
1841
 
public:
1842
1643
  Field *field; /**< Field to sort */
1843
1644
  Item  *item; /**< Item if not sorting fields */
1844
1645
  size_t length; /**< Length of sort field */
1890
1691
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1891
1692
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1892
1693
 
1893
 
namespace display  {
1894
 
const std::string &type(drizzled::Session::global_read_lock_t type);
1895
 
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1896
 
} /* namespace display */
1897
 
 
1898
1694
} /* namespace drizzled */
1899
1695
 
1900
1696
#endif /* DRIZZLED_SESSION_H */