~linuxjedi/drizzle/one-more-stab-at-boolean

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2011-02-12 10:06:03 UTC
  • mfrom: (2154.2.16 drizzle-build)
  • Revision ID: brian@tangent.org-20110212100603-i5ww0s02p8l4a8q7
Merge in solaris tree.

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
 
 
21
 
 
22
20
#ifndef DRIZZLED_SESSION_H
23
21
#define DRIZZLED_SESSION_H
24
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"
25
31
#include "drizzled/plugin.h"
26
 
#include "drizzled/sql_locale.h"
 
32
#include "drizzled/plugin/authorization.h"
 
33
#include "drizzled/pthread_globals.h"
 
34
#include "drizzled/query_id.h"
27
35
#include "drizzled/resource_context.h"
28
 
#include "drizzled/cursor.h"
29
 
#include "drizzled/current_session.h"
 
36
#include "drizzled/select_result_interceptor.h"
30
37
#include "drizzled/sql_error.h"
31
 
#include "drizzled/file_exchange.h"
32
 
#include "drizzled/select_result_interceptor.h"
 
38
#include "drizzled/sql_locale.h"
33
39
#include "drizzled/statistics_variables.h"
34
 
#include "drizzled/xid.h"
35
 
#include "drizzled/query_id.h"
36
 
#include "drizzled/named_savepoint.h"
37
40
#include "drizzled/transaction_context.h"
38
41
#include "drizzled/util/storable.h"
39
 
#include "drizzled/my_hash.h"
40
 
#include "drizzled/pthread_globals.h"
 
42
#include "drizzled/xid.h"
 
43
 
 
44
 
41
45
#include <netdb.h>
42
46
#include <sys/time.h>
43
47
#include <sys/resource.h>
44
48
 
45
49
#include <algorithm>
46
50
#include <bitset>
47
 
#include <deque>
48
51
#include <map>
49
52
#include <string>
50
53
 
51
 
#include "drizzled/identifier.h"
52
 
#include "drizzled/open_tables_state.h"
53
 
#include "drizzled/internal_error_handler.h"
54
 
#include "drizzled/diagnostics_area.h"
55
 
#include "drizzled/plugin/authorization.h"
56
 
 
57
54
#include "drizzled/catalog/instance.h"
58
55
#include "drizzled/catalog/local.h"
59
56
 
60
 
#include <boost/unordered_map.hpp>
 
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>
61
65
 
62
66
#include <boost/thread/thread.hpp>
63
67
#include <boost/thread/mutex.hpp>
65
69
#include <boost/thread/condition_variable.hpp>
66
70
#include <boost/make_shared.hpp>
67
71
 
 
72
#include <drizzled/lex_column.h>
 
73
#include "drizzled/sql_lex.h"
 
74
 
68
75
#include "drizzled/visibility.h"
69
76
 
70
77
#define MIN_HANDSHAKE_SIZE      6
86
93
class Resultset;
87
94
}
88
95
 
89
 
namespace internal
90
 
{
91
 
struct st_my_thread_var;
92
 
}
 
96
namespace internal { struct st_my_thread_var; }
93
97
 
94
 
namespace table
95
 
{
96
 
class Placeholder;
97
 
}
 
98
namespace table { class Placeholder; }
98
99
 
99
100
class Lex_input_stream;
100
101
class user_var_entry;
111
112
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
112
113
extern uint32_t tc_heuristic_recover;
113
114
 
114
 
/**
115
 
  @brief
116
 
  Local storage for proto that are tmp table. This should be enlarged
117
 
  to hande the entire table-share for a local table. Once Hash is done,
118
 
  we should consider exchanging the map for it.
119
 
*/
120
 
typedef std::map <std::string, message::Table> ProtoCache;
121
 
 
122
 
/**
123
 
  The COPY_INFO structure is used by INSERT/REPLACE code.
124
 
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
125
 
  UPDATE code:
126
 
    If a row is inserted then the copied variable is incremented.
127
 
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
128
 
      new data differs from the old one then the copied and the updated
129
 
      variables are incremented.
130
 
    The touched variable is incremented if a row was touched by the update part
131
 
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
132
 
      was actually changed or not.
133
 
*/
134
 
class CopyInfo 
135
 
{
136
 
public:
137
 
  ha_rows records; /**< Number of processed records */
138
 
  ha_rows deleted; /**< Number of deleted records */
139
 
  ha_rows updated; /**< Number of updated records */
140
 
  ha_rows copied;  /**< Number of copied records */
141
 
  ha_rows error_count;
142
 
  ha_rows touched; /* Number of touched records */
143
 
  enum enum_duplicates handle_duplicates;
144
 
  int escape_char, last_errno;
145
 
  bool ignore;
146
 
  /* for INSERT ... UPDATE */
147
 
  List<Item> *update_fields;
148
 
  List<Item> *update_values;
149
 
  /* for VIEW ... WITH CHECK OPTION */
150
 
 
151
 
  CopyInfo() :
152
 
    records(0),
153
 
    deleted(0),
154
 
    updated(0),
155
 
    copied(0),
156
 
    error_count(0),
157
 
    touched(0),
158
 
    escape_char(0),
159
 
    last_errno(0),
160
 
    ignore(0),
161
 
    update_fields(0),
162
 
    update_values(0)
163
 
  { }
164
 
 
165
 
};
166
 
 
167
 
} /* namespace drizzled */
168
 
 
169
 
/** @TODO why is this in the middle of the file */
170
 
#include <drizzled/lex_column.h>
171
 
 
172
 
namespace drizzled
173
 
{
174
 
 
175
115
class select_result;
176
116
class Time_zone;
177
117
 
178
118
#define Session_SENTRY_MAGIC 0xfeedd1ff
179
119
#define Session_SENTRY_GONE  0xdeadbeef
180
120
 
181
 
struct drizzle_system_variables
182
 
{
183
 
  drizzle_system_variables()
184
 
  {}
185
 
  /*
186
 
    How dynamically allocated system variables are handled:
187
 
 
188
 
    The global_system_variables and max_system_variables are "authoritative"
189
 
    They both should have the same 'version' and 'size'.
190
 
    When attempting to access a dynamic variable, if the session version
191
 
    is out of date, then the session version is updated and realloced if
192
 
    neccessary and bytes copied from global to make up for missing data.
193
 
  */
194
 
  ulong dynamic_variables_version;
195
 
  char * dynamic_variables_ptr;
196
 
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
197
 
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
198
 
 
199
 
  uint64_t myisam_max_extra_sort_file_size;
200
 
  uint64_t max_heap_table_size;
201
 
  uint64_t tmp_table_size;
202
 
  ha_rows select_limit;
203
 
  ha_rows max_join_size;
204
 
  uint64_t auto_increment_increment;
205
 
  uint64_t auto_increment_offset;
206
 
  uint64_t bulk_insert_buff_size;
207
 
  uint64_t join_buff_size;
208
 
  uint32_t max_allowed_packet;
209
 
  uint64_t max_error_count;
210
 
  uint64_t max_length_for_sort_data;
211
 
  size_t max_sort_length;
212
 
  uint64_t min_examined_row_limit;
213
 
  bool optimizer_prune_level;
214
 
  bool log_warnings;
215
 
 
216
 
  uint32_t optimizer_search_depth;
217
 
  uint32_t div_precincrement;
218
 
  uint64_t preload_buff_size;
219
 
  uint32_t read_buff_size;
220
 
  uint32_t read_rnd_buff_size;
221
 
  bool replicate_query;
222
 
  size_t sortbuff_size;
223
 
  uint32_t thread_handling;
224
 
  uint32_t tx_isolation;
225
 
  uint32_t completion_type;
226
 
  /* Determines which non-standard SQL behaviour should be enabled */
227
 
  uint32_t sql_mode;
228
 
  uint64_t max_seeks_for_key;
229
 
  size_t range_alloc_block_size;
230
 
  uint32_t query_alloc_block_size;
231
 
  uint32_t query_prealloc_size;
232
 
  uint64_t group_concat_max_len;
233
 
  uint64_t pseudo_thread_id;
234
 
 
235
 
  plugin::StorageEngine *storage_engine;
236
 
 
237
 
  /* Only charset part of these variables is sensible */
238
 
  const CHARSET_INFO  *character_set_filesystem;
239
 
 
240
 
  /* Both charset and collation parts of these variables are important */
241
 
  const CHARSET_INFO    *collation_server;
242
 
 
243
 
  inline const CHARSET_INFO  *getCollation(void) 
244
 
  {
245
 
    return collation_server;
246
 
  }
247
 
 
248
 
  /* Locale Support */
249
 
  MY_LOCALE *lc_time_names;
250
 
 
251
 
  Time_zone *time_zone;
252
 
};
253
 
 
254
121
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
255
122
 
256
 
} /* namespace drizzled */
257
 
 
258
 
#include "drizzled/sql_lex.h"
259
 
 
260
 
namespace drizzled
261
 
{
262
 
 
263
 
/**
264
 
  Storage engine specific thread local data.
265
 
*/
266
 
struct Ha_data
267
 
{
268
 
  /**
269
 
    Storage engine specific thread local data.
270
 
    Lifetime: one user connection.
271
 
  */
272
 
  void *ha_ptr;
273
 
  /**
274
 
   * Resource contexts for both the "statement" and "normal"
275
 
   * transactions.
276
 
   *
277
 
   * Resource context at index 0:
278
 
   *
279
 
   * Life time: one statement within a transaction. If @@autocommit is
280
 
   * on, also represents the entire transaction.
281
 
   *
282
 
   * Resource context at index 1:
283
 
   *
284
 
   * Life time: one transaction within a connection. 
285
 
   *
286
 
   * @note
287
 
   *
288
 
   * If the storage engine does not participate in a transaction, 
289
 
   * there will not be a resource context.
290
 
   */
291
 
  drizzled::ResourceContext resource_context[2];
292
 
 
293
 
  Ha_data() :ha_ptr(NULL) {}
294
 
};
295
 
 
296
123
/**
297
124
 * Represents a client connection to the database server.
298
125
 *
313
140
 * session object.
314
141
 */
315
142
 
316
 
class DRIZZLED_API Session :
317
 
  public Open_tables_state
 
143
class DRIZZLED_API Session : public Open_tables_state
318
144
{
319
145
public:
320
146
  // Plugin storage in Session.
321
 
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
322
 
  typedef Session* Ptr;
323
147
  typedef boost::shared_ptr<Session> shared_ptr;
324
148
  typedef Session& reference;
325
149
  typedef const Session& const_reference;
344
168
                        and update_row.
345
169
  */
346
170
  enum enum_mark_columns mark_used_columns;
347
 
  inline void* alloc(size_t size)
348
 
  {
349
 
    return mem_root->alloc_root(size);
350
 
  }
351
171
  inline void* calloc(size_t size)
352
172
  {
353
173
    void *ptr;
355
175
      memset(ptr, 0, size);
356
176
    return ptr;
357
177
  }
358
 
  inline char *strdup(const char *str)
359
 
  {
360
 
    return mem_root->strdup_root(str);
361
 
  }
362
178
  inline char *strmake(const char *str, size_t size)
363
179
  {
364
180
    return mem_root->strmake_root(str,size);
365
181
  }
366
 
  inline void *memdup(const void *str, size_t size)
367
 
  {
368
 
    return mem_root->memdup_root(str, size);
369
 
  }
 
182
 
370
183
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
371
184
  {
372
185
    void *ptr;
376
189
  }
377
190
  /** Frees all items attached to this Statement */
378
191
  void free_items();
 
192
 
379
193
  /**
380
194
   * List of items created in the parser for this query. Every item puts
381
195
   * itself to the list on creation (see Item::Item() for details))
422
236
 
423
237
  /** query associated with this statement */
424
238
  typedef boost::shared_ptr<const std::string> QueryString;
 
239
 
425
240
private:
426
241
  boost::shared_ptr<std::string> query;
427
242
 
460
275
    return to_return;
461
276
  }
462
277
 
463
 
  class State {
464
 
    std::vector <char> _query;
465
 
 
466
 
  public:
467
 
    typedef boost::shared_ptr<State> const_shared_ptr;
468
 
 
469
 
    State(const char *in_packet, size_t in_packet_length)
470
 
    {
471
 
      if (in_packet_length)
472
 
      {
473
 
        size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
474
 
        _query.resize(minimum + 1);
475
 
        memcpy(&_query[0], in_packet, minimum);
476
 
      }
477
 
      else
478
 
      {
479
 
        _query.resize(0);
480
 
      }
481
 
    }
482
 
 
483
 
    const char *query() const
484
 
    {
485
 
      if (_query.size())
486
 
        return &_query[0];
487
 
 
488
 
      return "";
489
 
    }
490
 
 
491
 
    const char *query(size_t &size) const
492
 
    {
493
 
      if (_query.size())
494
 
      {
495
 
        size= _query.size() -1;
496
 
        return &_query[0];
497
 
      }
498
 
 
499
 
      size= 0;
500
 
      return "";
501
 
    }
502
 
  protected:
503
 
    friend class Session;
504
 
    typedef boost::shared_ptr<State> shared_ptr;
505
 
  };
506
278
private:
507
 
  State::shared_ptr  _state; 
 
279
  session::State::shared_ptr  _state; 
 
280
 
508
281
public:
509
282
 
510
 
  State::const_shared_ptr state()
 
283
  session::State::const_shared_ptr state()
511
284
  {
512
285
    return _state;
513
286
  }
526
299
  */
527
300
private:
528
301
  util::string::shared_ptr _schema;
 
302
 
529
303
public:
530
304
 
531
305
  util::string::const_shared_ptr schema() const
568
342
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
569
343
 
570
344
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
 
345
 
571
346
private:
572
347
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
573
348
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
574
349
 
575
350
public:
576
 
 
577
351
  const UserVars &getUserVariables() const
578
352
  {
579
353
    return user_vars;
606
380
  {
607
381
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
608
382
  }
 
383
 
609
384
public:
610
385
  identifier::User::const_shared_ptr user() const
611
386
  {
667
442
  boost::this_thread::disable_interruption *interrupt;
668
443
 
669
444
  internal::st_my_thread_var *mysys_var;
 
445
 
670
446
public:
671
 
 
672
447
  boost_thread_shared_ptr &getThread()
673
448
  {
674
449
    return _thread;
749
524
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
750
525
                                      size_t index= 0);
751
526
 
752
 
  /**
753
 
   * Structure used to manage "statement transactions" and
754
 
   * "normal transactions". In autocommit mode, the normal transaction is
755
 
   * equivalent to the statement transaction.
756
 
   *
757
 
   * Storage engines will be registered here when they participate in
758
 
   * a transaction. No engine is registered more than once.
759
 
   */
760
 
  struct st_transactions {
761
 
    std::deque<NamedSavepoint> savepoints;
762
 
 
763
 
    /**
764
 
     * The normal transaction (since BEGIN WORK).
765
 
     *
766
 
     * Contains a list of all engines that have participated in any of the
767
 
     * statement transactions started within the context of the normal
768
 
     * transaction.
769
 
     *
770
 
     * @note In autocommit mode, this is empty.
771
 
     */
772
 
    TransactionContext all;
773
 
 
774
 
    /**
775
 
     * The statment transaction.
776
 
     *
777
 
     * Contains a list of all engines participating in the given statement.
778
 
     *
779
 
     * @note In autocommit mode, this will be used to commit/rollback the
780
 
     * normal transaction.
781
 
     */
782
 
    TransactionContext stmt;
783
 
 
784
 
    XID_STATE xid_state;
785
 
 
786
 
    void cleanup()
787
 
    {
788
 
      savepoints.clear();
789
 
    }
790
 
    st_transactions() :
791
 
      savepoints(),
792
 
      all(),
793
 
      stmt(),
794
 
      xid_state()
795
 
    { }
796
 
  } transaction;
 
527
  session::Transactions transaction;
797
528
 
798
529
  Field *dup_field;
799
530
  sigset_t signals;
801
532
  // As of right now we do not allow a concurrent execute to launch itself
802
533
private:
803
534
  bool concurrent_execute_allowed;
 
535
 
804
536
public:
805
537
 
806
538
  void setConcurrentExecute(bool arg)
1854
1586
  table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1855
1587
  bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1856
1588
 
1857
 
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
1858
 
 
1859
 
  class TableMessages
1860
 
  {
1861
 
    TableMessageCache table_message_cache;
1862
 
 
1863
 
  public:
1864
 
    bool storeTableMessage(const identifier::Table &identifier, message::Table &table_message);
1865
 
    bool removeTableMessage(const identifier::Table &identifier);
1866
 
    bool getTableMessage(const identifier::Table &identifier, message::Table &table_message);
1867
 
    bool doesTableMessageExist(const identifier::Table &identifier);
1868
 
    bool renameTableMessage(const identifier::Table &from, const identifier::Table &to);
1869
 
  };
1870
 
 
1871
1589
private:
1872
 
  TableMessages _table_message_cache;
 
1590
  session::TableMessages _table_message_cache;
1873
1591
 
1874
1592
public:
1875
 
  TableMessages &getMessageCache()
 
1593
  session::TableMessages &getMessageCache()
1876
1594
  {
1877
1595
    return _table_message_cache;
1878
1596
  }
1887
1605
 
1888
1606
  drizzled::util::Storable *getProperty(const std::string &arg)
1889
1607
  {
1890
 
    return life_properties[arg];
 
1608
    return life_properties.getProperty(arg);
1891
1609
  }
1892
1610
 
1893
1611
  template<class T>
1894
1612
  bool setProperty(const std::string &arg, T *value)
1895
1613
  {
1896
 
    life_properties[arg]= value;
 
1614
    life_properties.setProperty(arg, value);
1897
1615
 
1898
1616
    return true;
1899
1617
  }
1928
1646
 
1929
1647
    return true;
1930
1648
  }
 
1649
 
1931
1650
public:
1932
1651
 
1933
1652
  void setUsage(bool arg)
1955
1674
 
1956
1675
  // This lives throughout the life of Session
1957
1676
  bool use_usage;
1958
 
  PropertyMap life_properties;
 
1677
  session::PropertyMap life_properties;
1959
1678
  std::vector<table::Singular *> temporary_shares;
1960
1679
  struct rusage usage;
1961
1680
};
2043
1762
namespace display  {
2044
1763
const std::string &type(drizzled::Session::global_read_lock_t type);
2045
1764
size_t max_string_length(drizzled::Session::global_read_lock_t type);
 
1765
 
2046
1766
} /* namespace display */
2047
1767
 
2048
1768
} /* namespace drizzled */