~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Monty Taylor
  • Date: 2010-03-11 18:27:20 UTC
  • mfrom: (1333 staging)
  • mto: This revision was merged to the branch mainline in revision 1348.
  • Revision ID: mordred@inaugust.com-20100311182720-hd1h87y6cb1b1mp0
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include "drizzled/plugin.h"
27
27
#include <drizzled/sql_locale.h>
28
 
#include <drizzled/ha_trx_info.h>
 
28
#include "drizzled/resource_context.h"
29
29
#include <drizzled/cursor.h>
30
30
#include <drizzled/current_session.h>
31
31
#include <drizzled/sql_error.h>
34
34
#include <drizzled/xid.h>
35
35
#include "drizzled/query_id.h"
36
36
#include "drizzled/named_savepoint.h"
 
37
#include "drizzled/transaction_context.h"
37
38
 
38
39
#include <netdb.h>
39
40
#include <map>
47
48
#include <drizzled/internal_error_handler.h>
48
49
#include <drizzled/diagnostics_area.h>
49
50
 
 
51
#include <drizzled/plugin/authorization.h>
 
52
 
50
53
#define MIN_HANDSHAKE_SIZE      6
51
54
 
52
55
namespace drizzled
72
75
class CopyField;
73
76
class Table_ident;
74
77
 
75
 
 
76
78
extern char internal_table_name[2];
77
79
extern char empty_c_string[1];
78
80
extern const char **errmesg;
177
179
  bool log_warnings;
178
180
 
179
181
  uint32_t optimizer_search_depth;
180
 
  /* A bitmap for switching optimizations on/off */
181
 
  uint32_t optimizer_switch;
182
182
  uint32_t div_precincrement;
183
183
  uint64_t preload_buff_size;
184
184
  uint32_t read_buff_size;
286
286
    sense to add to the /global/ status variable counter.
287
287
  */
288
288
  double last_query_cost;
289
 
} STATUS_VAR;
 
289
} system_status_var;
290
290
 
291
291
/*
292
292
  This is used for 'SHOW STATUS'. It must be updated to the last ulong
313
313
  */
314
314
  void *ha_ptr;
315
315
  /**
316
 
    0: Life time: one statement within a transaction. If @@autocommit is
317
 
    on, also represents the entire transaction.
318
 
    @sa trans_register_ha()
319
 
 
320
 
    1: Life time: one transaction within a connection.
321
 
    If the storage engine does not participate in a transaction,
322
 
    this should not be used.
323
 
    @sa trans_register_ha()
324
 
  */
325
 
  Ha_trx_info ha_info[2];
 
316
   * Resource contexts for both the "statement" and "normal"
 
317
   * transactions.
 
318
   *
 
319
   * Resource context at index 0:
 
320
   *
 
321
   * Life time: one statement within a transaction. If @@autocommit is
 
322
   * on, also represents the entire transaction.
 
323
   *
 
324
   * Resource context at index 1:
 
325
   *
 
326
   * Life time: one transaction within a connection. 
 
327
   *
 
328
   * @note
 
329
   *
 
330
   * If the storage engine does not participate in a transaction, 
 
331
   * there will not be a resource context.
 
332
   */
 
333
  drizzled::ResourceContext resource_context[2];
326
334
 
327
335
  Ha_data() :ha_ptr(NULL) {}
328
336
};
407
415
   */
408
416
  uint32_t id;
409
417
  LEX *lex; /**< parse tree descriptor */
410
 
  /**
411
 
    Points to the query associated with this statement. It's const, but
412
 
    we need to declare it char * because all table handlers are written
413
 
    in C and need to point to it.
414
 
 
415
 
    Note that (A) if we set query = NULL, we must at the same time set
416
 
    query_length = 0, and protect the whole operation with the
417
 
    LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
418
 
    non-NULL value if its previous value is NULL. We do not need to protect
419
 
    operation (B) with any mutex. To avoid crashes in races, if we do not
420
 
    know that session->query cannot change at the moment, one should print
421
 
    session->query like this:
422
 
      (1) reserve the LOCK_thread_count mutex;
423
 
      (2) check if session->query is NULL;
424
 
      (3) if not NULL, then print at most session->query_length characters from
425
 
      it. We will see the query_length field as either 0, or the right value
426
 
      for it.
427
 
    Assuming that the write and read of an n-bit memory field in an n-bit
428
 
    computer is atomic, we can avoid races in the above way.
429
 
    This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
430
 
    STATUS.
431
 
  */
432
 
  char *query;
433
 
  uint32_t query_length; /**< current query length */
 
418
  /** query associated with this statement */
 
419
  std::string query;
434
420
 
435
421
  /**
436
422
    Name of the current (default) database.
479
465
   */
480
466
  char *thread_stack;
481
467
 
 
468
private:
 
469
  SecurityContext security_ctx;
 
470
public:
 
471
  const SecurityContext& getSecurityContext() const
 
472
  {
 
473
    return security_ctx;
 
474
  }
 
475
 
 
476
  SecurityContext& getSecurityContext()
 
477
  {
 
478
    return security_ctx;
 
479
  }
 
480
 
482
481
  /**
483
 
    @note
484
 
    Some members of Session (currently 'Statement::db',
485
 
    'query')  are set and alloced by the slave SQL thread
486
 
    (for the Session of that thread); that thread is (and must remain, for now)
487
 
    the only responsible for freeing these 3 members. If you add members
488
 
    here, and you add code to set them in replication, don't forget to
489
 
    free_them_and_set_them_to_0 in replication properly. For details see
490
 
    the 'err:' label of the handle_slave_sql() in sql/slave.cc.
491
 
 
492
 
    @see handle_slave_sql
493
 
  */
494
 
  Security_context security_ctx;
 
482
   * Is this session viewable by the current user?
 
483
   */
 
484
  bool isViewable() const
 
485
  {
 
486
    return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
 
487
                                               this,
 
488
                                               false);
 
489
  }
495
490
 
496
491
  /**
497
492
    Used in error messages to tell user in what part of MySQL we found an
529
524
 
530
525
private:
531
526
  /* container for handler's private per-connection data */
532
 
  Ha_data ha_data[MAX_HA];
 
527
  std::vector<Ha_data> ha_data;
533
528
  /*
534
529
    Id of current query. Statement can be reused to execute several queries
535
530
    query_id is global in context of the whole MySQL server.
541
536
  query_id_t query_id;
542
537
  query_id_t warn_query_id;
543
538
public:
544
 
  void **getEngineData(const plugin::StorageEngine *engine);
545
 
  Ha_trx_info *getEngineInfo(const plugin::StorageEngine *engine,
546
 
                             size_t index= 0);
 
539
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
 
540
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
 
541
                                      size_t index= 0);
547
542
 
548
543
  struct st_transactions {
549
 
    std::deque<drizzled::NamedSavepoint> savepoints;
550
 
    Session_TRANS all;                  // Trans since BEGIN WORK
551
 
    Session_TRANS stmt;                 // Trans for current statement
 
544
    std::deque<NamedSavepoint> savepoints;
 
545
    TransactionContext all; ///< Trans since BEGIN WORK
 
546
    TransactionContext stmt; ///< Trans for current statement
552
547
    XID_STATE xid_state;
553
548
 
554
 
    /*
555
 
       Tables changed in transaction (that must be invalidated in query cache).
556
 
       List contain only transactional tables, that not invalidated in query
557
 
       cache (instead of full list of changed in transaction tables).
558
 
    */
559
549
    void cleanup()
560
550
    {
561
551
      savepoints.clear();
567
557
      xid_state()
568
558
    { }
569
559
  } transaction;
 
560
 
570
561
  Field *dup_field;
571
562
  sigset_t signals;
572
563
 
801
792
  }
802
793
 
803
794
  /** Returns the current query text */
804
 
  inline const char *getQueryString()  const
 
795
  inline const std::string &getQueryString()  const
805
796
  {
806
797
    return query;
807
798
  }
809
800
  /** Returns the length of the current query text */
810
801
  inline size_t getQueryLength() const
811
802
  {
812
 
    if (query != NULL)
813
 
      return strlen(query);
 
803
    if (! query.empty())
 
804
      return query.length();
814
805
    else
815
806
      return 0;
816
807
  }
1042
1033
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1043
1034
                              const char* str, uint32_t length,
1044
1035
                              bool allocate_lex_string);
 
1036
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
 
1037
                              const std::string &str,
 
1038
                              bool allocate_lex_string);
1045
1039
 
1046
1040
  int send_explain_fields(select_result *result);
1047
1041
  /**
1428
1422
  /* Work with temporary tables */
1429
1423
  Table *find_temporary_table(TableList *table_list);
1430
1424
  Table *find_temporary_table(const char *db, const char *table_name);
 
1425
  void doGetTableNames(CachedDirectory &directory,
 
1426
                       const std::string& db_name,
 
1427
                       std::set<std::string>& set_of_names);
 
1428
  int doGetTableDefinition(const char *path,
 
1429
                           const char *db,
 
1430
                           const char *table_name,
 
1431
                           const bool is_tmp,
 
1432
                           message::Table *table_proto);
1431
1433
 
1432
1434
  void close_temporary_tables();
1433
1435
  void close_temporary_table(Table *table);
1439
1441
 
1440
1442
  int drop_temporary_table(TableList *table_list);
1441
1443
  bool rm_temporary_table(plugin::StorageEngine *base, const char *path);
1442
 
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
 
1444
  bool rm_temporary_table(TableIdentifier &identifier);
1443
1445
  Table *open_temporary_table(TableIdentifier &identifier,
1444
1446
                              bool link_in_list= true);
1445
1447
 
1550
1552
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1551
1553
 
1552
1554
/* Functions in sql_class.cc */
1553
 
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
 
1555
void add_to_status(system_status_var *to_var, system_status_var *from_var);
1554
1556
 
1555
 
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
1556
 
                        STATUS_VAR *dec_var);
 
1557
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
 
1558
                        system_status_var *dec_var);
1557
1559
 
1558
1560
} /* namespace drizzled */
1559
1561