~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Stewart Smith
  • Date: 2009-06-16 03:32:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090616033223-i8ffeqolaov4tps2
join test for MyISAM as temp table only: use myisam temp tables

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
 
20
21
#ifndef DRIZZLED_SESSION_H
21
22
#define DRIZZLED_SESSION_H
22
23
 
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"
31
 
#include "drizzled/plugin.h"
32
 
#include "drizzled/plugin/authorization.h"
33
 
#include "drizzled/pthread_globals.h"
34
 
#include "drizzled/query_id.h"
35
 
#include "drizzled/resource_context.h"
36
 
#include "drizzled/select_result_interceptor.h"
37
 
#include "drizzled/sql_error.h"
38
 
#include "drizzled/sql_locale.h"
39
 
#include "drizzled/statistics_variables.h"
40
 
#include "drizzled/transaction_context.h"
41
 
#include "drizzled/util/storable.h"
42
 
#include "drizzled/xid.h"
 
24
/* Classes in mysql */
43
25
 
 
26
#include <drizzled/protocol.h>
 
27
#include <drizzled/sql_locale.h>
 
28
#include <drizzled/ha_trx_info.h>
 
29
#include <mysys/my_alloc.h>
 
30
#include <mysys/my_tree.h>
 
31
#include <drizzled/handler.h>
 
32
#include <drizzled/current_session.h>
 
33
#include <drizzled/sql_error.h>
 
34
#include <drizzled/file_exchange.h>
 
35
#include <drizzled/select_result_interceptor.h>
 
36
#include <drizzled/authentication.h>
 
37
#include <drizzled/db.h>
 
38
#include <drizzled/xid.h>
44
39
 
45
40
#include <netdb.h>
46
 
#include <sys/time.h>
47
 
#include <sys/resource.h>
48
 
 
49
 
#include <algorithm>
 
41
#include <string>
50
42
#include <bitset>
51
 
#include <map>
52
 
#include <string>
53
 
 
54
 
#include "drizzled/catalog/instance.h"
55
 
#include "drizzled/catalog/local.h"
56
 
 
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>
65
 
 
66
 
#include <boost/thread/thread.hpp>
67
 
#include <boost/thread/mutex.hpp>
68
 
#include <boost/thread/shared_mutex.hpp>
69
 
#include <boost/thread/condition_variable.hpp>
70
 
#include <boost/make_shared.hpp>
71
 
 
72
 
#include <drizzled/lex_column.h>
73
 
#include "drizzled/sql_lex.h"
74
 
 
75
 
#include "drizzled/visibility.h"
76
43
 
77
44
#define MIN_HANDSHAKE_SIZE      6
78
45
 
79
 
namespace drizzled
80
 
{
81
 
 
82
 
namespace plugin
83
 
{
84
 
class Client;
85
 
class Scheduler;
86
 
class EventObserverList;
87
 
}
88
 
 
89
 
namespace message
90
 
{
91
 
class Transaction;
92
 
class Statement;
93
 
class Resultset;
94
 
}
95
 
 
96
 
namespace internal { struct st_my_thread_var; }
97
 
 
98
 
namespace table { class Placeholder; }
99
 
 
100
46
class Lex_input_stream;
101
47
class user_var_entry;
102
48
class CopyField;
103
49
class Table_ident;
104
50
 
105
 
class TableShareInstance;
106
 
 
107
51
extern char internal_table_name[2];
108
52
extern char empty_c_string[1];
109
53
extern const char **errmesg;
112
56
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
113
57
extern uint32_t tc_heuristic_recover;
114
58
 
 
59
/**
 
60
  The COPY_INFO structure is used by INSERT/REPLACE code.
 
61
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
 
62
  UPDATE code:
 
63
    If a row is inserted then the copied variable is incremented.
 
64
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
 
65
      new data differs from the old one then the copied and the updated
 
66
      variables are incremented.
 
67
    The touched variable is incremented if a row was touched by the update part
 
68
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
 
69
      was actually changed or not.
 
70
*/
 
71
typedef struct st_copy_info 
 
72
{
 
73
  ha_rows records; /**< Number of processed records */
 
74
  ha_rows deleted; /**< Number of deleted records */
 
75
  ha_rows updated; /**< Number of updated records */
 
76
  ha_rows copied;  /**< Number of copied records */
 
77
  ha_rows error_count;
 
78
  ha_rows touched; /* Number of touched records */
 
79
  enum enum_duplicates handle_duplicates;
 
80
  int escape_char, last_errno;
 
81
  bool ignore;
 
82
  /* for INSERT ... UPDATE */
 
83
  List<Item> *update_fields;
 
84
  List<Item> *update_values;
 
85
  /* for VIEW ... WITH CHECK OPTION */
 
86
} COPY_INFO;
 
87
 
 
88
typedef struct drizzled_lock_st
 
89
{
 
90
  Table **table;
 
91
  uint32_t table_count;
 
92
  uint32_t lock_count;
 
93
  THR_LOCK_DATA **locks;
 
94
} DRIZZLE_LOCK;
 
95
 
 
96
#include <drizzled/lex_column.h>
 
97
 
115
98
class select_result;
116
99
class Time_zone;
117
100
 
118
101
#define Session_SENTRY_MAGIC 0xfeedd1ff
119
102
#define Session_SENTRY_GONE  0xdeadbeef
120
103
 
121
 
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
122
 
 
123
 
/**
124
 
 * Represents a client connection to the database server.
125
 
 *
126
 
 * Contains the client/server protocol object, the current statement
127
 
 * being executed, local-to-session variables and status counters, and
128
 
 * a host of other information.
129
 
 *
130
 
 * @todo
131
 
 *
132
 
 * The Session class should have a vector of Statement object pointers which
133
 
 * comprise the statements executed on the Session. Until this architectural
134
 
 * change is done, we can forget about parallel operations inside a session.
135
 
 *
136
 
 * @todo
137
 
 *
138
 
 * Make member variables private and have inlined accessors and setters.  Hide
139
 
 * all member variables that are not critical to non-internal operations of the
140
 
 * session object.
141
 
 */
142
 
 
143
 
class DRIZZLED_API Session : public Open_tables_state
 
104
#define Session_CHECK_SENTRY(session) assert(session->dbug_sentry == Session_SENTRY_MAGIC)
 
105
 
 
106
struct system_variables
144
107
{
145
 
public:
146
 
  // Plugin storage in Session.
147
 
  typedef boost::shared_ptr<Session> shared_ptr;
148
 
  typedef Session& reference;
149
 
  typedef const Session& const_reference;
150
 
  typedef const Session* const_pointer;
151
 
  typedef Session* pointer;
152
 
 
153
 
  static shared_ptr make_shared(plugin::Client *client, catalog::Instance::shared_ptr instance_arg)
 
108
  system_variables() {};
 
109
  /*
 
110
    How dynamically allocated system variables are handled:
 
111
 
 
112
    The global_system_variables and max_system_variables are "authoritative"
 
113
    They both should have the same 'version' and 'size'.
 
114
    When attempting to access a dynamic variable, if the session version
 
115
    is out of date, then the session version is updated and realloced if
 
116
    neccessary and bytes copied from global to make up for missing data.
 
117
  */
 
118
  ulong dynamic_variables_version;
 
119
  char * dynamic_variables_ptr;
 
120
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
 
121
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
 
122
 
 
123
  uint64_t myisam_max_extra_sort_file_size;
 
124
  uint64_t max_heap_table_size;
 
125
  uint64_t tmp_table_size;
 
126
  ha_rows select_limit;
 
127
  ha_rows max_join_size;
 
128
  uint64_t auto_increment_increment;
 
129
  uint64_t auto_increment_offset;
 
130
  uint64_t bulk_insert_buff_size;
 
131
  uint64_t join_buff_size;
 
132
  uint32_t max_allowed_packet;
 
133
  uint32_t myisam_stats_method;
 
134
  uint64_t max_error_count;
 
135
  uint64_t max_length_for_sort_data;
 
136
  size_t max_sort_length;
 
137
  uint64_t max_tmp_tables;
 
138
  uint64_t min_examined_row_limit;
 
139
  uint32_t net_buffer_length;
 
140
  uint32_t net_read_timeout;
 
141
  uint32_t net_retry_count;
 
142
  uint32_t net_wait_timeout;
 
143
  uint32_t net_write_timeout;
 
144
  bool optimizer_prune_level;
 
145
  bool log_warnings;
 
146
  bool engine_condition_pushdown;
 
147
  bool keep_files_on_create;
 
148
 
 
149
  uint32_t optimizer_search_depth;
 
150
  /*
 
151
    Controls use of Engine-MRR:
 
152
      0 - auto, based on cost
 
153
      1 - force MRR when the storage engine is capable of doing it
 
154
      2 - disable MRR.
 
155
  */
 
156
  uint32_t optimizer_use_mrr;
 
157
  /* A bitmap for switching optimizations on/off */
 
158
  uint32_t optimizer_switch;
 
159
  uint32_t div_precincrement;
 
160
  uint64_t preload_buff_size;
 
161
  uint32_t read_buff_size;
 
162
  uint32_t read_rnd_buff_size;
 
163
  size_t sortbuff_size;
 
164
  uint32_t thread_handling;
 
165
  uint32_t tx_isolation;
 
166
  uint32_t completion_type;
 
167
  /* Determines which non-standard SQL behaviour should be enabled */
 
168
  uint32_t sql_mode;
 
169
  uint64_t max_seeks_for_key;
 
170
  size_t range_alloc_block_size;
 
171
  uint32_t query_alloc_block_size;
 
172
  uint32_t query_prealloc_size;
 
173
  uint32_t trans_alloc_block_size;
 
174
  uint32_t trans_prealloc_size;
 
175
  uint64_t group_concat_max_len;
 
176
  /* TODO: change this to my_thread_id - but have to fix set_var first */
 
177
  uint64_t pseudo_thread_id;
 
178
 
 
179
  StorageEngine *storage_engine;
 
180
 
 
181
  /* Only charset part of these variables is sensible */
 
182
  const CHARSET_INFO  *character_set_filesystem;
 
183
 
 
184
  /* Both charset and collation parts of these variables are important */
 
185
  const CHARSET_INFO    *collation_server;
 
186
 
 
187
  inline const CHARSET_INFO  *getCollation(void) 
154
188
  {
155
 
    assert(instance_arg);
156
 
    return boost::make_shared<Session>(client, instance_arg);
 
189
    return collation_server;
157
190
  }
158
191
 
 
192
  /* Locale Support */
 
193
  MY_LOCALE *lc_time_names;
 
194
 
 
195
  Time_zone *time_zone;
 
196
};
 
197
 
 
198
extern struct system_variables global_system_variables;
 
199
 
 
200
#include "sql_lex.h"
 
201
 
 
202
/**
 
203
 * Per-session local status counters
 
204
 */
 
205
typedef struct system_status_var
 
206
{
 
207
  uint64_t bytes_received;
 
208
  uint64_t bytes_sent;
 
209
  ulong com_other;
 
210
  ulong com_stat[(uint32_t) SQLCOM_END];
 
211
  ulong created_tmp_disk_tables;
 
212
  ulong created_tmp_tables;
 
213
  ulong ha_commit_count;
 
214
  ulong ha_delete_count;
 
215
  ulong ha_read_first_count;
 
216
  ulong ha_read_last_count;
 
217
  ulong ha_read_key_count;
 
218
  ulong ha_read_next_count;
 
219
  ulong ha_read_prev_count;
 
220
  ulong ha_read_rnd_count;
 
221
  ulong ha_read_rnd_next_count;
 
222
  ulong ha_rollback_count;
 
223
  ulong ha_update_count;
 
224
  ulong ha_write_count;
 
225
  ulong ha_prepare_count;
 
226
  ulong ha_savepoint_count;
 
227
  ulong ha_savepoint_rollback_count;
 
228
 
 
229
  /* KEY_CACHE parts. These are copies of the original */
 
230
  ulong key_blocks_changed;
 
231
  ulong key_blocks_used;
 
232
  ulong key_cache_r_requests;
 
233
  ulong key_cache_read;
 
234
  ulong key_cache_w_requests;
 
235
  ulong key_cache_write;
 
236
  /* END OF KEY_CACHE parts */
 
237
 
 
238
  ulong net_big_packet_count;
 
239
  ulong opened_tables;
 
240
  ulong opened_shares;
 
241
  ulong select_full_join_count;
 
242
  ulong select_full_range_join_count;
 
243
  ulong select_range_count;
 
244
  ulong select_range_check_count;
 
245
  ulong select_scan_count;
 
246
  ulong long_query_count;
 
247
  ulong filesort_merge_passes;
 
248
  ulong filesort_range_count;
 
249
  ulong filesort_rows;
 
250
  ulong filesort_scan_count;
 
251
  /*
 
252
    Number of statements sent from the client
 
253
  */
 
254
  ulong questions;
 
255
 
 
256
  /*
 
257
    IMPORTANT!
 
258
    SEE last_system_status_var DEFINITION BELOW.
 
259
 
 
260
    Below 'last_system_status_var' are all variables which doesn't make any
 
261
    sense to add to the /global/ status variable counter.
 
262
  */
 
263
  double last_query_cost;
 
264
} STATUS_VAR;
 
265
 
 
266
/*
 
267
  This is used for 'SHOW STATUS'. It must be updated to the last ulong
 
268
  variable in system_status_var which is makes sens to add to the global
 
269
  counter
 
270
*/
 
271
 
 
272
#define last_system_status_var questions
 
273
 
 
274
void mark_transaction_to_rollback(Session *session, bool all);
 
275
 
 
276
/**
 
277
 * Single command executed against this connection.
 
278
 *
 
279
 * @details
 
280
 *
 
281
 * One connection can contain a lot of simultaneously running statements,
 
282
 * some of which could be prepared, that is, contain placeholders.
 
283
 *
 
284
 * To perform some action with statement we reset Session part to the state  of
 
285
 * that statement, do the action, and then save back modified state from Session
 
286
 * to the statement. It will be changed in near future, and Statement will
 
287
 * be used explicitly.
 
288
 *
 
289
 * @todo
 
290
 *
 
291
 * The above comment is bullshit in Drizzle. See TODO markers on Session to
 
292
 * completely detach the inheritance of Session from Statement.
 
293
 */
 
294
class Statement
 
295
{
 
296
  Statement(const Statement &rhs);              /* not implemented: */
 
297
  Statement &operator=(const Statement &rhs);   /* non-copyable */
 
298
public:
 
299
  /**
 
300
   * List of items created in the parser for this query. Every item puts
 
301
   * itself to the list on creation (see Item::Item() for details))
 
302
   */
 
303
  Item *free_list;
 
304
  MEM_ROOT *mem_root; /**< Pointer to current memroot */
 
305
  /**
 
306
   * Uniquely identifies each statement object in thread scope; change during
 
307
   * statement lifetime.
 
308
   *
 
309
   * @todo should be const
 
310
   */
 
311
   uint32_t id;
 
312
 
159
313
  /*
160
314
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
161
315
                        handler of fields used is set
168
322
                        and update_row.
169
323
  */
170
324
  enum enum_mark_columns mark_used_columns;
171
 
  inline void* calloc(size_t size)
172
 
  {
173
 
    void *ptr;
174
 
    if ((ptr= mem_root->alloc_root(size)))
175
 
      memset(ptr, 0, size);
176
 
    return ptr;
177
 
  }
178
 
  inline char *strmake(const char *str, size_t size)
179
 
  {
180
 
    return mem_root->strmake_root(str,size);
181
 
  }
182
 
 
183
 
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
184
 
  {
185
 
    void *ptr;
186
 
    if ((ptr= mem_root->alloc_root(size + gap)))
187
 
      memcpy(ptr,str,size);
188
 
    return ptr;
189
 
  }
190
 
  /** Frees all items attached to this Statement */
191
 
  void free_items();
192
 
 
193
 
  /**
194
 
   * List of items created in the parser for this query. Every item puts
195
 
   * itself to the list on creation (see Item::Item() for details))
196
 
   */
197
 
  Item *free_list;
198
 
  memory::Root *mem_root; /**< Pointer to current memroot */
199
 
 
200
 
 
201
 
  memory::Root *getMemRoot()
202
 
  {
203
 
    return mem_root;
204
 
  }
205
 
 
206
 
  uint64_t xa_id;
207
 
 
208
 
  uint64_t getXaId()
209
 
  {
210
 
    return xa_id;
211
 
  }
212
 
 
213
 
  void setXaId(uint64_t in_xa_id)
214
 
  {
215
 
    xa_id= in_xa_id; 
216
 
  }
217
 
 
218
 
  /**
219
 
   * Uniquely identifies each statement object in thread scope; change during
220
 
   * statement lifetime.
221
 
   *
222
 
   * @todo should be const
223
 
   */
224
 
  uint32_t id;
 
325
 
225
326
  LEX *lex; /**< parse tree descriptor */
226
 
 
227
 
  LEX *getLex() 
228
 
  {
229
 
    return lex;
230
 
  }
231
 
 
232
 
  enum_sql_command getSqlCommand() const
233
 
  {
234
 
    return lex->sql_command;
235
 
  }
236
 
 
237
 
  /** query associated with this statement */
238
 
  typedef boost::shared_ptr<const std::string> QueryString;
239
 
 
240
 
private:
241
 
  boost::shared_ptr<std::string> query;
242
 
 
243
 
  // Never allow for a modification of this outside of the class. c_str()
244
 
  // requires under some setup non const, you must copy the QueryString in
245
 
  // order to use it.
246
 
public:
247
 
  QueryString getQueryString() const
248
 
  {
249
 
    return query;
250
 
  }
251
 
 
252
 
  void resetQueryString()
253
 
  {
254
 
    query.reset();
255
 
    _state.reset();
256
 
  }
257
 
 
258
 
  /*
259
 
    We need to copy the lock on the string in order to make sure we have a stable string.
260
 
    Once this is done we can use it to build a const char* which can be handed off for
261
 
    a method to use (Innodb is currently the only engine using this).
 
327
  /**
 
328
    Points to the query associated with this statement. It's const, but
 
329
    we need to declare it char * because all table handlers are written
 
330
    in C and need to point to it.
 
331
 
 
332
    Note that (A) if we set query = NULL, we must at the same time set
 
333
    query_length = 0, and protect the whole operation with the
 
334
    LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
 
335
    non-NULL value if its previous value is NULL. We do not need to protect
 
336
    operation (B) with any mutex. To avoid crashes in races, if we do not
 
337
    know that session->query cannot change at the moment, one should print
 
338
    session->query like this:
 
339
      (1) reserve the LOCK_thread_count mutex;
 
340
      (2) check if session->query is NULL;
 
341
      (3) if not NULL, then print at most session->query_length characters from
 
342
      it. We will see the query_length field as either 0, or the right value
 
343
      for it.
 
344
    Assuming that the write and read of an n-bit memory field in an n-bit
 
345
    computer is atomic, we can avoid races in the above way.
 
346
    This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
 
347
    STATUS.
262
348
  */
263
 
  const char *getQueryStringCopy(size_t &length)
264
 
  {
265
 
    QueryString tmp_string(getQueryString());
266
 
 
267
 
    if (not tmp_string)
268
 
    {
269
 
      length= 0;
270
 
      return NULL;
271
 
    }
272
 
 
273
 
    length= tmp_string->length();
274
 
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
275
 
    return to_return;
276
 
  }
277
 
 
278
 
private:
279
 
  session::State::shared_ptr  _state; 
280
 
 
281
 
public:
282
 
 
283
 
  session::State::const_shared_ptr state()
284
 
  {
285
 
    return _state;
286
 
  }
 
349
  char *query;
 
350
  uint32_t query_length; /**< current query length */
287
351
 
288
352
  /**
289
353
    Name of the current (default) database.
297
361
    the Session of that thread); that thread is (and must remain, for now) the
298
362
    only responsible for freeing this member.
299
363
  */
300
 
private:
301
 
  util::string::shared_ptr _schema;
302
 
 
303
 
public:
304
 
 
305
 
  util::string::const_shared_ptr schema() const
306
 
  {
307
 
    if (_schema)
308
 
      return _schema;
309
 
 
310
 
    return util::string::const_shared_ptr(new std::string(""));
311
 
  }
312
 
 
313
 
  /* current cache key */
314
 
  std::string query_cache_key;
 
364
  char *db;
 
365
  uint32_t db_length; /**< Length of current schema name */
 
366
 
 
367
public:
 
368
 
 
369
  /* This constructor is called for backup statements */
 
370
  Statement() {}
 
371
 
 
372
  Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, uint32_t id_arg)
 
373
  :
 
374
    free_list(NULL), 
 
375
    mem_root(mem_root_arg),
 
376
    id(id_arg),
 
377
    mark_used_columns(MARK_COLUMNS_READ),
 
378
    lex(lex_arg),
 
379
    query(NULL),
 
380
    query_length(0),
 
381
    db(NULL),
 
382
    db_length(0)
 
383
  {}
 
384
  virtual ~Statement() {}
 
385
  inline void* alloc(size_t size)
 
386
  {
 
387
    return alloc_root(mem_root,size);
 
388
  }
 
389
  inline void* calloc(size_t size)
 
390
  {
 
391
    void *ptr;
 
392
    if ((ptr= alloc_root(mem_root,size)))
 
393
      memset(ptr, 0, size);
 
394
    return ptr;
 
395
  }
 
396
  inline char *strdup(const char *str)
 
397
  {
 
398
    return strdup_root(mem_root,str);
 
399
  }
 
400
  inline char *strmake(const char *str, size_t size)
 
401
  {
 
402
    return strmake_root(mem_root,str,size);
 
403
  }
 
404
  inline void *memdup(const void *str, size_t size)
 
405
  {
 
406
    return memdup_root(mem_root,str,size);
 
407
  }
 
408
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
 
409
  {
 
410
    void *ptr;
 
411
    if ((ptr= alloc_root(mem_root,size+gap)))
 
412
      memcpy(ptr,str,size);
 
413
    return ptr;
 
414
  }
 
415
  /** Frees all items attached to this Statement */
 
416
  void free_items();
 
417
};
 
418
 
 
419
struct st_savepoint 
 
420
{
 
421
  struct st_savepoint *prev;
 
422
  char *name;
 
423
  uint32_t length;
 
424
  Ha_trx_info *ha_list;
 
425
};
 
426
 
 
427
extern pthread_mutex_t LOCK_xid_cache;
 
428
extern HASH xid_cache;
 
429
 
 
430
#include <drizzled/security_context.h>
 
431
#include <drizzled/open_tables_state.h>
 
432
 
 
433
#include <drizzled/internal_error_handler.h> 
 
434
#include <drizzled/diagnostics_area.h> 
 
435
 
 
436
/**
 
437
  Storage engine specific thread local data.
 
438
*/
 
439
struct Ha_data
 
440
{
 
441
  /**
 
442
    Storage engine specific thread local data.
 
443
    Lifetime: one user connection.
 
444
  */
 
445
  void *ha_ptr;
 
446
  /**
 
447
    0: Life time: one statement within a transaction. If @@autocommit is
 
448
    on, also represents the entire transaction.
 
449
    @sa trans_register_ha()
 
450
 
 
451
    1: Life time: one transaction within a connection.
 
452
    If the storage engine does not participate in a transaction,
 
453
    this should not be used.
 
454
    @sa trans_register_ha()
 
455
  */
 
456
  Ha_trx_info ha_info[2];
 
457
 
 
458
  Ha_data() :ha_ptr(NULL) {}
 
459
};
 
460
 
 
461
/**
 
462
 * Represents a client connection to the database server.
 
463
 *
 
464
 * Contains the client/server protocol object, the current statement
 
465
 * being executed, local-to-session variables and status counters, and
 
466
 * a host of other information.
 
467
 *
 
468
 * @todo
 
469
 *
 
470
 * Session should NOT inherit from Statement, but rather it should have a
 
471
 * vector of Statement object pointers which comprise the statements executed
 
472
 * on the Session.  Until this architectural change is done, we can forget
 
473
 * about parallel operations inside a session.
 
474
 *
 
475
 * @todo
 
476
 *
 
477
 * Make member variables private and have inlined accessors and setters.  Hide
 
478
 * all member variables that are not critical to non-internal operations of the
 
479
 * session object.
 
480
 */
 
481
class Session :public Statement, public Open_tables_state
 
482
{
 
483
public:
315
484
  /**
316
485
    Constant for Session::where initialization in the beginning of every query.
317
486
 
320
489
  */
321
490
  static const char * const DEFAULT_WHERE;
322
491
 
323
 
  memory::Root warn_root; /**< Allocation area for warnings and errors */
324
 
private:
325
 
  plugin::Client *client; /**< Pointer to client object */
326
 
 
327
 
public:
328
 
 
329
 
  void setClient(plugin::Client *client_arg);
330
 
 
331
 
  plugin::Client *getClient()
332
 
  {
333
 
    return client;
334
 
  }
335
 
 
336
 
  plugin::Client *getClient() const
337
 
  {
338
 
    return client;
339
 
  }
340
 
 
341
 
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
342
 
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
343
 
 
344
 
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
345
 
 
346
 
private:
347
 
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
348
 
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
349
 
 
350
 
public:
351
 
  const UserVars &getUserVariables() const
352
 
  {
353
 
    return user_vars;
354
 
  }
355
 
 
356
 
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
357
 
 
358
 
  enum_tx_isolation getTxIsolation()
359
 
  {
360
 
    return (enum_tx_isolation)variables.tx_isolation;
361
 
  }
362
 
 
 
492
  MEM_ROOT warn_root; /**< Allocation area for warnings and errors */
 
493
  Protocol *protocol;   /**< Pointer to the current protocol */
 
494
  HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
 
495
  String packet; /**< dynamic buffer for network I/O */
 
496
  String convert_buffer; /**< A buffer for charset conversions */
 
497
  struct system_variables variables; /**< Mutable local variables local to the session */
363
498
  struct system_status_var status_var; /**< Session-local status counters */
 
499
  struct system_status_var *initial_status_var; /* used by show status */
364
500
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
365
501
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
366
502
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
367
 
 
368
 
  /**
369
 
   * A pointer to the stack frame of the scheduler thread
 
503
  pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
 
504
 
 
505
  /**
 
506
   * A peek into the query string for the session. This is a best effort
 
507
   * delivery, there is no guarantee whether the content is meaningful.
 
508
   */
 
509
  char process_list_info[PROCESS_LIST_WIDTH+1];
 
510
 
 
511
  /**
 
512
   * A pointer to the stack frame of handle_one_connection(),
370
513
   * which is called first in the thread for handling a client
371
514
   */
372
515
  char *thread_stack;
373
516
 
374
 
private:
375
 
  identifier::User::shared_ptr security_ctx;
376
 
 
377
 
  int32_t scoreboard_index;
378
 
 
379
 
  inline void checkSentry() const
380
 
  {
381
 
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
382
 
  }
383
 
 
384
 
public:
385
 
  identifier::User::const_shared_ptr user() const
386
 
  {
387
 
    if (security_ctx)
388
 
      return security_ctx;
389
 
 
390
 
    return identifier::User::const_shared_ptr();
391
 
  }
392
 
 
393
 
  void setUser(identifier::User::shared_ptr arg)
394
 
  {
395
 
    security_ctx= arg;
396
 
  }
397
 
 
398
 
  int32_t getScoreboardIndex()
399
 
  {
400
 
    return scoreboard_index;
401
 
  }
402
 
 
403
 
  void setScoreboardIndex(int32_t in_scoreboard_index)
404
 
  {
405
 
    scoreboard_index= in_scoreboard_index;
406
 
  }
407
 
 
408
517
  /**
409
 
   * Is this session viewable by the current user?
410
 
   */
411
 
  bool isViewable(identifier::User::const_reference) const;
412
 
 
413
 
private:
 
518
    @note
 
519
    Some members of Session (currently 'Statement::db',
 
520
    'query')  are set and alloced by the slave SQL thread
 
521
    (for the Session of that thread); that thread is (and must remain, for now)
 
522
    the only responsible for freeing these 3 members. If you add members
 
523
    here, and you add code to set them in replication, don't forget to
 
524
    free_them_and_set_them_to_0 in replication properly. For details see
 
525
    the 'err:' label of the handle_slave_sql() in sql/slave.cc.
 
526
 
 
527
    @see handle_slave_sql
 
528
  */
 
529
  Security_context security_ctx;
 
530
 
414
531
  /**
415
532
    Used in error messages to tell user in what part of MySQL we found an
416
533
    error. E. g. when where= "having clause", if fix_fields() fails, user
417
534
    will know that the error was in having clause.
418
535
  */
419
 
  const char *_where;
420
 
 
421
 
public:
422
 
  const char *where()
423
 
  {
424
 
    return _where;
425
 
  }
426
 
 
427
 
  void setWhere(const char *arg)
428
 
  {
429
 
    _where= arg;
430
 
  }
 
536
  const char *where;
431
537
 
432
538
  /*
433
539
    One thread can hold up to one named user-level lock. This variable
435
541
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
436
542
  */
437
543
  uint32_t dbug_sentry; /**< watch for memory corruption */
438
 
 
439
 
private:
440
 
  boost::thread::id boost_thread_id;
441
 
  boost_thread_shared_ptr _thread;
442
 
  boost::this_thread::disable_interruption *interrupt;
443
 
 
444
 
  internal::st_my_thread_var *mysys_var;
445
 
 
446
 
public:
447
 
  boost_thread_shared_ptr &getThread()
448
 
  {
449
 
    return _thread;
450
 
  }
451
 
 
452
 
  void pushInterrupt(boost::this_thread::disable_interruption *interrupt_arg)
453
 
  {
454
 
    interrupt= interrupt_arg;
455
 
  }
456
 
 
457
 
  boost::this_thread::disable_interruption &getThreadInterupt()
458
 
  {
459
 
    assert(interrupt);
460
 
    return *interrupt;
461
 
  }
462
 
 
463
 
  internal::st_my_thread_var *getThreadVar()
464
 
  {
465
 
    return mysys_var;
466
 
  }
467
 
 
 
544
  struct st_my_thread_var *mysys_var;
468
545
  /**
469
546
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
470
547
   * first byte of the packet in executeStatement()
471
548
   */
472
549
  enum enum_server_command command;
473
550
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
474
 
  /* @note the following three members should likely move to Client */
 
551
  /* @note the following three members should likely move to Protocol */
 
552
  uint32_t client_capabilities; /**< What the client supports */
 
553
  uint16_t peer_port; /**< The remote (peer) port */
475
554
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
476
 
 
477
 
private:
478
 
  boost::posix_time::ptime _epoch;
479
 
  boost::posix_time::ptime _connect_time;
480
 
  boost::posix_time::ptime _start_timer;
481
 
  boost::posix_time::ptime _end_timer;
482
 
 
483
 
  boost::posix_time::ptime _user_time;
484
 
public:
485
 
  uint64_t utime_after_lock; // This used by Innodb.
486
 
 
487
 
  void resetUserTime()
488
 
  {
489
 
    _user_time= boost::posix_time::not_a_date_time;
490
 
  }
491
 
 
492
 
  const boost::posix_time::ptime &start_timer() const
493
 
  {
494
 
    return _start_timer;
495
 
  }
496
 
 
497
 
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
498
 
  {
499
 
    result_arg=  arg - _start_timer;
500
 
  }
 
555
  time_t start_time;
 
556
  time_t user_time;
 
557
  uint64_t connect_utime;
 
558
  uint64_t thr_create_utime; /**< track down slow pthread_create */
 
559
  uint64_t start_utime;
 
560
  uint64_t utime_after_lock;
501
561
 
502
562
  thr_lock_type update_lock_default;
503
563
 
505
565
    Both of the following container points in session will be converted to an API.
506
566
  */
507
567
 
508
 
private:
509
568
  /* container for handler's private per-connection data */
510
 
  std::vector<Ha_data> ha_data;
511
 
  /*
512
 
    Id of current query. Statement can be reused to execute several queries
513
 
    query_id is global in context of the whole MySQL server.
514
 
    ID is automatically generated from an atomic counter.
515
 
    It's used in Cursor code for various purposes: to check which columns
516
 
    from table are necessary for this select, to check if it's necessary to
517
 
    update auto-updatable fields (like auto_increment and timestamp).
518
 
  */
519
 
  query_id_t query_id;
520
 
  query_id_t warn_query_id;
521
 
 
522
 
public:
523
 
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
524
 
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
525
 
                                      size_t index= 0);
526
 
 
527
 
  session::Transactions transaction;
528
 
 
 
569
  Ha_data ha_data[MAX_HA];
 
570
 
 
571
  /* container for replication data */
 
572
  void *replication_data;
 
573
 
 
574
  struct st_transactions {
 
575
    SAVEPOINT *savepoints;
 
576
    Session_TRANS all;                  // Trans since BEGIN WORK
 
577
    Session_TRANS stmt;                 // Trans for current statement
 
578
    bool on;                            // see ha_enable_transaction()
 
579
    XID_STATE xid_state;
 
580
 
 
581
    /*
 
582
       Tables changed in transaction (that must be invalidated in query cache).
 
583
       List contain only transactional tables, that not invalidated in query
 
584
       cache (instead of full list of changed in transaction tables).
 
585
    */
 
586
    CHANGED_TableList* changed_tables;
 
587
    MEM_ROOT mem_root; // Transaction-life memory allocation pool
 
588
    void cleanup()
 
589
    {
 
590
      changed_tables= 0;
 
591
      savepoints= 0;
 
592
      free_root(&mem_root,MYF(MY_KEEP_PREALLOC));
 
593
    }
 
594
    st_transactions()
 
595
    {
 
596
      memset(this, 0, sizeof(*this));
 
597
      xid_state.xid.null();
 
598
      init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
 
599
    }
 
600
  } transaction;
529
601
  Field *dup_field;
530
602
  sigset_t signals;
531
603
 
532
 
  // As of right now we do not allow a concurrent execute to launch itself
533
 
private:
534
 
  bool concurrent_execute_allowed;
535
 
 
536
 
public:
537
 
 
538
 
  void setConcurrentExecute(bool arg)
539
 
  {
540
 
    concurrent_execute_allowed= arg;
541
 
  }
542
 
 
543
 
  bool isConcurrentExecuteAllowed() const
544
 
  {
545
 
    return concurrent_execute_allowed;
546
 
  }
547
 
 
548
604
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
549
605
  bool arg_of_last_insert_id_function;
550
 
 
551
606
  /*
552
607
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
553
608
    insertion into an auto_increment column".
601
656
  uint64_t limit_found_rows;
602
657
  uint64_t options; /**< Bitmap of options */
603
658
  int64_t row_count_func; /**< For the ROW_COUNT() function */
604
 
 
605
 
  int64_t rowCount() const
606
 
  {
607
 
    return row_count_func;
608
 
  }
609
 
 
610
659
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
611
660
 
612
661
  /** 
644
693
  uint32_t total_warn_count;
645
694
  Diagnostics_area main_da;
646
695
 
 
696
  /*
 
697
    Id of current query. Statement can be reused to execute several queries
 
698
    query_id is global in context of the whole MySQL server.
 
699
    ID is automatically generated from mutex-protected counter.
 
700
    It's used in handler code for various purposes: to check which columns
 
701
    from table are necessary for this select, to check if it's necessary to
 
702
    update auto-updatable fields (like auto_increment and timestamp).
 
703
  */
 
704
  query_id_t query_id;
 
705
  query_id_t warn_id;
647
706
  ulong col_access;
648
707
 
 
708
#ifdef ERROR_INJECT_SUPPORT
 
709
  ulong error_inject_value;
 
710
#endif
649
711
  /* Statement id is thread-wide. This counter is used to generate ids */
650
712
  uint32_t statement_id_counter;
651
713
  uint32_t rand_saved_seed1;
655
717
    create_sort_index(); may differ from examined_row_count.
656
718
  */
657
719
  uint32_t row_count;
658
 
 
659
 
  uint32_t getRowCount() const
660
 
  {
661
 
    return row_count;
662
 
  }
663
 
 
664
 
  session_id_t thread_id;
 
720
  pthread_t real_id; /**< For debugging */
 
721
  my_thread_id thread_id;
665
722
  uint32_t tmp_table;
666
 
  enum global_read_lock_t
667
 
  {
668
 
    NONE= 0,
669
 
    GOT_GLOBAL_READ_LOCK= 1,
670
 
    MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT= 2
671
 
  };
672
 
private:
673
 
  global_read_lock_t _global_read_lock;
674
 
 
675
 
public:
676
 
 
677
 
  global_read_lock_t isGlobalReadLock() const
678
 
  {
679
 
    return _global_read_lock;
680
 
  }
681
 
 
682
 
  void setGlobalReadLock(global_read_lock_t arg)
683
 
  {
684
 
    _global_read_lock= arg;
685
 
  }
686
 
 
687
 
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags);
688
 
  bool lockGlobalReadLock();
689
 
  bool lock_table_names(TableList *table_list);
690
 
  bool lock_table_names_exclusively(TableList *table_list);
691
 
  bool makeGlobalReadLockBlockCommit();
692
 
  bool abortLockForThread(Table *table);
693
 
  bool wait_if_global_read_lock(bool abort_on_refresh, bool is_not_commit);
694
 
  int lock_table_name(TableList *table_list);
695
 
  void abortLock(Table *table);
696
 
  void removeLock(Table *table);
697
 
  void unlockReadTables(DrizzleLock *sql_lock);
698
 
  void unlockSomeTables(Table **table, uint32_t count);
699
 
  void unlockTables(DrizzleLock *sql_lock);
700
 
  void startWaitingGlobalReadLock();
701
 
  void unlockGlobalReadLock();
702
 
 
703
 
private:
704
 
  int unlock_external(Table **table, uint32_t count);
705
 
  int lock_external(Table **tables, uint32_t count);
706
 
  bool wait_for_locked_table_names(TableList *table_list);
707
 
  DrizzleLock *get_lock_data(Table **table_ptr, uint32_t count,
708
 
                             bool should_lock, Table **write_lock_used);
709
 
public:
710
 
 
 
723
  uint32_t global_read_lock;
711
724
  uint32_t server_status;
712
725
  uint32_t open_options;
713
726
  uint32_t select_number; /**< number of select (used for EXPLAIN) */
715
728
  enum_tx_isolation session_tx_isolation;
716
729
  enum_check_fields count_cuted_fields;
717
730
 
718
 
  enum killed_state_t
 
731
  enum killed_state
719
732
  {
720
733
    NOT_KILLED,
721
734
    KILL_BAD_DATA,
723
736
    KILL_QUERY,
724
737
    KILLED_NO_VALUE /* means none of the above states apply */
725
738
  };
726
 
private:
727
 
  killed_state_t volatile _killed;
728
 
 
729
 
public:
730
 
 
731
 
  void setKilled(killed_state_t arg)
732
 
  {
733
 
    _killed= arg;
734
 
  }
735
 
 
736
 
  killed_state_t getKilled()
737
 
  {
738
 
    return _killed;
739
 
  }
740
 
 
741
 
  volatile killed_state_t *getKilledPtr() // Do not use this method, it is here for historical convience.
742
 
  {
743
 
    return &_killed;
744
 
  }
745
 
 
746
 
  bool is_admin_connection;
 
739
  killed_state volatile killed;
 
740
 
747
741
  bool some_tables_deleted;
748
742
  bool no_errors;
749
743
  bool password;
752
746
    can not continue. In particular, disables activation of
753
747
    CONTINUE or EXIT handlers of stored routines.
754
748
    Reset in the end of processing of the current user request, in
755
 
    @see reset_session_for_next_command().
 
749
    @see mysql_reset_session_for_next_command().
756
750
  */
757
751
  bool is_fatal_error;
758
752
  /**
777
771
  bool substitute_null_with_insert_id;
778
772
  bool cleanup_done;
779
773
 
780
 
private:
781
774
  bool abort_on_warning;
782
 
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
783
 
 
784
 
public:
785
775
  bool got_warning; /**< Set on call to push_warning() */
786
776
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
787
777
  /** set during loop of derived table processing */
788
778
  bool derived_tables_processing;
789
 
 
790
 
  bool doing_tablespace_operation(void)
791
 
  {
792
 
    return tablespace_op;
793
 
  }
794
 
 
795
 
  void setDoingTablespaceOperation(bool doing)
796
 
  {
797
 
    tablespace_op= doing;
798
 
  }
799
 
 
 
779
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
800
780
 
801
781
  /** Used by the sys_var class to store temporary values */
802
782
  union
816
796
  */
817
797
  Lex_input_stream *m_lip;
818
798
  
 
799
  /** session_scheduler for events */
 
800
  void *scheduler;
 
801
 
819
802
  /** Place to store various things */
820
803
  void *session_marker;
821
 
 
822
804
  /** Keeps a copy of the previous table around in case we are just slamming on particular table */
823
805
  Table *cached_table;
824
806
 
839
821
    return proc_info;
840
822
  }
841
823
 
842
 
  /** Sets this Session's current query ID */
843
 
  inline void setQueryId(query_id_t in_query_id)
844
 
  {
845
 
    query_id= in_query_id;
 
824
  inline void setReplicationData (void *data)
 
825
  {
 
826
    replication_data= data;
 
827
  }
 
828
  inline void *getReplicationData () const
 
829
  {
 
830
    return replication_data;
846
831
  }
847
832
 
848
833
  /** Returns the current query ID */
849
 
  query_id_t getQueryId()  const
 
834
  inline query_id_t getQueryId()  const
850
835
  {
851
836
    return query_id;
852
837
  }
853
838
 
854
 
 
855
 
  /** Sets this Session's warning query ID */
856
 
  inline void setWarningQueryId(query_id_t in_query_id)
857
 
  {
858
 
    warn_query_id= in_query_id;
859
 
  }
860
 
 
861
 
  /** Returns the Session's warning query ID */
862
 
  inline query_id_t getWarningQueryId()  const
863
 
  {
864
 
    return warn_query_id;
865
 
  }
866
 
 
867
 
  /** Accessor method returning the session's ID. */
868
 
  inline session_id_t getSessionId()  const
869
 
  {
870
 
    return thread_id;
 
839
  /** Returns the current query text */
 
840
  inline const char *getQueryString()  const
 
841
  {
 
842
    return query;
 
843
  }
 
844
 
 
845
  /** Returns the length of the current query text */
 
846
  inline size_t getQueryLength() const
 
847
  {
 
848
    return strlen(query);
871
849
  }
872
850
 
873
851
  /** Accessor method returning the server's ID. */
938
916
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
939
917
  }
940
918
 
941
 
  Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog);
942
 
  virtual ~Session();
 
919
  Session(Protocol *protocol_arg);
 
920
  ~Session();
943
921
 
 
922
  /**
 
923
    Initialize memory roots necessary for query processing and (!)
 
924
    pre-allocate memory for it. We can't do that in Session constructor because
 
925
    there are use cases (acl_init, watcher threads,
 
926
    killing mysqld) where it's vital to not allocate excessive and not used
 
927
    memory. Note, that we still don't return error from init_for_queries():
 
928
    if preallocation fails, we should notice that at the first call to
 
929
    alloc_root.
 
930
  */
 
931
  void init_for_queries();
944
932
  void cleanup(void);
945
933
  /**
946
934
   * Cleans up after query.
955
943
   * slave.
956
944
   */
957
945
  void cleanup_after_query();
958
 
  bool storeGlobals();
959
 
  void awake(Session::killed_state_t state_to_set);
 
946
  bool store_globals();
 
947
  void awake(Session::killed_state state_to_set);
960
948
  /**
961
949
   * Pulls thread-specific variables into Session state.
962
950
   *
969
957
  bool initGlobals();
970
958
 
971
959
  /**
972
 
    Initialize memory roots necessary for query processing and (!)
973
 
    pre-allocate memory for it. We can't do that in Session constructor because
974
 
    there are use cases where it's vital to not allocate excessive and not used
975
 
    memory.
976
 
  */
 
960
   * Initializes the Session to handle queries.
 
961
   */
977
962
  void prepareForQueries();
978
963
 
979
964
  /**
1020
1005
   */
1021
1006
  bool endTransaction(enum enum_mysql_completiontype completion);
1022
1007
  bool endActiveTransaction();
1023
 
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
1024
 
  void markTransactionForRollback(bool all);
 
1008
  bool startTransaction();
1025
1009
 
1026
1010
  /**
1027
1011
   * Authenticates users, with error reporting.
1030
1014
   */
1031
1015
  bool authenticate();
1032
1016
 
1033
 
  /**
1034
 
   * Run a session.
1035
 
   *
1036
 
   * This will initialize the session and begin the command loop.
1037
 
   */
1038
 
  void run();
1039
 
 
1040
 
  /**
1041
 
   * Schedule a session to be run on the default scheduler.
1042
 
   */
1043
 
  static bool schedule(Session::shared_ptr&);
1044
 
 
1045
 
  static void unlink(session_id_t &session_id);
1046
 
  static void unlink(Session::shared_ptr&);
1047
 
 
1048
1017
  /*
1049
1018
    For enter_cond() / exit_cond() to work the mutex must be got before
1050
1019
    enter_cond(); this mutex is then released by exit_cond().
1051
1020
    Usage must be: lock mutex; enter_cond(); your code; exit_cond().
1052
1021
  */
1053
 
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1054
 
  void exit_cond(const char* old_msg);
1055
 
 
1056
 
  type::Time::epoch_t query_start()
1057
 
  {
1058
 
    return getCurrentTimestampEpoch();
1059
 
  }
1060
 
 
1061
 
  void set_time()
1062
 
  {
1063
 
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
1064
 
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
1065
 
  }
1066
 
 
1067
 
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
1068
 
  {
1069
 
    _user_time= boost::posix_time::from_time_t(t);
1070
 
  }
1071
 
 
1072
 
  void set_time_after_lock()
1073
 
  { 
1074
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1075
 
    utime_after_lock= (mytime - _epoch).total_microseconds();
1076
 
  }
1077
 
 
1078
 
  void set_end_timer()
1079
 
  {
1080
 
    _end_timer= boost::posix_time::microsec_clock::universal_time();
1081
 
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
1082
 
  }
1083
 
 
1084
 
  uint64_t getElapsedTime() const
1085
 
  {
1086
 
    return (_end_timer - _start_timer).total_microseconds();
1087
 
  }
1088
 
 
 
1022
  inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg)
 
1023
  {
 
1024
    const char* old_msg = get_proc_info();
 
1025
    safe_mutex_assert_owner(mutex);
 
1026
    mysys_var->current_mutex = mutex;
 
1027
    mysys_var->current_cond = cond;
 
1028
    this->set_proc_info(msg);
 
1029
    return old_msg;
 
1030
  }
 
1031
  inline void exit_cond(const char* old_msg)
 
1032
  {
 
1033
    /*
 
1034
      Putting the mutex unlock in exit_cond() ensures that
 
1035
      mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
 
1036
      locked (if that would not be the case, you'll get a deadlock if someone
 
1037
      does a Session::awake() on you).
 
1038
    */
 
1039
    pthread_mutex_unlock(mysys_var->current_mutex);
 
1040
    pthread_mutex_lock(&mysys_var->mutex);
 
1041
    mysys_var->current_mutex = 0;
 
1042
    mysys_var->current_cond = 0;
 
1043
    this->set_proc_info(old_msg);
 
1044
    pthread_mutex_unlock(&mysys_var->mutex);
 
1045
  }
 
1046
  inline time_t query_start() { return start_time; }
 
1047
  inline void set_time()
 
1048
  {
 
1049
    if (user_time)
 
1050
    {
 
1051
      start_time= user_time;
 
1052
      start_utime= utime_after_lock= my_micro_time();
 
1053
    }
 
1054
    else
 
1055
      start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
 
1056
  }
 
1057
  inline void   set_current_time()    { start_time= time(NULL); }
 
1058
  inline void   set_time(time_t t)
 
1059
  {
 
1060
    start_time= user_time= t;
 
1061
    start_utime= utime_after_lock= my_micro_time();
 
1062
  }
 
1063
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
1089
1064
  /**
1090
1065
   * Returns the current micro-timestamp
1091
1066
   */
1092
 
  type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
1093
 
  { 
1094
 
    type::Time::epoch_t t_mark;
1095
 
 
1096
 
    if (actual)
1097
 
    {
1098
 
      boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1099
 
      t_mark= (mytime - _epoch).total_microseconds();
1100
 
    }
1101
 
    else
1102
 
    {
1103
 
      t_mark= (_end_timer - _epoch).total_microseconds();
1104
 
    }
1105
 
 
1106
 
    return t_mark; 
1107
 
  }
1108
 
 
1109
 
  // We may need to set user on this
1110
 
  type::Time::epoch_t getCurrentTimestampEpoch() const
1111
 
  { 
1112
 
    if (not _user_time.is_not_a_date_time())
1113
 
      return (_user_time - _epoch).total_seconds();
1114
 
 
1115
 
    return (_start_timer - _epoch).total_seconds();
1116
 
  }
1117
 
 
1118
 
  type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
1119
 
  { 
1120
 
    if (not _user_time.is_not_a_date_time())
1121
 
    {
1122
 
      fraction_arg= 0;
1123
 
      return (_user_time - _epoch).total_seconds();
1124
 
    }
1125
 
 
1126
 
    fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
1127
 
    return (_start_timer - _epoch).total_seconds();
1128
 
  }
1129
 
 
1130
 
  uint64_t found_rows(void) const
 
1067
  inline uint64_t getCurrentTimestamp()  
 
1068
  { 
 
1069
    return my_micro_time(); 
 
1070
  }
 
1071
  inline uint64_t found_rows(void)
1131
1072
  {
1132
1073
    return limit_found_rows;
1133
1074
  }
1134
 
 
1135
1075
  /** Returns whether the session is currently inside a transaction */
1136
 
  bool inTransaction() const
 
1076
  inline bool inTransaction()
1137
1077
  {
1138
1078
    return server_status & SERVER_STATUS_IN_TRANS;
1139
1079
  }
 
1080
  inline bool fill_derived_tables()
 
1081
  {
 
1082
    return !lex->only_view_structure();
 
1083
  }
 
1084
  inline void* trans_alloc(unsigned int size)
 
1085
  {
 
1086
    return alloc_root(&transaction.mem_root,size);
 
1087
  }
1140
1088
 
1141
1089
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1142
1090
                              const char* str, uint32_t length,
1143
1091
                              bool allocate_lex_string);
1144
1092
 
1145
 
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1146
 
                              const std::string &str,
1147
 
                              bool allocate_lex_string);
1148
 
 
 
1093
  void add_changed_table(Table *table);
 
1094
  void add_changed_table(const char *key, long key_length);
 
1095
  CHANGED_TableList * changed_table_dup(const char *key, long key_length);
1149
1096
  int send_explain_fields(select_result *result);
1150
 
 
1151
1097
  /**
1152
1098
    Clear the current error, if any.
1153
1099
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
1155
1101
    @todo: To silence an error, one should use Internal_error_handler
1156
1102
    mechanism. In future this function will be removed.
1157
1103
  */
1158
 
  inline void clear_error(bool full= false)
 
1104
  inline void clear_error()
1159
1105
  {
1160
1106
    if (main_da.is_error())
1161
1107
      main_da.reset_diagnostics_area();
1162
 
 
1163
 
    if (full)
1164
 
    {
1165
 
      drizzle_reset_errors(this, true);
1166
 
    }
1167
 
  }
1168
 
 
1169
 
  void clearDiagnostics()
1170
 
  {
1171
 
    main_da.reset_diagnostics_area();
 
1108
    return;
1172
1109
  }
1173
1110
 
1174
1111
  /**
1212
1149
  void end_statement();
1213
1150
  inline int killed_errno() const
1214
1151
  {
1215
 
    killed_state_t killed_val; /* to cache the volatile 'killed' */
1216
 
    return (killed_val= _killed) != KILL_BAD_DATA ? killed_val : 0;
 
1152
    killed_state killed_val; /* to cache the volatile 'killed' */
 
1153
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1217
1154
  }
1218
1155
  void send_kill_message() const;
1219
1156
  /* return true if we will abort query if we make a warning now */
1220
 
  inline bool abortOnWarning()
1221
 
  {
1222
 
    return abort_on_warning;
1223
 
  }
1224
 
 
1225
 
  inline void setAbortOnWarning(bool arg)
1226
 
  {
1227
 
    abort_on_warning= arg;
1228
 
  }
1229
 
 
1230
 
  void setAbort(bool arg);
1231
 
  void lockOnSys();
 
1157
  inline bool really_abort_on_warning()
 
1158
  {
 
1159
    return (abort_on_warning);
 
1160
  }
1232
1161
  void set_status_var_init();
 
1162
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
 
1163
  void restore_backup_open_tables_state(Open_tables_state *backup);
1233
1164
 
1234
1165
  /**
1235
1166
    Set the current database; use deep copy of C-string.
1247
1178
    database usually involves other actions, like switching other database
1248
1179
    attributes including security context. In the future, this operation
1249
1180
    will be made private and more convenient interface will be provided.
1250
 
  */
1251
 
  void set_db(const std::string &new_db);
1252
 
 
 
1181
 
 
1182
    @return Operation status
 
1183
      @retval false Success
 
1184
      @retval true  Out-of-memory error
 
1185
  */
 
1186
  bool set_db(const char *new_db, size_t new_db_len);
 
1187
 
 
1188
  /**
 
1189
    Set the current database; use shallow copy of C-string.
 
1190
 
 
1191
    @param new_db     a pointer to the new database name.
 
1192
    @param new_db_len length of the new database name.
 
1193
 
 
1194
    @note This operation just sets {db, db_length}. Switching the current
 
1195
    database usually involves other actions, like switching other database
 
1196
    attributes including security context. In the future, this operation
 
1197
    will be made private and more convenient interface will be provided.
 
1198
  */
 
1199
  void reset_db(char *new_db, size_t new_db_len)
 
1200
  {
 
1201
    db= new_db;
 
1202
    db_length= new_db_len;
 
1203
  }
1253
1204
  /*
1254
1205
    Copy the current database to the argument. Use the current arena to
1255
1206
    allocate memory for a deep copy: current database may be freed after
1270
1221
    @param level the error level
1271
1222
    @return true if the error is handled
1272
1223
  */
1273
 
  virtual bool handle_error(drizzled::error_t sql_errno, const char *message,
 
1224
  virtual bool handle_error(uint32_t sql_errno, const char *message,
1274
1225
                            DRIZZLE_ERROR::enum_warning_level level);
1275
1226
 
1276
1227
  /**
1298
1249
   * updates any status variables necessary.
1299
1250
   *
1300
1251
   * @param errcode     Error code to print to console
 
1252
   * @param should_lock 1 if we have have to lock LOCK_thread_count
1301
1253
   *
1302
1254
   * @note  For the connection that is doing shutdown, this is called twice
1303
1255
   */
1304
 
  void disconnect(enum error_t errcode= EE_OK);
 
1256
  void disconnect(uint32_t errcode, bool lock);
1305
1257
 
1306
1258
  /**
1307
1259
   * Check if user exists and the password supplied is correct.
1312
1264
   * Current implementation does not depend on that, but future changes
1313
1265
   * should be done with this in mind; 
1314
1266
   *
1315
 
   * @param passwd Scrambled password received from client
1316
 
   * @param db Database name to connect to, may be NULL
1317
 
   */
1318
 
  bool checkUser(const std::string &passwd, const std::string &db);
1319
 
  
1320
 
  /**
1321
 
   * Returns the timestamp (in microseconds) of when the Session 
1322
 
   * connected to the server.
1323
 
   */
1324
 
  uint64_t getConnectMicroseconds() const
1325
 
  {
1326
 
    return (_connect_time - _epoch).total_microseconds();
1327
 
  }
1328
 
 
1329
 
  uint64_t getConnectSeconds() const
1330
 
  {
1331
 
    return (_connect_time - _epoch).total_seconds();
1332
 
  }
1333
 
 
1334
 
  /**
1335
 
   * Returns a pointer to the active Transaction message for this
1336
 
   * Session being managed by the ReplicationServices component, or
1337
 
   * NULL if no active message.
1338
 
   */
1339
 
  message::Transaction *getTransactionMessage() const
1340
 
  {
1341
 
    return transaction_message;
1342
 
  }
1343
 
 
1344
 
  /**
1345
 
   * Returns a pointer to the active Statement message for this
1346
 
   * Session, or NULL if no active message.
1347
 
   */
1348
 
  message::Statement *getStatementMessage() const
1349
 
  {
1350
 
    return statement_message;
1351
 
  }
1352
 
  
1353
 
  /**
1354
 
   * Returns a pointer to the current Resulset message for this
1355
 
   * Session, or NULL if no active message.
1356
 
   */
1357
 
  message::Resultset *getResultsetMessage() const
1358
 
  {
1359
 
    return resultset;
1360
 
  }
1361
 
  /**
1362
 
   * Sets the active transaction message used by the ReplicationServices
1363
 
   * component.
1364
 
   *
1365
 
   * @param[in] Pointer to the message
1366
 
   */
1367
 
  void setTransactionMessage(message::Transaction *in_message)
1368
 
  {
1369
 
    transaction_message= in_message;
1370
 
  }
1371
 
 
1372
 
  /**
1373
 
   * Sets the active statement message used by the ReplicationServices
1374
 
   * component.
1375
 
   *
1376
 
   * @param[in] Pointer to the message
1377
 
   */
1378
 
  void setStatementMessage(message::Statement *in_message)
1379
 
  {
1380
 
    statement_message= in_message;
1381
 
  }
1382
 
 
1383
 
  /**
1384
 
   * Sets the active Resultset message used by the Query Cache
1385
 
   * plugin.
1386
 
   *
1387
 
   * @param[in] Pointer to the message
1388
 
   */
1389
 
  void setResultsetMessage(message::Resultset *in_message)
1390
 
  {
1391
 
    resultset= in_message;
1392
 
  }
1393
 
  /**
1394
 
   * reset the active Resultset message used by the Query Cache
1395
 
   * plugin.
1396
 
   */
1397
 
 
1398
 
  void resetResultsetMessage()
1399
 
  { 
1400
 
    resultset= NULL;
1401
 
  }
 
1267
   * @param  Scrambled password received from client
 
1268
   * @param  Length of scrambled password
 
1269
   * @param  Database name to connect to, may be NULL
 
1270
   */
 
1271
  bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1402
1272
 
1403
1273
private:
1404
 
  /** Pointers to memory managed by the ReplicationServices component */
1405
 
  message::Transaction *transaction_message;
1406
 
  message::Statement *statement_message;
1407
 
  /* Pointer to the current resultset of Select query */
1408
 
  message::Resultset *resultset;
1409
 
  plugin::EventObserverList *session_event_observers;
1410
 
  
1411
 
  /* Schema observers are mapped to databases. */
1412
 
  std::map<std::string, plugin::EventObserverList *> schema_event_observers;
1413
 
 
1414
 
 
1415
 
public:
1416
 
  plugin::EventObserverList *getSessionObservers() 
1417
 
  { 
1418
 
    return session_event_observers;
1419
 
  }
1420
 
  
1421
 
  void setSessionObservers(plugin::EventObserverList *observers) 
1422
 
  { 
1423
 
    session_event_observers= observers;
1424
 
  }
1425
 
  
1426
 
  /* For schema event observers there is one set of observers per database. */
1427
 
  plugin::EventObserverList *getSchemaObservers(const std::string &db_name) 
1428
 
  { 
1429
 
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1430
 
    
1431
 
    it= schema_event_observers.find(db_name);
1432
 
    if (it == schema_event_observers.end())
1433
 
      return NULL;
1434
 
      
1435
 
    return it->second;
1436
 
  }
1437
 
  
1438
 
  void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers) 
1439
 
  { 
1440
 
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1441
 
 
1442
 
    it= schema_event_observers.find(db_name);
1443
 
    if (it != schema_event_observers.end())
1444
 
      schema_event_observers.erase(it);;
1445
 
 
1446
 
    if (observers)
1447
 
      schema_event_observers[db_name] = observers;
1448
 
  }
1449
 
  
1450
 
  
1451
 
 private:
1452
1274
  const char *proc_info;
1453
1275
 
1454
1276
  /** The current internal error handler for this thread, or NULL. */
1468
1290
    - for prepared queries, only to allocate runtime data. The parsed
1469
1291
    tree itself is reused between executions and thus is stored elsewhere.
1470
1292
  */
1471
 
  memory::Root main_mem_root;
 
1293
  MEM_ROOT main_mem_root;
1472
1294
 
1473
1295
  /**
1474
1296
   * Marks all tables in the list which were used by current substatement
1489
1311
   * set to query_id of original query.
1490
1312
   */
1491
1313
  void mark_used_tables_as_free_for_reuse(Table *table);
 
1314
  /**
 
1315
    Mark all temporary tables which were used by the current statement or
 
1316
    substatement as free for reuse, but only if the query_id can be cleared.
 
1317
 
 
1318
    @param session thread context
 
1319
 
 
1320
    @remark For temp tables associated with a open SQL HANDLER the query_id
 
1321
            is not reset until the HANDLER is closed.
 
1322
  */
 
1323
  void mark_temp_tables_as_free_for_reuse();
1492
1324
 
1493
1325
public:
1494
1326
 
1495
1327
  /** A short cut for session->main_da.set_ok_status(). */
1496
 
  inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1497
 
                    uint64_t passed_id= 0, const char *message= NULL)
 
1328
  inline void my_ok(ha_rows affected_rows= 0, uint64_t passed_id= 0, const char *message= NULL)
1498
1329
  {
1499
 
    main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
 
1330
    main_da.set_ok_status(this, affected_rows, passed_id, message);
1500
1331
  }
1501
1332
 
1502
1333
 
1530
1361
  }
1531
1362
  void refresh_status();
1532
1363
  user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1533
 
  user_var_entry *getVariable(const std::string  &name, bool create_if_not_exists);
1534
 
  void setVariable(const std::string &name, const std::string &value);
1535
1364
  
1536
1365
  /**
1537
1366
   * Closes all tables used by the current substatement, or all tables
1538
1367
   * used by this thread if we are on the upper level.
1539
1368
   */
1540
1369
  void close_thread_tables();
1541
 
  void close_old_data_files(bool morph_locks= false,
1542
 
                            bool send_refresh= false);
 
1370
  void close_old_data_files(bool morph_locks, bool send_refresh);
1543
1371
  void close_open_tables();
1544
 
  void close_data_files_and_morph_locks(const identifier::Table &identifier);
1545
 
 
1546
 
private:
1547
 
  bool free_cached_table(boost::mutex::scoped_lock &scopedLock);
1548
 
 
1549
 
public:
1550
 
 
 
1372
  void close_data_files_and_morph_locks(const char *db, const char *table_name);
1551
1373
  /**
1552
1374
   * Prepares statement for reopening of tables and recalculation of set of
1553
1375
   * prelocked tables.
1555
1377
   * @param Pointer to a pointer to a list of tables which we were trying to open and lock
1556
1378
   */
1557
1379
  void close_tables_for_reopen(TableList **tables);
1558
 
 
1559
 
 
1560
1380
  /**
1561
1381
   * Open all tables in list, locks them (all, including derived)
1562
1382
   *
1571
1391
   * 
1572
1392
   * The lock will automaticaly be freed by close_thread_tables()
1573
1393
   */
1574
 
  bool openTablesLock(TableList *tables);
1575
 
 
1576
 
  int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1577
 
 
1578
 
  Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1579
 
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1580
 
 
 
1394
  int open_and_lock_tables(TableList *tables);
 
1395
  /**
 
1396
   * Open all tables in list and process derived tables
 
1397
   *
 
1398
   * @param Pointer to a list of tables for open
 
1399
   * @param Bitmap of flags to modify how the tables will be open:
 
1400
   *        DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
 
1401
   *        done a flush or namelock on it.
 
1402
   *
 
1403
   * @retval
 
1404
   *  false - ok
 
1405
   * @retval
 
1406
   *  true  - error
 
1407
   *
 
1408
   * @note
 
1409
   *
 
1410
   * This is to be used on prepare stage when you don't read any
 
1411
   * data from the tables.
 
1412
   */
 
1413
  bool open_normal_and_derived_tables(TableList *tables, uint32_t flags);
 
1414
  int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags);
 
1415
  Table *open_ltable(TableList *table_list, thr_lock_type lock_type);
 
1416
  Table *open_table(TableList *table_list, bool *refresh, uint32_t flags);
1581
1417
  void unlink_open_table(Table *find);
1582
 
  void drop_open_table(Table *table, const identifier::Table &identifier);
 
1418
  void drop_open_table(Table *table, const char *db_name,
 
1419
                       const char *table_name);
1583
1420
  void close_cached_table(Table *table);
1584
1421
 
1585
1422
  /* Create a lock in the cache */
1586
 
  table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1587
 
  bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1588
 
 
1589
 
private:
1590
 
  session::TableMessages _table_message_cache;
1591
 
 
1592
 
public:
1593
 
  session::TableMessages &getMessageCache()
1594
 
  {
1595
 
    return _table_message_cache;
1596
 
  }
1597
 
 
 
1423
  Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
 
1424
  bool lock_table_name_if_not_cached(const char *db, 
 
1425
                                     const char *table_name, Table **table);
 
1426
 
 
1427
  /* Work with temporary tables */
 
1428
  Table *find_temporary_table(TableList *table_list);
 
1429
  Table *find_temporary_table(const char *db, const char *table_name);
 
1430
  void close_temporary_tables();
 
1431
  void close_temporary_table(Table *table, bool free_share, bool delete_table);
 
1432
  int drop_temporary_table(TableList *table_list);
 
1433
  
1598
1434
  /* Reopen operations */
1599
 
  bool reopen_tables();
1600
 
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1601
 
 
1602
 
  void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1603
 
  int setup_conds(TableList *leaves, COND **conds);
1604
 
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1605
 
 
1606
 
  drizzled::util::Storable *getProperty(const std::string &arg)
1607
 
  {
1608
 
    return life_properties.getProperty(arg);
1609
 
  }
1610
 
 
1611
 
  template<class T>
1612
 
  bool setProperty(const std::string &arg, T *value)
1613
 
  {
1614
 
    life_properties.setProperty(arg, value);
1615
 
 
1616
 
    return true;
1617
 
  }
1618
 
 
1619
 
  /**
1620
 
    Return the default storage engine
1621
 
 
1622
 
    @param getDefaultStorageEngine()
1623
 
 
1624
 
    @return
1625
 
    pointer to plugin::StorageEngine
1626
 
  */
1627
 
  plugin::StorageEngine *getDefaultStorageEngine()
1628
 
  {
1629
 
    if (variables.storage_engine)
1630
 
      return variables.storage_engine;
1631
 
    return global_system_variables.storage_engine;
1632
 
  }
1633
 
 
1634
 
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1635
 
 
1636
 
  table::Singular *getInstanceTable();
1637
 
  table::Singular *getInstanceTable(List<CreateField> &field_list);
1638
 
 
1639
 
private:
1640
 
  bool resetUsage()
1641
 
  {
1642
 
    if (getrusage(RUSAGE_THREAD, &usage))
1643
 
    {
1644
 
      return false;
1645
 
    }
1646
 
 
1647
 
    return true;
1648
 
  }
1649
 
 
1650
 
public:
1651
 
 
1652
 
  void setUsage(bool arg)
1653
 
  {
1654
 
    use_usage= arg;
1655
 
  }
1656
 
 
1657
 
  const struct rusage &getUsage()
1658
 
  {
1659
 
    return usage;
1660
 
  }
1661
 
 
1662
 
  catalog::Instance::const_reference catalog() const
1663
 
  {
1664
 
    return *(_catalog.get());
1665
 
  }
1666
 
 
1667
 
  catalog::Instance::reference catalog()
1668
 
  {
1669
 
    return *(_catalog.get());
1670
 
  }
1671
 
 
1672
 
private:
1673
 
  catalog::Instance::shared_ptr _catalog;
1674
 
 
1675
 
  // This lives throughout the life of Session
1676
 
  bool use_usage;
1677
 
  session::PropertyMap life_properties;
1678
 
  std::vector<table::Singular *> temporary_shares;
1679
 
  struct rusage usage;
 
1435
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
 
1436
  bool reopen_name_locked_table(TableList* table_list, bool link_in);
 
1437
 
 
1438
  void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1680
1439
};
1681
1440
 
1682
 
class Join;
 
1441
class JOIN;
1683
1442
 
1684
1443
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1685
1444
 
1686
 
} /* namespace drizzled */
1687
 
 
1688
 
/** @TODO why is this in the middle of the file */
1689
1445
#include <drizzled/select_to_file.h>
1690
1446
#include <drizzled/select_export.h>
1691
1447
#include <drizzled/select_dump.h>
1692
1448
#include <drizzled/select_insert.h>
1693
1449
#include <drizzled/select_create.h>
 
1450
#include <plugin/myisam/myisam.h>
1694
1451
#include <drizzled/tmp_table_param.h>
1695
1452
#include <drizzled/select_union.h>
1696
1453
#include <drizzled/select_subselect.h>
1698
1455
#include <drizzled/select_max_min_finder_subselect.h>
1699
1456
#include <drizzled/select_exists_subselect.h>
1700
1457
 
1701
 
namespace drizzled
1702
 
{
1703
 
 
1704
1458
/**
1705
1459
 * A structure used to describe sort information
1706
1460
 * for a field or item used in ORDER BY.
1707
1461
 */
1708
 
class SortField 
 
1462
typedef struct st_sort_field 
1709
1463
{
1710
 
public:
1711
1464
  Field *field; /**< Field to sort */
1712
1465
  Item  *item; /**< Item if not sorting fields */
1713
1466
  size_t length; /**< Length of sort field */
1715
1468
  Item_result result_type; /**< Type of item */
1716
1469
  bool reverse; /**< if descending sort */
1717
1470
  bool need_strxnfrm;   /**< If we have to use strxnfrm() */
1718
 
 
1719
 
  SortField() :
1720
 
    field(0),
1721
 
    item(0),
1722
 
    length(0),
1723
 
    suffix_length(0),
1724
 
    result_type(STRING_RESULT),
1725
 
    reverse(0),
1726
 
    need_strxnfrm(0)
1727
 
  { }
1728
 
 
1729
 
};
1730
 
 
1731
 
} /* namespace drizzled */
1732
 
 
1733
 
/** @TODO why is this in the middle of the file */
 
1471
} SORT_FIELD;
 
1472
 
 
1473
typedef struct st_sort_buffer 
 
1474
{
 
1475
  uint32_t index;       /* 0 or 1 */
 
1476
  uint32_t sort_orders;
 
1477
  uint32_t change_pos; /* If sort-fields changed */
 
1478
  char **buff;
 
1479
  SORT_FIELD *sortorder;
 
1480
} SORT_BUFFER;
1734
1481
 
1735
1482
#include <drizzled/table_ident.h>
1736
1483
#include <drizzled/user_var_entry.h>
1737
1484
#include <drizzled/unique.h>
1738
 
#include <drizzled/var.h>
 
1485
#include <drizzled/multi_delete.h>
 
1486
#include <drizzled/multi_update.h>
 
1487
#include <drizzled/my_var.h>
1739
1488
#include <drizzled/select_dumpvar.h>
1740
1489
 
1741
 
namespace drizzled
1742
 
{
1743
 
 
1744
1490
/* Bits in sql_command_flags */
1745
1491
 
1746
1492
enum sql_command_flag_bits 
1759
1505
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1760
1506
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1761
1507
 
1762
 
namespace display  {
1763
 
const std::string &type(drizzled::Session::global_read_lock_t type);
1764
 
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1765
 
 
1766
 
} /* namespace display */
1767
 
 
1768
 
} /* namespace drizzled */
 
1508
/* Functions in sql_class.cc */
 
1509
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
 
1510
 
 
1511
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
 
1512
                        STATUS_VAR *dec_var);
1769
1513
 
1770
1514
#endif /* DRIZZLED_SESSION_H */