~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
20
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
21
#ifndef DRIZZLED_SESSION_H
22
#define DRIZZLED_SESSION_H
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
23
1 by brian
clean slate
24
/* Classes in mysql */
538 by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib.
25
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
26
#include "drizzled/plugin.h"
561.1.3 by Monty Taylor
Split some more things out of common_includes.h.
27
#include <drizzled/sql_locale.h>
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
28
#include "drizzled/resource_context.h"
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
29
#include <drizzled/cursor.h>
670.2.1 by Monty Taylor
Moved pthread keys
30
#include <drizzled/current_session.h>
584.1.14 by Monty Taylor
Removed field.h from common_includes.
31
#include <drizzled/sql_error.h>
831.1.3 by Brian Aker
Moved over file_exchange class.
32
#include <drizzled/file_exchange.h>
837 by Brian Aker
Reworked some classes out of session.h
33
#include <drizzled/select_result_interceptor.h>
1537.2.1 by Joe Daly
add statistics_variables.h
34
#include <drizzled/statistics_variables.h>
934.2.15 by Jay Pipes
Pulls remainder of XID and xid_cache implementation into xid.cc and xid.h from drizzled/session.cc.
35
#include <drizzled/xid.h>
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
36
#include "drizzled/query_id.h"
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
37
#include "drizzled/named_savepoint.h"
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
38
#include "drizzled/transaction_context.h"
934.2.4 by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false...
39
40
#include <netdb.h>
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
41
#include <map>
694 by Brian Aker
Refactor out char* strdup for string class in user.
42
#include <string>
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
43
#include <bitset>
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
44
#include <deque>
1 by brian
clean slate
45
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
46
#include <drizzled/security_context.h>
47
#include <drizzled/open_tables_state.h>
48
49
#include <drizzled/internal_error_handler.h>
50
#include <drizzled/diagnostics_area.h>
51
1317.2.11 by Monty Taylor
Moved isViewable check in to Session.h.
52
#include <drizzled/plugin/authorization.h>
53
934.2.4 by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false...
54
#define MIN_HANDSHAKE_SIZE      6
55
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
56
namespace drizzled
57
{
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
58
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
59
namespace plugin
60
{
61
class Client;
62
class Scheduler;
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
63
class EventObserverList;
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
64
}
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
65
1143.2.10 by Jay Pipes
Phase 2 new replication work:
66
namespace message
67
{
68
class Transaction;
69
class Statement;
70
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
71
namespace internal
72
{
73
struct st_my_thread_var;
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
74
}
75
1 by brian
clean slate
76
class Lex_input_stream;
584.1.12 by Monty Taylor
HA! Removed item.h from common_includes. woot.
77
class user_var_entry;
1052.2.2 by Nathan Williams
No actual code changes. Changed Copy_field to CopyField, to reflect the coding standards.
78
class CopyField;
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
79
class Table_ident;
1 by brian
clean slate
80
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
81
class TableShareInstance;
82
1 by brian
clean slate
83
extern char internal_table_name[2];
84
extern char empty_c_string[1];
85
extern const char **errmesg;
86
87
#define TC_HEURISTIC_RECOVER_COMMIT   1
88
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
482 by Brian Aker
Remove uint.
89
extern uint32_t tc_heuristic_recover;
1 by brian
clean slate
90
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
91
/**
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
92
  @brief
93
  Local storage for proto that are tmp table. This should be enlarged
94
  to hande the entire table-share for a local table. Once Hash is done,
95
  we should consider exchanging the map for it.
96
*/
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
97
typedef std::map <std::string, message::Table> ProtoCache;
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
98
99
/**
1 by brian
clean slate
100
  The COPY_INFO structure is used by INSERT/REPLACE code.
101
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
102
  UPDATE code:
103
    If a row is inserted then the copied variable is incremented.
104
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
105
      new data differs from the old one then the copied and the updated
106
      variables are incremented.
107
    The touched variable is incremented if a row was touched by the update part
108
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
109
      was actually changed or not.
110
*/
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
111
typedef struct st_copy_info 
112
{
1 by brian
clean slate
113
  ha_rows records; /**< Number of processed records */
114
  ha_rows deleted; /**< Number of deleted records */
115
  ha_rows updated; /**< Number of updated records */
116
  ha_rows copied;  /**< Number of copied records */
117
  ha_rows error_count;
118
  ha_rows touched; /* Number of touched records */
119
  enum enum_duplicates handle_duplicates;
120
  int escape_char, last_errno;
121
  bool ignore;
122
  /* for INSERT ... UPDATE */
123
  List<Item> *update_fields;
124
  List<Item> *update_values;
125
  /* for VIEW ... WITH CHECK OPTION */
126
} COPY_INFO;
127
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
128
typedef struct drizzled_lock_st
1 by brian
clean slate
129
{
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
130
  Table **table;
1054.1.6 by Brian Aker
Removed internal logic/dead variables for LOCK TABLES.
131
  uint32_t table_count;
132
  uint32_t lock_count;
1 by brian
clean slate
133
  THR_LOCK_DATA **locks;
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
134
} DRIZZLE_LOCK;
1 by brian
clean slate
135
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
136
} /* namespace drizzled */
137
138
/** @TODO why is this in the middle of the file */
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
139
#include <drizzled/lex_column.h>
1 by brian
clean slate
140
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
141
namespace drizzled
142
{
143
1 by brian
clean slate
144
class select_result;
145
class Time_zone;
146
520.1.21 by Brian Aker
THD -> Session rename
147
#define Session_SENTRY_MAGIC 0xfeedd1ff
148
#define Session_SENTRY_GONE  0xdeadbeef
1 by brian
clean slate
149
150
struct system_variables
151
{
896.1.4 by Monty Taylor
Fixed compiler warnings.
152
  system_variables() {};
1 by brian
clean slate
153
  /*
154
    How dynamically allocated system variables are handled:
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
155
1 by brian
clean slate
156
    The global_system_variables and max_system_variables are "authoritative"
157
    They both should have the same 'version' and 'size'.
158
    When attempting to access a dynamic variable, if the session version
159
    is out of date, then the session version is updated and realloced if
160
    neccessary and bytes copied from global to make up for missing data.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
161
  */
1 by brian
clean slate
162
  ulong dynamic_variables_version;
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
163
  char * dynamic_variables_ptr;
482 by Brian Aker
Remove uint.
164
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
165
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
166
151 by Brian Aker
Ulonglong to uint64_t
167
  uint64_t myisam_max_extra_sort_file_size;
168
  uint64_t max_heap_table_size;
169
  uint64_t tmp_table_size;
1 by brian
clean slate
170
  ha_rows select_limit;
171
  ha_rows max_join_size;
819.1.1 by Toru Maesaka
Removed the 16bit limitation of auto_increment_(increment|offset) system variables
172
  uint64_t auto_increment_increment;
173
  uint64_t auto_increment_offset;
616 by Brian Aker
ulong fixes.
174
  uint64_t bulk_insert_buff_size;
175
  uint64_t join_buff_size;
176
  uint32_t max_allowed_packet;
177
  uint64_t max_error_count;
178
  uint64_t max_length_for_sort_data;
910.4.4 by Stewart Smith
max_sort_length should be size_t everywhere. Causing numerous failures on SPARC and PowerPC due to strang value being retrieved in filesort. Basically, anything with filesort fails without this patch.
179
  size_t max_sort_length;
617 by Brian Aker
ulong fixes
180
  uint64_t min_examined_row_limit;
619 by Brian Aker
Removed ulong methods from vars.
181
  bool optimizer_prune_level;
1030.1.3 by Brian Aker
Final bits to structure alignment
182
  bool log_warnings;
183
619 by Brian Aker
Removed ulong methods from vars.
184
  uint32_t optimizer_search_depth;
1030.1.3 by Brian Aker
Final bits to structure alignment
185
  uint32_t div_precincrement;
619 by Brian Aker
Removed ulong methods from vars.
186
  uint64_t preload_buff_size;
187
  uint32_t read_buff_size;
188
  uint32_t read_rnd_buff_size;
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
189
  size_t sortbuff_size;
619 by Brian Aker
Removed ulong methods from vars.
190
  uint32_t thread_handling;
617 by Brian Aker
ulong fixes
191
  uint32_t tx_isolation;
619 by Brian Aker
Removed ulong methods from vars.
192
  uint32_t completion_type;
1 by brian
clean slate
193
  /* Determines which non-standard SQL behaviour should be enabled */
619 by Brian Aker
Removed ulong methods from vars.
194
  uint32_t sql_mode;
617 by Brian Aker
ulong fixes
195
  uint64_t max_seeks_for_key;
629.4.1 by Monty Taylor
First step in support size_t sys_var stuff.
196
  size_t range_alloc_block_size;
615 by Brian Aker
Added 32bit system variable support
197
  uint32_t query_alloc_block_size;
198
  uint32_t query_prealloc_size;
617 by Brian Aker
ulong fixes
199
  uint64_t group_concat_max_len;
555 by Monty
Fixed 32-bit issues.
200
  uint64_t pseudo_thread_id;
1 by brian
clean slate
201
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
202
  plugin::StorageEngine *storage_engine;
1 by brian
clean slate
203
204
  /* Only charset part of these variables is sensible */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
205
  const CHARSET_INFO  *character_set_filesystem;
1 by brian
clean slate
206
207
  /* Both charset and collation parts of these variables are important */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
208
  const CHARSET_INFO	*collation_server;
748 by Brian Aker
Removal of client side collation.
209
210
  inline const CHARSET_INFO  *getCollation(void) 
211
  {
1014.3.2 by Brian Aker
Factor out need for session in many "schema" calls. Removed variable about
212
    return collation_server;
748 by Brian Aker
Removal of client side collation.
213
  }
1 by brian
clean slate
214
215
  /* Locale Support */
216
  MY_LOCALE *lc_time_names;
217
218
  Time_zone *time_zone;
219
};
220
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
221
extern struct system_variables global_system_variables;
222
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
223
} /* namespace drizzled */
224
225
#include "drizzled/sql_lex.h"
226
227
namespace drizzled
228
{
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
229
520.1.22 by Brian Aker
Second pass of thd cleanup
230
void mark_transaction_to_rollback(Session *session, bool all);
1 by brian
clean slate
231
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
232
extern pthread_mutex_t LOCK_xid_cache;
233
extern HASH xid_cache;
234
235
/**
236
  Storage engine specific thread local data.
237
*/
238
struct Ha_data
239
{
240
  /**
241
    Storage engine specific thread local data.
242
    Lifetime: one user connection.
243
  */
244
  void *ha_ptr;
245
  /**
1273.1.27 by Jay Pipes
Completes the work of removing the weirdness around transaction
246
   * Resource contexts for both the "statement" and "normal"
247
   * transactions.
248
   *
249
   * Resource context at index 0:
250
   *
251
   * Life time: one statement within a transaction. If @@autocommit is
252
   * on, also represents the entire transaction.
253
   *
254
   * Resource context at index 1:
255
   *
256
   * Life time: one transaction within a connection. 
257
   *
258
   * @note
259
   *
260
   * If the storage engine does not participate in a transaction, 
261
   * there will not be a resource context.
262
   */
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
263
  drizzled::ResourceContext resource_context[2];
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
264
265
  Ha_data() :ha_ptr(NULL) {}
266
};
267
268
/**
269
 * Represents a client connection to the database server.
270
 *
271
 * Contains the client/server protocol object, the current statement
272
 * being executed, local-to-session variables and status counters, and
273
 * a host of other information.
274
 *
275
 * @todo
276
 *
1100.3.34 by Padraig O'Sullivan
Various updates after great code review from Jay. Thanks Jay!
277
 * The Session class should have a vector of Statement object pointers which
278
 * comprise the statements executed on the Session. Until this architectural
279
 * change is done, we can forget about parallel operations inside a session.
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
280
 *
281
 * @todo
282
 *
283
 * Make member variables private and have inlined accessors and setters.  Hide
284
 * all member variables that are not critical to non-internal operations of the
285
 * session object.
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
286
 */
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
287
class Session : public Open_tables_state
1 by brian
clean slate
288
{
289
public:
290
  /*
291
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
292
                        handler of fields used is set
293
    MARK_COLUMNS_READ:  Means a bit in read set is set to inform handler
294
	                that the field is to be read. If field list contains
520.1.22 by Brian Aker
Second pass of thd cleanup
295
                        duplicates, then session->dup_field is set to point
1 by brian
clean slate
296
                        to the last found duplicate.
297
    MARK_COLUMNS_WRITE: Means a bit is set in write set to inform handler
298
			that it needs to update this field in write_row
299
                        and update_row.
300
  */
301
  enum enum_mark_columns mark_used_columns;
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
302
  inline void* alloc(size_t size)
303
  {
1485 by Brian Aker
Updates to confine memroot
304
    return mem_root->alloc_root(size);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
305
  }
306
  inline void* calloc(size_t size)
307
  {
308
    void *ptr;
1485 by Brian Aker
Updates to confine memroot
309
    if ((ptr= mem_root->alloc_root(size)))
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
310
      memset(ptr, 0, size);
311
    return ptr;
312
  }
313
  inline char *strdup(const char *str)
314
  {
1487 by Brian Aker
More updates for memory::Root
315
    return mem_root->strdup_root(str);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
316
  }
317
  inline char *strmake(const char *str, size_t size)
318
  {
1487 by Brian Aker
More updates for memory::Root
319
    return mem_root->strmake_root(str,size);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
320
  }
321
  inline void *memdup(const void *str, size_t size)
322
  {
1487 by Brian Aker
More updates for memory::Root
323
    return mem_root->memdup_root(str, size);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
324
  }
325
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
326
  {
327
    void *ptr;
1485 by Brian Aker
Updates to confine memroot
328
    if ((ptr= mem_root->alloc_root(size + gap)))
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
329
      memcpy(ptr,str,size);
330
    return ptr;
331
  }
332
  /** Frees all items attached to this Statement */
333
  void free_items();
334
  /**
335
   * List of items created in the parser for this query. Every item puts
336
   * itself to the list on creation (see Item::Item() for details))
337
   */
338
  Item *free_list;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
339
  memory::Root *mem_root; /**< Pointer to current memroot */
1532.1.10 by Brian Aker
Encapsulation of mem_root for session/this switches the creation of new_path
340
341
342
  memory::Root *getMemRoot()
343
  {
344
    return mem_root;
345
  }
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
346
  /**
347
   * Uniquely identifies each statement object in thread scope; change during
348
   * statement lifetime.
349
   *
350
   * @todo should be const
351
   */
352
  uint32_t id;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
353
  LEX *lex; /**< parse tree descriptor */
1280.3.11 by Padraig O'Sullivan
Changed the query member of Session to be std::string
354
  /** query associated with this statement */
355
  std::string query;
1 by brian
clean slate
356
357
  /**
358
    Name of the current (default) database.
359
360
    If there is the current (default) database, "db" contains its name. If
361
    there is no current (default) database, "db" is NULL and "db_length" is
362
    0. In other words, "db", "db_length" must either be NULL, or contain a
363
    valid database name.
364
365
    @note this attribute is set and alloced by the slave SQL thread (for
520.1.21 by Brian Aker
THD -> Session rename
366
    the Session of that thread); that thread is (and must remain, for now) the
1 by brian
clean slate
367
    only responsible for freeing this member.
368
  */
1220.1.9 by Brian Aker
Remove char *db from session, and replaces it with std::string.
369
  std::string db;
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
370
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
371
  /**
520.1.21 by Brian Aker
THD -> Session rename
372
    Constant for Session::where initialization in the beginning of every query.
1 by brian
clean slate
373
520.1.21 by Brian Aker
THD -> Session rename
374
    It's needed because we do not save/restore Session::where normally during
1 by brian
clean slate
375
    primary (non subselect) query execution.
376
  */
377
  static const char * const DEFAULT_WHERE;
378
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
379
  memory::Root warn_root; /**< Allocation area for warnings and errors */
380
  plugin::Client *client; /**< Pointer to client object */
381
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
971.3.64 by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.
382
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
383
  HASH user_vars; /**< Hash of user variables defined during the session's lifetime */
384
  struct system_variables variables; /**< Mutable local variables local to the session */
385
  struct system_status_var status_var; /**< Session-local status counters */
386
  struct system_status_var *initial_status_var; /* used by show status */
387
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
388
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
389
  THR_LOCK_OWNER *lock_id; /**< If not main_lock_id, points to the lock_id of a cursor. */
390
  pthread_mutex_t LOCK_delete; /**< Locked before session is deleted */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
391
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
392
  /**
393
   * A peek into the query string for the session. This is a best effort
394
   * delivery, there is no guarantee whether the content is meaningful.
395
   */
998 by Brian Aker
Patch on show processlist from davi@apache.org
396
  char process_list_info[PROCESS_LIST_WIDTH+1];
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
397
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
398
  /**
971.3.64 by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.
399
   * A pointer to the stack frame of the scheduler thread
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
400
   * which is called first in the thread for handling a client
401
   */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
402
  char *thread_stack;
1 by brian
clean slate
403
1273.11.5 by Dennis Schoen
add getSecurityContext()
404
private:
1273.11.1 by Dennis Schoen
rename class
405
  SecurityContext security_ctx;
1377.6.3 by pawel
changed function-like defines into functions in some files
406
407
  inline void checkSentry() const
408
  {
409
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
410
  }
1273.11.5 by Dennis Schoen
add getSecurityContext()
411
public:
1273.11.6 by Dennis Schoen
add some const madness
412
  const SecurityContext& getSecurityContext() const
1273.11.5 by Dennis Schoen
add getSecurityContext()
413
  {
414
    return security_ctx;
415
  }
1 by brian
clean slate
416
1273.11.7 by Dennis Schoen
add second getSecurityContext() function that returns a non-const refernce
417
  SecurityContext& getSecurityContext()
418
  {
419
    return security_ctx;
420
  }
421
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
422
  /**
1317.2.11 by Monty Taylor
Moved isViewable check in to Session.h.
423
   * Is this session viewable by the current user?
424
   */
425
  bool isViewable() const
426
  {
427
    return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
1317.2.14 by Monty Taylor
Turned off send_error for isViewable. The error there always gets thrown in
428
                                               this,
429
                                               false);
1317.2.11 by Monty Taylor
Moved isViewable check in to Session.h.
430
  }
431
432
  /**
1 by brian
clean slate
433
    Used in error messages to tell user in what part of MySQL we found an
434
    error. E. g. when where= "having clause", if fix_fields() fails, user
435
    will know that the error was in having clause.
436
  */
437
  const char *where;
438
439
  /*
440
    One thread can hold up to one named user-level lock. This variable
441
    points to a lock object if the lock is present. See item_func.cc and
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
442
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
1 by brian
clean slate
443
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
444
  uint32_t dbug_sentry; /**< watch for memory corruption */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
445
  internal::st_my_thread_var *mysys_var;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
446
  /**
447
   * Type of current query: COM_STMT_PREPARE, COM_QUERY, etc. Set from
448
   * first byte of the packet in executeStatement()
449
   */
1 by brian
clean slate
450
  enum enum_server_command command;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
451
  uint32_t file_id;	/**< File ID for LOAD DATA INFILE */
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
452
  /* @note the following three members should likely move to Client */
1055.2.15 by Jay Pipes
Removed unused cached character set variables in Session along with dead update_charset() method.
453
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
454
  time_t start_time;
455
  time_t user_time;
456
  uint64_t thr_create_utime; /**< track down slow pthread_create */
457
  uint64_t start_utime;
458
  uint64_t utime_after_lock;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
459
1 by brian
clean slate
460
  thr_lock_type update_lock_default;
461
661 by Brian Aker
First major pass through new replication.
462
  /*
463
    Both of the following container points in session will be converted to an API.
464
  */
465
1240.9.6 by Monty Taylor
Removed some casts- also removed a few c-interface functions and made them actual methods on session. Also made the ha_data private. (fancy that)
466
private:
1 by brian
clean slate
467
  /* container for handler's private per-connection data */
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
468
  std::vector<Ha_data> ha_data;
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
469
  /*
470
    Id of current query. Statement can be reused to execute several queries
471
    query_id is global in context of the whole MySQL server.
472
    ID is automatically generated from an atomic counter.
473
    It's used in Cursor code for various purposes: to check which columns
474
    from table are necessary for this select, to check if it's necessary to
475
    update auto-updatable fields (like auto_increment and timestamp).
476
  */
477
  query_id_t query_id;
478
  query_id_t warn_query_id;
1240.9.6 by Monty Taylor
Removed some casts- also removed a few c-interface functions and made them actual methods on session. Also made the ha_data private. (fancy that)
479
public:
1273.1.30 by Jay Pipes
* Completes the blueprint for splitting the XA Resource Manager
480
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
481
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
1273.1.11 by Jay Pipes
Merge trunk changes and resolve conflicts
482
                                      size_t index= 0);
1240.9.6 by Monty Taylor
Removed some casts- also removed a few c-interface functions and made them actual methods on session. Also made the ha_data private. (fancy that)
483
1 by brian
clean slate
484
  struct st_transactions {
1273.1.11 by Jay Pipes
Merge trunk changes and resolve conflicts
485
    std::deque<NamedSavepoint> savepoints;
486
    TransactionContext all; ///< Trans since BEGIN WORK
487
    TransactionContext stmt; ///< Trans for current statement
1 by brian
clean slate
488
    XID_STATE xid_state;
489
490
    void cleanup()
491
    {
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
492
      savepoints.clear();
1 by brian
clean slate
493
    }
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
494
    st_transactions() :
495
      savepoints(),
496
      all(),
497
      stmt(),
498
      xid_state()
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
499
    { }
1 by brian
clean slate
500
  } transaction;
1273.1.10 by Jay Pipes
* Renames Ha_trx_info to drizzled::ResourceContext
501
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
502
  Field *dup_field;
1 by brian
clean slate
503
  sigset_t signals;
504
505
  /* Tells if LAST_INSERT_ID(#) was called for the current statement */
506
  bool arg_of_last_insert_id_function;
507
  /*
508
    ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
509
    insertion into an auto_increment column".
510
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
511
  /**
1 by brian
clean slate
512
    This is the first autogenerated insert id which was *successfully*
513
    inserted by the previous statement (exactly, if the previous statement
514
    didn't successfully insert an autogenerated insert id, then it's the one
515
    of the statement before, etc).
516
    It can also be set by SET LAST_INSERT_ID=# or SELECT LAST_INSERT_ID(#).
517
    It is returned by LAST_INSERT_ID().
518
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
519
  uint64_t first_successful_insert_id_in_prev_stmt;
520
  /**
1 by brian
clean slate
521
    This is the first autogenerated insert id which was *successfully*
522
    inserted by the current statement. It is maintained only to set
523
    first_successful_insert_id_in_prev_stmt when statement ends.
524
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
525
  uint64_t first_successful_insert_id_in_cur_stmt;
526
  /**
1 by brian
clean slate
527
    We follow this logic:
528
    - when stmt starts, first_successful_insert_id_in_prev_stmt contains the
529
    first insert id successfully inserted by the previous stmt.
530
    - as stmt makes progress, handler::insert_id_for_cur_row changes;
531
    every time get_auto_increment() is called,
532
    auto_inc_intervals_in_cur_stmt_for_binlog is augmented with the
533
    reserved interval (if statement-based binlogging).
534
    - at first successful insertion of an autogenerated value,
535
    first_successful_insert_id_in_cur_stmt is set to
536
    handler::insert_id_for_cur_row.
537
    - when stmt goes to binlog,
538
    auto_inc_intervals_in_cur_stmt_for_binlog is binlogged if
539
    non-empty.
540
    - when stmt ends, first_successful_insert_id_in_prev_stmt is set to
541
    first_successful_insert_id_in_cur_stmt.
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
542
1 by brian
clean slate
543
    List of auto_increment intervals reserved by the thread so far, for
544
    storage in the statement-based binlog.
545
    Note that its minimum is not first_successful_insert_id_in_cur_stmt:
546
    assuming a table with an autoinc column, and this happens:
547
    INSERT INTO ... VALUES(3);
548
    SET INSERT_ID=3; INSERT IGNORE ... VALUES (NULL);
549
    then the latter INSERT will insert no rows
550
    (first_successful_insert_id_in_cur_stmt == 0), but storing "INSERT_ID=3"
551
    in the binlog is still needed; the list's minimum will contain 3.
552
  */
553
  Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
554
  /** Used by replication and SET INSERT_ID */
1 by brian
clean slate
555
  Discrete_intervals_list auto_inc_intervals_forced;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
556
557
  uint64_t limit_found_rows;
1055.2.15 by Jay Pipes
Removed unused cached character set variables in Session along with dead update_charset() method.
558
  uint64_t options; /**< Bitmap of options */
559
  int64_t row_count_func; /**< For the ROW_COUNT() function */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
560
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
561
562
  /** 
563
   * Number of rows we actually sent to the client, including "synthetic"
564
   * rows in ROLLUP etc.
565
   */
566
  ha_rows sent_row_count;
567
568
  /**
569
   * Number of rows we read, sent or not, including in create_sort_index()
570
   */
571
  ha_rows examined_row_count;
572
573
  /**
574
   * The set of those tables whose fields are referenced in all subqueries
575
   * of the query.
576
   *
577
   * @todo
578
   * 
579
   * Possibly this it is incorrect to have used tables in Session because
580
   * with more than one subquery, it is not clear what does the field mean.
581
   */
582
  table_map used_tables;
583
584
  /**
585
    @todo
586
    
587
    This, and some other variables like 'count_cuted_fields'
1 by brian
clean slate
588
    maybe should be statement/cursor local, that is, moved to Statement
589
    class. With current implementation warnings produced in each prepared
590
    statement/cursor settle here.
591
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
592
  List<DRIZZLE_ERROR> warn_list;
593
  uint32_t warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_END];
594
  uint32_t total_warn_count;
1 by brian
clean slate
595
  Diagnostics_area main_da;
596
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
597
  ulong col_access;
1 by brian
clean slate
598
599
  /* Statement id is thread-wide. This counter is used to generate ids */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
600
  uint32_t statement_id_counter;
601
  uint32_t rand_saved_seed1;
602
  uint32_t rand_saved_seed2;
603
  /**
1 by brian
clean slate
604
    Row counter, mainly for errors and warnings. Not increased in
605
    create_sort_index(); may differ from examined_row_count.
606
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
607
  uint32_t row_count;
608
  pthread_t real_id; /**< For debugging */
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
609
  uint64_t thread_id;
1046.1.7 by Brian Aker
Style cleanup.
610
  uint32_t tmp_table;
611
  uint32_t global_read_lock;
612
  uint32_t server_status;
613
  uint32_t open_options;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
614
  uint32_t select_number; /**< number of select (used for EXPLAIN) */
1 by brian
clean slate
615
  /* variables.transaction_isolation is reset to this after each commit */
616
  enum_tx_isolation session_tx_isolation;
617
  enum_check_fields count_cuted_fields;
618
619
  enum killed_state
620
  {
550 by Monty Taylor
Moved error.h into just the files that need it.
621
    NOT_KILLED,
622
    KILL_BAD_DATA,
623
    KILL_CONNECTION,
624
    KILL_QUERY,
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
625
    KILLED_NO_VALUE /* means none of the above states apply */
1 by brian
clean slate
626
  };
627
  killed_state volatile killed;
628
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
629
  bool some_tables_deleted;
630
  bool no_errors;
631
  bool password;
1 by brian
clean slate
632
  /**
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
633
    Set to true if execution of the current compound statement
1 by brian
clean slate
634
    can not continue. In particular, disables activation of
635
    CONTINUE or EXIT handlers of stored routines.
636
    Reset in the end of processing of the current user request, in
520.1.22 by Brian Aker
Second pass of thd cleanup
637
    @see mysql_reset_session_for_next_command().
1 by brian
clean slate
638
  */
639
  bool is_fatal_error;
640
  /**
641
    Set by a storage engine to request the entire
642
    transaction (that possibly spans multiple engines) to
643
    rollback. Reset in ha_rollback.
644
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
645
  bool transaction_rollback_request;
1 by brian
clean slate
646
  /**
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
647
    true if we are in a sub-statement and the current error can
1 by brian
clean slate
648
    not be safely recovered until we left the sub-statement mode.
649
    In particular, disables activation of CONTINUE and EXIT
650
    handlers inside sub-statements. E.g. if it is a deadlock
651
    error and requires a transaction-wide rollback, this flag is
652
    raised (traditionally, MySQL first has to close all the reads
653
    via @see handler::ha_index_or_rnd_end() and only then perform
654
    the rollback).
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
655
    Reset to false when we leave the sub-statement mode.
1 by brian
clean slate
656
  */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
657
  bool is_fatal_sub_stmt_error;
658
  /** for IS NULL => = last_insert_id() fix in remove_eq_conds() */
659
  bool substitute_null_with_insert_id;
660
  bool cleanup_done;
661
662
  bool abort_on_warning;
663
  bool got_warning; /**< Set on call to push_warning() */
664
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
665
  /** set during loop of derived table processing */
666
  bool derived_tables_processing;
1055.2.15 by Jay Pipes
Removed unused cached character set variables in Session along with dead update_charset() method.
667
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
668
669
  /** Used by the sys_var class to store temporary values */
1 by brian
clean slate
670
  union
671
  {
1055.2.17 by Jay Pipes
More style cleanups in Session
672
    bool bool_value;
673
    uint32_t uint32_t_value;
674
    int32_t int32_t_value;
151 by Brian Aker
Ulonglong to uint64_t
675
    uint64_t uint64_t_value;
1 by brian
clean slate
676
  } sys_var_tmp;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
677
1 by brian
clean slate
678
  /**
679
    Character input stream consumed by the lexical analyser,
680
    used during parsing.
681
    Note that since the parser is not re-entrant, we keep only one input
682
    stream here. This member is valid only when executing code during parsing,
683
    and may point to invalid memory after that.
684
  */
685
  Lex_input_stream *m_lip;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
686
  
687
  /** Place to store various things */
688
  void *session_marker;
1183.1.29 by Brian Aker
Clean up interface so that Truncate sets the propper engine when
689
1055.2.17 by Jay Pipes
More style cleanups in Session
690
  /** Keeps a copy of the previous table around in case we are just slamming on particular table */
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
691
  Table *cached_table;
692
693
  /**
694
    Points to info-string that we show in SHOW PROCESSLIST
695
    You are supposed to call Session_SET_PROC_INFO only if you have coded
696
    a time-consuming piece that MySQL can get stuck in for a long time.
697
698
    Set it using the  session_proc_info(Session *thread, const char *message)
699
    macro/function.
700
  */
701
  inline void set_proc_info(const char *info)
702
  { 
703
    proc_info= info;
704
  }
705
  inline const char* get_proc_info() const
706
  {
707
    return proc_info;
708
  }
709
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
710
  /** Sets this Session's current query ID */
711
  inline void setQueryId(query_id_t in_query_id)
712
  {
713
    query_id= in_query_id;
714
  }
715
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
716
  /** Returns the current query ID */
717
  inline query_id_t getQueryId()  const
718
  {
719
    return query_id;
720
  }
721
1273.1.1 by Jay Pipes
* Changes Session::warn_id to Session::warn_query_id
722
723
  /** Sets this Session's warning query ID */
724
  inline void setWarningQueryId(query_id_t in_query_id)
725
  {
726
    warn_query_id= in_query_id;
727
  }
728
729
  /** Returns the Session's warning query ID */
730
  inline query_id_t getWarningQueryId()  const
731
  {
732
    return warn_query_id;
733
  }
734
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
735
  /** Returns the current query text */
1280.3.11 by Padraig O'Sullivan
Changed the query member of Session to be std::string
736
  inline const std::string &getQueryString()  const
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
737
  {
738
    return query;
739
  }
740
741
  /** Returns the length of the current query text */
742
  inline size_t getQueryLength() const
743
  {
1280.3.11 by Padraig O'Sullivan
Changed the query member of Session to be std::string
744
    if (! query.empty())
745
      return query.length();
1124.2.4 by Diego Medina
Fixes bug #421345 - Crash when calling getQueryLength() on query = NULL
746
    else
747
      return 0;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
748
  }
749
1039.5.56 by Jay Pipes
Adds Session ID accessor, and output to replication messages
750
  /** Accessor method returning the session's ID. */
751
  inline uint64_t getSessionId()  const
752
  {
753
    return thread_id;
754
  }
755
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
756
  /** Accessor method returning the server's ID. */
757
  inline uint32_t getServerId()  const
758
  {
759
    /* We return the global server ID. */
760
    return server_id;
761
  }
762
763
  /** Returns the current transaction ID for the session's current statement */
764
  inline my_xid getTransactionId()
765
  {
766
    return transaction.xid_state.xid.quick_get_my_xid();
767
  }
768
  /**
769
    There is BUG#19630 where statement-based replication of stored
770
    functions/triggers with two auto_increment columns breaks.
771
    We however ensure that it works when there is 0 or 1 auto_increment
772
    column; our rules are
773
    a) on master, while executing a top statement involving substatements,
774
    first top- or sub- statement to generate auto_increment values wins the
775
    exclusive right to see its values be written to binlog (the write
776
    will be done by the statement or its caller), and the losers won't see
777
    their values be written to binlog.
778
    b) on slave, while replicating a top statement involving substatements,
779
    first top- or sub- statement to need to read auto_increment values from
780
    the master's binlog wins the exclusive right to read them (so the losers
781
    won't read their values from binlog but instead generate on their own).
782
    a) implies that we mustn't backup/restore
783
    auto_inc_intervals_in_cur_stmt_for_binlog.
784
    b) implies that we mustn't backup/restore auto_inc_intervals_forced.
785
786
    If there are more than 1 auto_increment columns, then intervals for
787
    different columns may mix into the
788
    auto_inc_intervals_in_cur_stmt_for_binlog list, which is logically wrong,
789
    but there is no point in preventing this mixing by preventing intervals
790
    from the secondly inserted column to come into the list, as such
791
    prevention would be wrong too.
792
    What will happen in the case of
793
    INSERT INTO t1 (auto_inc) VALUES(NULL);
794
    where t1 has a trigger which inserts into an auto_inc column of t2, is
795
    that in binlog we'll store the interval of t1 and the interval of t2 (when
796
    we store intervals, soon), then in slave, t1 will use both intervals, t2
797
    will use none; if t1 inserts the same number of rows as on master,
798
    normally the 2nd interval will not be used by t1, which is fine. t2's
799
    values will be wrong if t2's internal auto_increment counter is different
800
    from what it was on master (which is likely). In 5.1, in mixed binlogging
801
    mode, row-based binlogging is used for such cases where two
802
    auto_increment columns are inserted.
803
  */
804
  inline void record_first_successful_insert_id_in_cur_stmt(uint64_t id_arg)
805
  {
806
    if (first_successful_insert_id_in_cur_stmt == 0)
807
      first_successful_insert_id_in_cur_stmt= id_arg;
808
  }
809
  inline uint64_t read_first_successful_insert_id_in_prev_stmt(void)
810
  {
811
    return first_successful_insert_id_in_prev_stmt;
812
  }
813
  /**
814
    Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#"
815
    (mysqlbinlog). We'll soon add a variant which can take many intervals in
816
    argument.
817
  */
818
  inline void force_one_auto_inc_interval(uint64_t next_id)
819
  {
820
    auto_inc_intervals_forced.empty(); // in case of multiple SET INSERT_ID
821
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
822
  }
1 by brian
clean slate
823
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
824
  Session(plugin::Client *client_arg);
1100.3.29 by Padraig O'Sullivan
Removed the Statement class. Copied any members it had that were needed by
825
  virtual ~Session();
1 by brian
clean slate
826
827
  void cleanup(void);
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
828
  /**
829
   * Cleans up after query.
830
   *
831
   * @details
832
   *
833
   * This function is used to reset thread data to its default state.
834
   *
835
   * This function is not suitable for setting thread data to some
836
   * non-default values, as there is only one replication thread, so
837
   * different master threads may overwrite data of each other on
838
   * slave.
839
   */
1 by brian
clean slate
840
  void cleanup_after_query();
971.3.64 by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.
841
  bool storeGlobals();
520.1.21 by Brian Aker
THD -> Session rename
842
  void awake(Session::killed_state state_to_set);
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
843
  /**
844
   * Pulls thread-specific variables into Session state.
845
   *
846
   * Returns true most times, or false if there was a problem
847
   * allocating resources for thread-specific storage.
848
   *
849
   * @TODO Kill this.  It's not necessary once my_thr_init() is bye bye.
850
   *
851
   */
852
  bool initGlobals();
853
854
  /**
971.3.64 by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.
855
    Initialize memory roots necessary for query processing and (!)
856
    pre-allocate memory for it. We can't do that in Session constructor because
971.3.70 by Eric Day
Fixed style issues found by Jay.
857
    there are use cases where it's vital to not allocate excessive and not used
858
    memory.
971.3.64 by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.
859
  */
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
860
  void prepareForQueries();
1 by brian
clean slate
861
934.2.4 by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false...
862
  /**
934.2.8 by Jay Pipes
Refactors the do_command() function out of the sql_parse.cc stuff and implements it as a member method, executeStatement() on the Session object.
863
   * Executes a single statement received from the 
864
   * client connection.
865
   *
866
   * Returns true if the statement was successful, or false 
867
   * otherwise.
868
   *
869
   * @note
870
   *
871
   * For profiling to work, it must never be called recursively.
872
   *
873
   * In MySQL, this used to be the do_command() C function whic
874
   * accepted a single parameter of the THD pointer.
875
   */
876
  bool executeStatement();
877
878
  /**
934.2.9 by Jay Pipes
Pulls alloc_query() C function out of sql_parse.cc and adds readAndStoreQuery() member method of Session class.
879
   * Reads a query from packet and stores it.
880
   *
881
   * Returns true if query is read and allocated successfully, 
882
   * false otherwise.  On a return of false, Session::fatal_error
883
   * is set.
884
   *
885
   * @note Used in COM_QUERY and COM_STMT_PREPARE.
886
   *
887
   * Sets the following Session variables:
888
   *  - query
889
   *  - query_length
890
   *
891
   * @param The packet pointer to read from
892
   * @param The length of the query to read
893
   */
894
  bool readAndStoreQuery(const char *in_packet, uint32_t in_packet_length);
895
896
  /**
934.2.11 by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object.
897
   * Ends the current transaction and (maybe) begins the next.
898
   *
899
   * Returns true if the transaction completed successfully, 
900
   * otherwise false.
901
   *
902
   * @param Completion type
903
   */
904
  bool endTransaction(enum enum_mysql_completiontype completion);
905
  bool endActiveTransaction();
1206.1.3 by Brian Aker
Valgrind fix for startTransaction()
906
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
934.2.11 by Jay Pipes
Moves end_trans(), begin_trans(), end_active_trans() out of the parser module and adds startTransaction(), endTransaction(), and endActiveTransaction() member methods of Session object.
907
908
  /**
934.2.4 by Jay Pipes
This changeset pulls check_user(), check_connection(), and login_connection() out of sql_connect.cc and makes them member methods of Session, where they belong. Also, made sure that functions that return a bool return true when it succeeds, and not false...
909
   * Authenticates users, with error reporting.
910
   *
911
   * Returns true on success, or false on failure.
912
   */
913
  bool authenticate();
914
971.3.64 by Eric Day
Cleaned up Scheduler plugin, moved more code to the schedular plugins, reworked some functions to be methods in Session, removed some dead code.
915
  /**
916
   * Run a session.
917
   *
918
   * This will initialize the session and begin the command loop.
919
   */
920
  void run();
921
922
  /**
923
   * Schedule a session to be run on the default scheduler.
924
   */
925
  bool schedule();
926
1 by brian
clean slate
927
  /*
928
    For enter_cond() / exit_cond() to work the mutex must be got before
929
    enter_cond(); this mutex is then released by exit_cond().
930
    Usage must be: lock mutex; enter_cond(); your code; exit_cond().
931
  */
1241.9.55 by Monty Taylor
Moved tree into drizzled/
932
  const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg);
933
  void exit_cond(const char* old_msg);
934
735 by Brian Aker
Refactor session.
935
  inline time_t query_start() { return start_time; }
1 by brian
clean slate
936
  inline void set_time()
937
  {
938
    if (user_time)
939
    {
940
      start_time= user_time;
1055.3.6 by Jay Pipes
Adds public getConnectMicroseconds() call to Session object. Protects connect_microseconds member variable and sets it correctly. Corrects logging_xxx plugins to use getConnectMicroseconds() API call properly. Fixes Bug #402855
941
      connect_microseconds= start_utime= utime_after_lock= my_micro_time();
1 by brian
clean slate
942
    }
943
    else
944
      start_utime= utime_after_lock= my_micro_time_and_time(&start_time);
945
  }
713.1.3 by Monty Taylor
Fixed one more my_time thing.
946
  inline void	set_current_time()    { start_time= time(NULL); }
1 by brian
clean slate
947
  inline void	set_time(time_t t)
948
  {
949
    start_time= user_time= t;
950
    start_utime= utime_after_lock= my_micro_time();
951
  }
952
  void set_time_after_lock()  { utime_after_lock= my_micro_time(); }
988.1.5 by Jay Pipes
Removal of log.cc (binlog), added Applier plugin and fixed up Replicator
953
  /**
954
   * Returns the current micro-timestamp
955
   */
956
  inline uint64_t getCurrentTimestamp()  
957
  { 
958
    return my_micro_time(); 
959
  }
151 by Brian Aker
Ulonglong to uint64_t
960
  inline uint64_t found_rows(void)
1 by brian
clean slate
961
  {
962
    return limit_found_rows;
963
  }
934.2.28 by Jay Pipes
Renamed some things to our standards and made private methods private...
964
  /** Returns whether the session is currently inside a transaction */
965
  inline bool inTransaction()
1 by brian
clean slate
966
  {
967
    return server_status & SERVER_STATUS_IN_TRANS;
968
  }
969
  inline bool fill_derived_tables()
970
  {
971
    return !lex->only_view_structure();
972
  }
973
974
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
482 by Brian Aker
Remove uint.
975
                              const char* str, uint32_t length,
1 by brian
clean slate
976
                              bool allocate_lex_string);
1273.13.38 by Brian Aker
Add in new show work.
977
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
978
                              const std::string &str,
979
                              bool allocate_lex_string);
1 by brian
clean slate
980
981
  int send_explain_fields(select_result *result);
982
  /**
983
    Clear the current error, if any.
984
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
985
    assume this is never called if the fatal error is set.
986
    @todo: To silence an error, one should use Internal_error_handler
987
    mechanism. In future this function will be removed.
988
  */
989
  inline void clear_error()
990
  {
991
    if (main_da.is_error())
992
      main_da.reset_diagnostics_area();
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
993
    return;
1 by brian
clean slate
994
  }
383.1.55 by Monty Taylor
Removed libvio deps from drizzled.
995
1 by brian
clean slate
996
  /**
997
    Mark the current error as fatal. Warning: this does not
998
    set any error, it sets a property of the error, so must be
999
    followed or prefixed with my_error().
1000
  */
1001
  inline void fatal_error()
1002
  {
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1003
    assert(main_da.is_error());
1055.2.17 by Jay Pipes
More style cleanups in Session
1004
    is_fatal_error= true;
1 by brian
clean slate
1005
  }
1006
  /**
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1007
    true if there is an error in the error stack.
1 by brian
clean slate
1008
1009
    Please use this method instead of direct access to
1010
    net.report_error.
1011
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1012
    If true, the current (sub)-statement should be aborted.
1 by brian
clean slate
1013
    The main difference between this member and is_fatal_error
1014
    is that a fatal error can not be handled by a stored
1015
    procedure continue handler, whereas a normal error can.
1016
1017
    To raise this flag, use my_error().
1018
  */
1019
  inline bool is_error() const { return main_da.is_error(); }
748 by Brian Aker
Removal of client side collation.
1020
  inline const CHARSET_INFO *charset() { return default_charset_info; }
1 by brian
clean slate
1021
1022
  void change_item_tree(Item **place, Item *new_value)
1023
  {
1024
    *place= new_value;
1025
  }
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
1026
  /**
1 by brian
clean slate
1027
    Cleanup statement parse state (parse tree, lex) and execution
1028
    state after execution of a non-prepared SQL statement.
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
1029
1030
    @todo
1031
1032
    Move this to Statement::~Statement
1 by brian
clean slate
1033
  */
1034
  void end_statement();
1035
  inline int killed_errno() const
1036
  {
1037
    killed_state killed_val; /* to cache the volatile 'killed' */
1038
    return (killed_val= killed) != KILL_BAD_DATA ? killed_val : 0;
1039
  }
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1040
  void send_kill_message() const;
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1041
  /* return true if we will abort query if we make a warning now */
1 by brian
clean slate
1042
  inline bool really_abort_on_warning()
1043
  {
1044
    return (abort_on_warning);
1045
  }
1046
  void set_status_var_init();
1047
1048
  /**
1049
    Set the current database; use deep copy of C-string.
1050
1051
    @param new_db     a pointer to the new database name.
1052
    @param new_db_len length of the new database name.
1053
1054
    Initialize the current database from a NULL-terminated string with
1055
    length. If we run out of memory, we free the current database and
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1056
    return true.  This way the user will notice the error as there will be
1 by brian
clean slate
1057
    no current database selected (in addition to the error message set by
1058
    malloc).
1059
1060
    @note This operation just sets {db, db_length}. Switching the current
1061
    database usually involves other actions, like switching other database
1062
    attributes including security context. In the future, this operation
1063
    will be made private and more convenient interface will be provided.
1064
1065
    @return Operation status
51.1.50 by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE
1066
      @retval false Success
1067
      @retval true  Out-of-memory error
1 by brian
clean slate
1068
  */
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1069
  bool set_db(const std::string &new_db);
1 by brian
clean slate
1070
1071
  /*
1072
    Copy the current database to the argument. Use the current arena to
1073
    allocate memory for a deep copy: current database may be freed after
1074
    a statement is parsed but before it's executed.
1075
  */
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
1076
  bool copy_db_to(char **p_db, size_t *p_db_length);
1 by brian
clean slate
1077
1078
public:
1079
  /**
1080
    Add an internal error handler to the thread execution context.
1081
    @param handler the exception handler to add
1082
  */
1083
  void push_internal_handler(Internal_error_handler *handler);
1084
1085
  /**
1086
    Handle an error condition.
1087
    @param sql_errno the error number
1088
    @param level the error level
1089
    @return true if the error is handled
1090
  */
482 by Brian Aker
Remove uint.
1091
  virtual bool handle_error(uint32_t sql_errno, const char *message,
261.4.1 by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR.
1092
                            DRIZZLE_ERROR::enum_warning_level level);
1 by brian
clean slate
1093
1094
  /**
1095
    Remove the error handler last pushed.
1096
  */
1097
  void pop_internal_handler();
1098
693 by Brian Aker
Cleaning up session class.
1099
  /**
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1100
    Resets Session part responsible for command processing state.
1101
1102
    This needs to be called before execution of every statement
1103
    (prepared or conventional).
1104
    It is not called by substatements of routines.
1105
1106
    @todo
1107
    Make it a method of Session and align its name with the rest of
1108
    reset/end/start/init methods.
1109
    @todo
1110
    Call it after we use Session for queries, not before.
735 by Brian Aker
Refactor session.
1111
  */
1112
  void reset_for_next_command();
1113
1114
  /**
934.2.6 by Jay Pipes
This changeset removes a few more C functions from sql_connect.cc/connect.h
1115
   * Disconnects the session from a client connection and
1116
   * updates any status variables necessary.
1117
   *
1118
   * @param errcode	Error code to print to console
1119
   * @param should_lock 1 if we have have to lock LOCK_thread_count
1120
   *
1121
   * @note  For the connection that is doing shutdown, this is called twice
1122
   */
1123
  void disconnect(uint32_t errcode, bool lock);
693 by Brian Aker
Cleaning up session class.
1124
934.2.28 by Jay Pipes
Renamed some things to our standards and made private methods private...
1125
  /**
1126
   * Check if user exists and the password supplied is correct.
1127
   *
1128
   * Returns true on success, and false on failure.
1129
   *
1130
   * @note Host, user and passwd may point to communication buffer.
1131
   * Current implementation does not depend on that, but future changes
1132
   * should be done with this in mind; 
1133
   *
1134
   * @param  Scrambled password received from client
1135
   * @param  Length of scrambled password
1136
   * @param  Database name to connect to, may be NULL
1137
   */
965 by Brian Aker
Merge with Jay
1138
  bool checkUser(const char *passwd, uint32_t passwd_len, const char *db);
1055.3.6 by Jay Pipes
Adds public getConnectMicroseconds() call to Session object. Protects connect_microseconds member variable and sets it correctly. Corrects logging_xxx plugins to use getConnectMicroseconds() API call properly. Fixes Bug #402855
1139
  
1140
  /**
1141
   * Returns the timestamp (in microseconds) of when the Session 
1142
   * connected to the server.
1143
   */
1144
  inline uint64_t getConnectMicroseconds() const
1145
  {
1146
    return connect_microseconds;
1147
  }
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
1148
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1149
  /**
1150
   * Returns a pointer to the active Transaction message for this
1151
   * Session being managed by the ReplicationServices component, or
1152
   * NULL if no active message.
1153
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1154
  message::Transaction *getTransactionMessage() const
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1155
  {
1156
    return transaction_message;
1157
  }
1158
1159
  /**
1160
   * Returns a pointer to the active Statement message for this
1161
   * Session, or NULL if no active message.
1162
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1163
  message::Statement *getStatementMessage() const
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1164
  {
1165
    return statement_message;
1166
  }
1167
1168
  /**
1169
   * Sets the active transaction message used by the ReplicationServices
1170
   * component.
1171
   *
1172
   * @param[in] Pointer to the message
1173
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1174
  void setTransactionMessage(message::Transaction *in_message)
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1175
  {
1176
    transaction_message= in_message;
1177
  }
1178
1179
  /**
1180
   * Sets the active statement message used by the ReplicationServices
1181
   * component.
1182
   *
1183
   * @param[in] Pointer to the message
1184
   */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1185
  void setStatementMessage(message::Statement *in_message)
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1186
  {
1187
    statement_message= in_message;
1188
  }
971.3.6 by Eric Day
Moved the last of the libdrizzleclient calls into Protocol.
1189
private:
1143.2.10 by Jay Pipes
Phase 2 new replication work:
1190
  /** Pointers to memory managed by the ReplicationServices component */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1191
  message::Transaction *transaction_message;
1192
  message::Statement *statement_message;
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1193
  plugin::EventObserverList *session_event_observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1194
  
1195
  /* Schema observers are mapped to databases. */
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1196
  std::map<std::string, plugin::EventObserverList *> schema_event_observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1197
1198
 
1199
public:
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1200
  plugin::EventObserverList *getSessionObservers() 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1201
  { 
1202
    return session_event_observers;
1203
  }
1204
  
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1205
  void setSessionObservers(plugin::EventObserverList *observers) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1206
  { 
1207
    session_event_observers= observers;
1208
  }
1209
  
1210
  /* For schema event observers there is one set of observers per database. */
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1211
  plugin::EventObserverList *getSchemaObservers(const std::string &db_name) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1212
  { 
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1213
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1214
    
1502.5.7 by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer.
1215
    it= schema_event_observers.find(db_name);
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1216
    if (it == schema_event_observers.end())
1217
      return NULL;
1218
      
1219
    return it->second;
1220
  }
1221
  
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1222
  void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1223
  { 
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
1224
    std::map<std::string, plugin::EventObserverList *>::iterator it;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1225
1502.5.7 by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer.
1226
    it= schema_event_observers.find(db_name);
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1227
    if (it != schema_event_observers.end())
1228
      schema_event_observers.erase(it);;
1229
1230
    if (observers)
1502.5.7 by Barry.Leslie at PrimeBase
Renamed the 'Event' plugin to 'EventObserver' plugin along with some internal class renames to make things clearer.
1231
      schema_event_observers[db_name] = observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
1232
  }
1233
  
1234
  
1235
 private:
1236
 /** Microsecond timestamp of when Session connected */
1055.3.6 by Jay Pipes
Adds public getConnectMicroseconds() call to Session object. Protects connect_microseconds member variable and sets it correctly. Corrects logging_xxx plugins to use getConnectMicroseconds() API call properly. Fixes Bug #402855
1237
  uint64_t connect_microseconds;
322.2.2 by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter.
1238
  const char *proc_info;
1239
1 by brian
clean slate
1240
  /** The current internal error handler for this thread, or NULL. */
1241
  Internal_error_handler *m_internal_handler;
1242
  /**
1243
    The lex to hold the parsed tree of conventional (non-prepared) queries.
1244
    Whereas for prepared and stored procedure statements we use an own lex
1245
    instance for each new query, for conventional statements we reuse
1246
    the same lex. (@see mysql_parse for details).
1247
  */
1248
  LEX main_lex;
1249
  /**
1250
    This memory root is used for two purposes:
1251
    - for conventional queries, to allocate structures stored in main_lex
1252
    during parsing, and allocate runtime data (execution plan, etc.)
1253
    during execution.
1254
    - for prepared queries, only to allocate runtime data. The parsed
1255
    tree itself is reused between executions and thus is stored elsewhere.
1256
  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1257
  memory::Root main_mem_root;
836 by Brian Aker
Fixed session call from function to method.
1258
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1259
  /**
1260
   * Marks all tables in the list which were used by current substatement
1261
   * as free for reuse.
1262
   *
1263
   * @param Head of the list of tables
1264
   *
1265
   * @note
1266
   *
1267
   * The reason we reset query_id is that it's not enough to just test
1268
   * if table->query_id != session->query_id to know if a table is in use.
1269
   *
1270
   * For example
1271
   * 
1272
   *  SELECT f1_that_uses_t1() FROM t1;
1273
   *  
1274
   * In f1_that_uses_t1() we will see one instance of t1 where query_id is
1275
   * set to query_id of original query.
1276
   */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1277
  void mark_used_tables_as_free_for_reuse(Table *table);
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1278
  /**
1279
    Mark all temporary tables which were used by the current statement or
1280
    substatement as free for reuse, but only if the query_id can be cleared.
1281
1282
    @param session thread context
1283
1284
    @remark For temp tables associated with a open SQL HANDLER the query_id
1285
            is not reset until the HANDLER is closed.
1286
  */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1287
  void mark_temp_tables_as_free_for_reuse();
1288
836 by Brian Aker
Fixed session call from function to method.
1289
public:
1046.1.4 by Brian Aker
Move lazy read of refresh to outside of LOCK_open (we don't lock the refresh
1290
836 by Brian Aker
Fixed session call from function to method.
1291
  /** A short cut for session->main_da.set_ok_status(). */
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
1292
  inline void my_ok(ha_rows affected_rows= 0, ha_rows found_rows_arg= 0,
1293
                    uint64_t passed_id= 0, const char *message= NULL)
836 by Brian Aker
Fixed session call from function to method.
1294
  {
971.3.59 by Eric Day
Removed client_capabilities from session and pushed functionality into protocol plugin.
1295
    main_da.set_ok_status(this, affected_rows, found_rows_arg, passed_id, message);
836 by Brian Aker
Fixed session call from function to method.
1296
  }
1297
1298
1299
  /** A short cut for session->main_da.set_eof_status(). */
1300
1301
  inline void my_eof()
1302
  {
1303
    main_da.set_eof_status(this);
1304
  }
838 by Brian Aker
More class adoption/method
1305
1306
  /* Some inline functions for more speed */
1307
1308
  inline bool add_item_to_list(Item *item)
1309
  {
1310
    return lex->current_select->add_item_to_list(this, item);
1311
  }
1312
1313
  inline bool add_value_to_list(Item *value)
1314
  {
1315
    return lex->value_list.push_back(value);
1316
  }
1317
1318
  inline bool add_order_to_list(Item *item, bool asc)
1319
  {
1320
    return lex->current_select->add_order_to_list(this, item, asc);
1321
  }
1322
1323
  inline bool add_group_to_list(Item *item, bool asc)
1324
  {
1325
    return lex->current_select->add_group_to_list(this, item, asc);
1326
  }
855 by Brian Aker
Refactor reset of status.
1327
  void refresh_status();
995 by Brian Aker
Refactor get_variable to session
1328
  user_var_entry *getVariable(LEX_STRING &name, bool create_if_not_exists);
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1329
  
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1330
  /**
1331
   * Closes all tables used by the current substatement, or all tables
1332
   * used by this thread if we are on the upper level.
1333
   */
1039.1.16 by Brian Aker
A lot of little cleanups (most based off lcov)
1334
  void close_thread_tables();
1089.1.7 by Brian Aker
Shuffled free_cached_table() to table
1335
  void close_old_data_files(bool morph_locks= false,
1336
                            bool send_refresh= false);
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1337
  void close_open_tables();
1395.1.2 by Brian Aker
More logic pulling from ALTER TABLE
1338
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1339
  void close_data_files_and_morph_locks(const char *db, const char *table_name);
1089.1.7 by Brian Aker
Shuffled free_cached_table() to table
1340
1341
private:
1342
  bool free_cached_table();
1343
public:
1344
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1345
  /**
1346
   * Prepares statement for reopening of tables and recalculation of set of
1347
   * prelocked tables.
1348
   *
1349
   * @param Pointer to a pointer to a list of tables which we were trying to open and lock
1350
   */
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1351
  void close_tables_for_reopen(TableList **tables);
1089.1.7 by Brian Aker
Shuffled free_cached_table() to table
1352
1353
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1354
  /**
1355
   * Open all tables in list, locks them (all, including derived)
1356
   *
1357
   * @param Pointer to a list of tables for open & locking
1358
   *
1359
   * @retval
1360
   *  false - ok
1361
   * @retval
1362
   *  true  - error
1363
   *
1364
   * @note
1365
   * 
1366
   * The lock will automaticaly be freed by close_thread_tables()
1367
   */
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1368
  bool openTablesLock(TableList *tables);
1109.1.2 by Brian Aker
More from the table patch
1369
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
1370
  /**
1371
   * Open all tables in list and process derived tables
1372
   *
1373
   * @param Pointer to a list of tables for open
1374
   * @param Bitmap of flags to modify how the tables will be open:
1375
   *        DRIZZLE_LOCK_IGNORE_FLUSH - open table even if someone has
1376
   *        done a flush or namelock on it.
1377
   *
1378
   * @retval
1379
   *  false - ok
1380
   * @retval
1381
   *  true  - error
1382
   *
1383
   * @note
1384
   *
1385
   * This is to be used on prepare stage when you don't read any
1386
   * data from the tables.
1387
   */
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1388
  bool openTables(TableList *tables, uint32_t flags= 0);
1109.1.2 by Brian Aker
More from the table patch
1389
1390
  int open_tables_from_list(TableList **start, uint32_t *counter, uint32_t flags= 0);
1109.1.3 by Brian Aker
Move names around a bit (to align similar methods)
1391
1392
  Table *openTableLock(TableList *table_list, thr_lock_type lock_type);
1393
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1394
1054.1.11 by Brian Aker
Remove dead lock.cc commands.
1395
  void unlink_open_table(Table *find);
1372.1.1 by Brian Aker
Removed/rewrite to remove goto in alter table.
1396
  void drop_open_table(Table *table, TableIdentifier &identifier);
1054.1.11 by Brian Aker
Remove dead lock.cc commands.
1397
  void close_cached_table(Table *table);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1398
1399
  /* Create a lock in the cache */
1400
  Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
1358.1.9 by Brian Aker
Update for std::string
1401
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1237.6.12 by Brian Aker
Adding patch for engine methods for definition files.
1402
  bool lock_table_name_if_not_cached(const char *db,
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1403
                                     const char *table_name, Table **table);
1404
1429.3.1 by Monty Taylor
Use unordered_map from the upcoming c++0x standard instead of a homemade
1405
  typedef unordered_map<std::string, message::Table> TableMessageCache;
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
1406
  TableMessageCache table_message_cache;
1407
1408
  bool storeTableMessage(TableIdentifier &identifier, message::Table &table_message);
1409
  bool removeTableMessage(TableIdentifier &identifier);
1410
  bool getTableMessage(TableIdentifier &identifier, message::Table &table_message);
1411
  bool doesTableMessageExist(TableIdentifier &identifier);
1395.1.1 by Brian Aker
Fixes for alter table to make sure that the proto on disk is valid.
1412
  bool renameTableMessage(TableIdentifier &from, TableIdentifier &to);
1358.1.2 by Brian Aker
Long pass through the system to use more of TableIdentifiers.
1413
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1414
  /* Work with temporary tables */
1415
  Table *find_temporary_table(TableList *table_list);
1416
  Table *find_temporary_table(const char *db, const char *table_name);
1369 by Brian Aker
Small interface bits.
1417
  Table *find_temporary_table(TableIdentifier &identifier);
1387 by Brian Aker
Fix for cases where not all files are removed during a deletion of a schema.
1418
1273.19.10 by Brian Aker
Add support for listing temporay tables from show commands.
1419
  void doGetTableNames(CachedDirectory &directory,
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1420
                       SchemaIdentifier &schema_identifier,
1273.19.10 by Brian Aker
Add support for listing temporay tables from show commands.
1421
                       std::set<std::string>& set_of_names);
1415 by Brian Aker
Mass overhaul to use schema_identifier.
1422
  void doGetTableNames(SchemaIdentifier &schema_identifier,
1387 by Brian Aker
Fix for cases where not all files are removed during a deletion of a schema.
1423
                       std::set<std::string>& set_of_names);
1424
1429.1.3 by Brian Aker
Merge in work for fetching a list of table identifiers.
1425
  void doGetTableIdentifiers(CachedDirectory &directory,
1426
                             SchemaIdentifier &schema_identifier,
1427
                             TableIdentifiers &set_of_identifiers);
1428
  void doGetTableIdentifiers(SchemaIdentifier &schema_identifier,
1429
                             TableIdentifiers &set_of_identifiers);
1430
1358.1.8 by Brian Aker
Another pass through the interface...
1431
  int doGetTableDefinition(drizzled::TableIdentifier &identifier,
1354.1.1 by Brian Aker
Modify ptr to reference.
1432
                           message::Table &table_proto);
1358.1.1 by Brian Aker
Fixes regression in performance from Exists patch.
1433
  bool doDoesTableExist(TableIdentifier &identifier);
1216.1.1 by Brian Aker
Move print_error up to Engine.
1434
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1435
  void close_temporary_tables();
1216.1.1 by Brian Aker
Move print_error up to Engine.
1436
  void close_temporary_table(Table *table);
1437
  // The method below just handles the de-allocation of the table. In
1237.6.12 by Brian Aker
Adding patch for engine methods for definition files.
1438
  // a better memory type world, this would not be needed.
1216.1.1 by Brian Aker
Move print_error up to Engine.
1439
private:
1395.1.11 by Brian Aker
Rename of close_temporary to nukeTable() so that my regex will stop looking
1440
  void nukeTable(Table *table);
1216.1.1 by Brian Aker
Move print_error up to Engine.
1441
public:
1442
1395.1.12 by Brian Aker
Fixes failure related to Heap's hack on deletion. Also cleans up error
1443
  void dumpTemporaryTableNames(const char *id);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1444
  int drop_temporary_table(TableList *table_list);
1395.1.8 by Brian Aker
Cleanup usage of TI so that the NULL ones no longer exist.
1445
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
1320.1.10 by Brian Aker
Additional pass through doDropTable()
1446
  bool rm_temporary_table(TableIdentifier &identifier);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1447
  Table *open_temporary_table(TableIdentifier &identifier,
1223.4.7 by Brian Aker
Next pass through for TableIdentifier.
1448
                              bool link_in_list= true);
1237.6.12 by Brian Aker
Adding patch for engine methods for definition files.
1449
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1450
  /* Reopen operations */
1046.1.14 by Brian Aker
More redactoring of all lock issue code that is session bound, to be a
1451
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
1054.1.9 by Brian Aker
This is a large number of refactors against the Session class for its
1452
  bool reopen_name_locked_table(TableList* table_list, bool link_in);
1109.1.4 by Brian Aker
More Table refactor
1453
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1054.1.10 by Brian Aker
Move open_table() to session.
1454
1455
  void wait_for_condition(pthread_mutex_t *mutex, pthread_cond_t *cond);
1109.1.5 by Brian Aker
More extraction from sql_base
1456
  int setup_conds(TableList *leaves, COND **conds);
1457
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1183.1.1 by Brian Aker
Rework interface pieces on SE (sort of... dumb ones...)
1458
1502.1.6 by Brian Aker
Further shift TableShare to private strucute.
1459
  Table *create_virtual_tmp_table(List<CreateField> &field_list);
1460
1461
1183.1.1 by Brian Aker
Rework interface pieces on SE (sort of... dumb ones...)
1462
1463
  /**
1464
    Return the default storage engine
1465
1466
    @param getDefaultStorageEngine()
1467
1468
    @return
1469
    pointer to plugin::StorageEngine
1470
  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1471
  plugin::StorageEngine *getDefaultStorageEngine()
1183.1.1 by Brian Aker
Rework interface pieces on SE (sort of... dumb ones...)
1472
  {
1473
    if (variables.storage_engine)
1474
      return variables.storage_engine;
1475
    return global_system_variables.storage_engine;
1476
  };
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
1477
1478
  static void unlink(Session *session);
1479
1490 by Brian Aker
Updates to remove a fe bits of dead code around C support for plugins
1480
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
1481
1482
private:
1483
  std::vector<TableShareInstance *> temporary_shares;
1484
1485
public:
1486
  TableShareInstance *getTemporaryShare(const char *tmpname_arg);
1487
  TableShareInstance *getTemporaryShare();
1 by brian
clean slate
1488
};
1489
1541.1.1 by Brian Aker
JOIN -> Join rename
1490
class Join;
1 by brian
clean slate
1491
1492
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1493
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1494
} /* namespace drizzled */
1495
1496
/** @TODO why is this in the middle of the file */
850 by Brian Aker
More class creation.
1497
#include <drizzled/select_to_file.h>
1498
#include <drizzled/select_export.h>
1499
#include <drizzled/select_dump.h>
1500
#include <drizzled/select_insert.h>
1501
#include <drizzled/select_create.h>
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1502
#include <drizzled/tmp_table_param.h>
1503
#include <drizzled/select_union.h>
1504
#include <drizzled/select_subselect.h>
1505
#include <drizzled/select_singlerow_subselect.h>
1506
#include <drizzled/select_max_min_finder_subselect.h>
1507
#include <drizzled/select_exists_subselect.h>
1 by brian
clean slate
1508
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1509
namespace drizzled
1510
{
1511
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
1512
/**
1513
 * A structure used to describe sort information
1514
 * for a field or item used in ORDER BY.
1515
 */
1516
typedef struct st_sort_field 
1517
{
1518
  Field *field;	/**< Field to sort */
1519
  Item	*item; /**< Item if not sorting fields */
1520
  size_t length; /**< Length of sort field */
1521
  uint32_t suffix_length; /**< Length suffix (0-4) */
1522
  Item_result result_type; /**< Type of item */
1523
  bool reverse; /**< if descending sort */
1524
  bool need_strxnfrm;	/**< If we have to use strxnfrm() */
1 by brian
clean slate
1525
} SORT_FIELD;
1526
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
1527
typedef struct st_sort_buffer 
1528
{
1529
  uint32_t index;	/* 0 or 1 */
482 by Brian Aker
Remove uint.
1530
  uint32_t sort_orders;
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
1531
  uint32_t change_pos; /* If sort-fields changed */
1 by brian
clean slate
1532
  char **buff;
1533
  SORT_FIELD *sortorder;
1534
} SORT_BUFFER;
1535
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1536
} /* namespace drizzled */
1537
1538
/** @TODO why is this in the middle of the file */
1539
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1540
#include <drizzled/table_ident.h>
1541
#include <drizzled/user_var_entry.h>
1542
#include <drizzled/unique.h>
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1543
#include <drizzled/var.h>
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1544
#include <drizzled/select_dumpvar.h>
1 by brian
clean slate
1545
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1546
namespace drizzled
1547
{
1548
1 by brian
clean slate
1549
/* Bits in sql_command_flags */
1550
1055.2.13 by Jay Pipes
Documentation and style fixes in Session class. Doxygen should finally pick up the Statement and Session classes now. Removes the silly Query_arena class, as it's not needed anymore.
1551
enum sql_command_flag_bits 
1552
{
590.2.17 by Monty Taylor
Changed CF_BIT_* to an enum.
1553
  CF_BIT_CHANGES_DATA,
1554
  CF_BIT_HAS_ROW_COUNT,
1555
  CF_BIT_STATUS_COMMAND,
1556
  CF_BIT_SHOW_TABLE_COMMAND,
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
1557
  CF_BIT_WRITE_LOGS_COMMAND,
1558
  CF_BIT_SIZE
590.2.17 by Monty Taylor
Changed CF_BIT_* to an enum.
1559
};
602.2.2 by Yoshinori Sano
Fix bugs in params of sql_command_flags[...].test(). Previously, the value such as, 0, 1, 2, 4, 8 and 16 is given to std::bitset.test() in that place, which is misunderstanding of the spec of the test(). The test(size_t n) returns true if bit n is set.
1560
590.2.18 by Monty Taylor
Changed the bitset<32> to a bitset<5>. Made the int constants into bitset constants.
1561
static const std::bitset<CF_BIT_SIZE> CF_CHANGES_DATA(1 << CF_BIT_CHANGES_DATA);
1562
static const std::bitset<CF_BIT_SIZE> CF_HAS_ROW_COUNT(1 << CF_BIT_HAS_ROW_COUNT);
1563
static const std::bitset<CF_BIT_SIZE> CF_STATUS_COMMAND(1 << CF_BIT_STATUS_COMMAND);
1564
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1565
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1 by brian
clean slate
1566
1567
/* Functions in sql_class.cc */
1273.13.74 by Brian Aker
Bits of dead code/STATUS_VAR rename.
1568
void add_to_status(system_status_var *to_var, system_status_var *from_var);
1 by brian
clean slate
1569
1273.13.74 by Brian Aker
Bits of dead code/STATUS_VAR rename.
1570
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
1571
                        system_status_var *dec_var);
1 by brian
clean slate
1572
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1573
} /* namespace drizzled */
1574
897.2.2 by Jay Pipes
Replaced custom List in select_dumpvar.h with std::vector<>
1575
#endif /* DRIZZLED_SESSION_H */