~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ 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.
493
479
  }
494
480
 
495
481
  /**
 
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
  }
 
490
 
 
491
  /**
496
492
    Used in error messages to tell user in what part of MySQL we found an
497
493
    error. E. g. when where= "having clause", if fix_fields() fails, user
498
494
    will know that the error was in having clause.
528
524
 
529
525
private:
530
526
  /* container for handler's private per-connection data */
531
 
  Ha_data ha_data[MAX_HA];
 
527
  std::vector<Ha_data> ha_data;
532
528
  /*
533
529
    Id of current query. Statement can be reused to execute several queries
534
530
    query_id is global in context of the whole MySQL server.
540
536
  query_id_t query_id;
541
537
  query_id_t warn_query_id;
542
538
public:
543
 
  void **getEngineData(const plugin::StorageEngine *engine);
544
 
  Ha_trx_info *getEngineInfo(const plugin::StorageEngine *engine,
545
 
                             size_t index= 0);
 
539
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
 
540
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
 
541
                                      size_t index= 0);
546
542
 
547
543
  struct st_transactions {
548
 
    std::deque<drizzled::NamedSavepoint> savepoints;
549
 
    Session_TRANS all;                  // Trans since BEGIN WORK
550
 
    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
551
547
    XID_STATE xid_state;
552
548
 
553
 
    /*
554
 
       Tables changed in transaction (that must be invalidated in query cache).
555
 
       List contain only transactional tables, that not invalidated in query
556
 
       cache (instead of full list of changed in transaction tables).
557
 
    */
558
549
    void cleanup()
559
550
    {
560
551
      savepoints.clear();
566
557
      xid_state()
567
558
    { }
568
559
  } transaction;
 
560
 
569
561
  Field *dup_field;
570
562
  sigset_t signals;
571
563
 
800
792
  }
801
793
 
802
794
  /** Returns the current query text */
803
 
  inline const char *getQueryString()  const
 
795
  inline const std::string &getQueryString()  const
804
796
  {
805
797
    return query;
806
798
  }
808
800
  /** Returns the length of the current query text */
809
801
  inline size_t getQueryLength() const
810
802
  {
811
 
    if (query != NULL)
812
 
      return strlen(query);
 
803
    if (! query.empty())
 
804
      return query.length();
813
805
    else
814
806
      return 0;
815
807
  }
1430
1422
  /* Work with temporary tables */
1431
1423
  Table *find_temporary_table(TableList *table_list);
1432
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);
1433
1433
 
1434
1434
  void close_temporary_tables();
1435
1435
  void close_temporary_table(Table *table);
1441
1441
 
1442
1442
  int drop_temporary_table(TableList *table_list);
1443
1443
  bool rm_temporary_table(plugin::StorageEngine *base, const char *path);
1444
 
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
 
1444
  bool rm_temporary_table(TableIdentifier &identifier);
1445
1445
  Table *open_temporary_table(TableIdentifier &identifier,
1446
1446
                              bool link_in_list= true);
1447
1447
 
1552
1552
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1553
1553
 
1554
1554
/* Functions in sql_class.cc */
1555
 
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);
1556
1556
 
1557
 
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
1558
 
                        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);
1559
1559
 
1560
1560
} /* namespace drizzled */
1561
1561