~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: kalebral at gmail
  • Date: 2010-12-04 04:58:08 UTC
  • mto: (1971.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1972.
  • Revision ID: kalebral@gmail.com-20101204045808-acto22oxfg43m02e
a few more updates of files that did not have license or had incorrect license structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
 
20
21
#ifndef DRIZZLED_SESSION_H
21
22
#define DRIZZLED_SESSION_H
22
23
 
 
24
#include "drizzled/plugin.h"
 
25
#include "drizzled/sql_locale.h"
 
26
#include "drizzled/resource_context.h"
23
27
#include "drizzled/cursor.h"
24
 
#include "drizzled/diagnostics_area.h"
 
28
#include "drizzled/current_session.h"
 
29
#include "drizzled/sql_error.h"
25
30
#include "drizzled/file_exchange.h"
26
 
#include "drizzled/identifier.h"
27
 
#include "drizzled/internal_error_handler.h"
28
 
#include "drizzled/my_hash.h"
29
 
#include "drizzled/named_savepoint.h"
30
 
#include "drizzled/open_tables_state.h"
31
 
#include "drizzled/plugin.h"
32
 
#include "drizzled/plugin/authorization.h"
33
 
#include "drizzled/pthread_globals.h"
34
 
#include "drizzled/query_id.h"
35
 
#include "drizzled/resource_context.h"
36
31
#include "drizzled/select_result_interceptor.h"
37
 
#include "drizzled/sql_error.h"
38
 
#include "drizzled/sql_locale.h"
39
32
#include "drizzled/statistics_variables.h"
 
33
#include "drizzled/xid.h"
 
34
#include "drizzled/query_id.h"
 
35
#include "drizzled/named_savepoint.h"
40
36
#include "drizzled/transaction_context.h"
41
37
#include "drizzled/util/storable.h"
42
 
#include "drizzled/xid.h"
43
 
 
 
38
#include "drizzled/my_hash.h"
 
39
#include "drizzled/pthread_globals.h"
44
40
 
45
41
#include <netdb.h>
46
42
#include <sys/time.h>
47
43
#include <sys/resource.h>
48
44
 
49
 
#include <algorithm>
50
 
#include <bitset>
51
45
#include <map>
52
46
#include <string>
53
 
 
54
 
#include "drizzled/catalog/instance.h"
55
 
#include "drizzled/catalog/local.h"
56
 
 
57
 
#include <drizzled/session/property_map.h>
58
 
#include <drizzled/session/state.h>
59
 
#include <drizzled/session/table_messages.h>
60
 
#include <drizzled/session/transactions.h>
61
 
#include <drizzled/system_variables.h>
62
 
#include <drizzled/copy_info.h>
63
 
#include <drizzled/system_variables.h>
64
 
#include <drizzled/ha_data.h>
 
47
#include <bitset>
 
48
#include <deque>
 
49
 
 
50
#include "drizzled/security_context.h"
 
51
#include "drizzled/open_tables_state.h"
 
52
#include "drizzled/internal_error_handler.h"
 
53
#include "drizzled/diagnostics_area.h"
 
54
#include "drizzled/plugin/authorization.h"
 
55
 
 
56
#include <boost/unordered_map.hpp>
65
57
 
66
58
#include <boost/thread/thread.hpp>
67
59
#include <boost/thread/mutex.hpp>
68
60
#include <boost/thread/shared_mutex.hpp>
69
61
#include <boost/thread/condition_variable.hpp>
70
 
#include <boost/make_shared.hpp>
71
 
 
72
 
#include <drizzled/lex_column.h>
73
 
#include "drizzled/sql_lex.h"
74
 
 
75
 
#include "drizzled/visibility.h"
76
62
 
77
63
#define MIN_HANDSHAKE_SIZE      6
78
64
 
93
79
class Resultset;
94
80
}
95
81
 
96
 
namespace internal { struct st_my_thread_var; }
 
82
namespace internal
 
83
{
 
84
struct st_my_thread_var;
 
85
}
97
86
 
98
 
namespace table { class Placeholder; }
 
87
namespace table
 
88
{
 
89
class Placeholder;
 
90
}
99
91
 
100
92
class Lex_input_stream;
101
93
class user_var_entry;
112
104
#define TC_HEURISTIC_RECOVER_ROLLBACK 2
113
105
extern uint32_t tc_heuristic_recover;
114
106
 
 
107
/**
 
108
  @brief
 
109
  Local storage for proto that are tmp table. This should be enlarged
 
110
  to hande the entire table-share for a local table. Once Hash is done,
 
111
  we should consider exchanging the map for it.
 
112
*/
 
113
typedef std::map <std::string, message::Table> ProtoCache;
 
114
 
 
115
/**
 
116
  The COPY_INFO structure is used by INSERT/REPLACE code.
 
117
  The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY
 
118
  UPDATE code:
 
119
    If a row is inserted then the copied variable is incremented.
 
120
    If a row is updated by the INSERT ... ON DUPLICATE KEY UPDATE and the
 
121
      new data differs from the old one then the copied and the updated
 
122
      variables are incremented.
 
123
    The touched variable is incremented if a row was touched by the update part
 
124
      of the INSERT ... ON DUPLICATE KEY UPDATE no matter whether the row
 
125
      was actually changed or not.
 
126
*/
 
127
class CopyInfo 
 
128
{
 
129
public:
 
130
  ha_rows records; /**< Number of processed records */
 
131
  ha_rows deleted; /**< Number of deleted records */
 
132
  ha_rows updated; /**< Number of updated records */
 
133
  ha_rows copied;  /**< Number of copied records */
 
134
  ha_rows error_count;
 
135
  ha_rows touched; /* Number of touched records */
 
136
  enum enum_duplicates handle_duplicates;
 
137
  int escape_char, last_errno;
 
138
  bool ignore;
 
139
  /* for INSERT ... UPDATE */
 
140
  List<Item> *update_fields;
 
141
  List<Item> *update_values;
 
142
  /* for VIEW ... WITH CHECK OPTION */
 
143
 
 
144
  CopyInfo() :
 
145
    records(0),
 
146
    deleted(0),
 
147
    updated(0),
 
148
    copied(0),
 
149
    error_count(0),
 
150
    touched(0),
 
151
    escape_char(0),
 
152
    last_errno(0),
 
153
    ignore(0),
 
154
    update_fields(0),
 
155
    update_values(0)
 
156
  { }
 
157
 
 
158
};
 
159
 
 
160
} /* namespace drizzled */
 
161
 
 
162
/** @TODO why is this in the middle of the file */
 
163
#include <drizzled/lex_column.h>
 
164
 
 
165
namespace drizzled
 
166
{
 
167
 
115
168
class select_result;
116
169
class Time_zone;
117
170
 
118
171
#define Session_SENTRY_MAGIC 0xfeedd1ff
119
172
#define Session_SENTRY_GONE  0xdeadbeef
120
173
 
121
 
extern DRIZZLED_API struct drizzle_system_variables global_system_variables;
 
174
struct drizzle_system_variables
 
175
{
 
176
  drizzle_system_variables()
 
177
  {}
 
178
  /*
 
179
    How dynamically allocated system variables are handled:
 
180
 
 
181
    The global_system_variables and max_system_variables are "authoritative"
 
182
    They both should have the same 'version' and 'size'.
 
183
    When attempting to access a dynamic variable, if the session version
 
184
    is out of date, then the session version is updated and realloced if
 
185
    neccessary and bytes copied from global to make up for missing data.
 
186
  */
 
187
  ulong dynamic_variables_version;
 
188
  char * dynamic_variables_ptr;
 
189
  uint32_t dynamic_variables_head;  /* largest valid variable offset */
 
190
  uint32_t dynamic_variables_size;  /* how many bytes are in use */
 
191
 
 
192
  uint64_t myisam_max_extra_sort_file_size;
 
193
  uint64_t max_heap_table_size;
 
194
  uint64_t tmp_table_size;
 
195
  ha_rows select_limit;
 
196
  ha_rows max_join_size;
 
197
  uint64_t auto_increment_increment;
 
198
  uint64_t auto_increment_offset;
 
199
  uint64_t bulk_insert_buff_size;
 
200
  uint64_t join_buff_size;
 
201
  uint32_t max_allowed_packet;
 
202
  uint64_t max_error_count;
 
203
  uint64_t max_length_for_sort_data;
 
204
  size_t max_sort_length;
 
205
  uint64_t min_examined_row_limit;
 
206
  bool optimizer_prune_level;
 
207
  bool log_warnings;
 
208
 
 
209
  uint32_t optimizer_search_depth;
 
210
  uint32_t div_precincrement;
 
211
  uint64_t preload_buff_size;
 
212
  uint32_t read_buff_size;
 
213
  uint32_t read_rnd_buff_size;
 
214
  bool replicate_query;
 
215
  size_t sortbuff_size;
 
216
  uint32_t thread_handling;
 
217
  uint32_t tx_isolation;
 
218
  size_t transaction_message_threshold;
 
219
  uint32_t completion_type;
 
220
  /* Determines which non-standard SQL behaviour should be enabled */
 
221
  uint32_t sql_mode;
 
222
  uint64_t max_seeks_for_key;
 
223
  size_t range_alloc_block_size;
 
224
  uint32_t query_alloc_block_size;
 
225
  uint32_t query_prealloc_size;
 
226
  uint64_t group_concat_max_len;
 
227
  uint64_t pseudo_thread_id;
 
228
 
 
229
  plugin::StorageEngine *storage_engine;
 
230
 
 
231
  /* Only charset part of these variables is sensible */
 
232
  const CHARSET_INFO  *character_set_filesystem;
 
233
 
 
234
  /* Both charset and collation parts of these variables are important */
 
235
  const CHARSET_INFO    *collation_server;
 
236
 
 
237
  inline const CHARSET_INFO  *getCollation(void) 
 
238
  {
 
239
    return collation_server;
 
240
  }
 
241
 
 
242
  /* Locale Support */
 
243
  MY_LOCALE *lc_time_names;
 
244
 
 
245
  Time_zone *time_zone;
 
246
};
 
247
 
 
248
extern struct drizzle_system_variables global_system_variables;
 
249
 
 
250
} /* namespace drizzled */
 
251
 
 
252
#include "drizzled/sql_lex.h"
 
253
 
 
254
namespace drizzled
 
255
{
 
256
 
 
257
void mark_transaction_to_rollback(Session *session, bool all);
 
258
 
 
259
/**
 
260
  Storage engine specific thread local data.
 
261
*/
 
262
struct Ha_data
 
263
{
 
264
  /**
 
265
    Storage engine specific thread local data.
 
266
    Lifetime: one user connection.
 
267
  */
 
268
  void *ha_ptr;
 
269
  /**
 
270
   * Resource contexts for both the "statement" and "normal"
 
271
   * transactions.
 
272
   *
 
273
   * Resource context at index 0:
 
274
   *
 
275
   * Life time: one statement within a transaction. If @@autocommit is
 
276
   * on, also represents the entire transaction.
 
277
   *
 
278
   * Resource context at index 1:
 
279
   *
 
280
   * Life time: one transaction within a connection. 
 
281
   *
 
282
   * @note
 
283
   *
 
284
   * If the storage engine does not participate in a transaction, 
 
285
   * there will not be a resource context.
 
286
   */
 
287
  drizzled::ResourceContext resource_context[2];
 
288
 
 
289
  Ha_data() :ha_ptr(NULL) {}
 
290
};
122
291
 
123
292
/**
124
293
 * Represents a client connection to the database server.
139
308
 * all member variables that are not critical to non-internal operations of the
140
309
 * session object.
141
310
 */
 
311
typedef int64_t session_id_t;
142
312
 
143
 
class DRIZZLED_API Session : public Open_tables_state
 
313
class Session : public Open_tables_state
144
314
{
145
315
public:
146
316
  // Plugin storage in Session.
 
317
  typedef boost::unordered_map<std::string, util::Storable *, util::insensitive_hash, util::insensitive_equal_to> PropertyMap;
 
318
  typedef Session* Ptr;
147
319
  typedef boost::shared_ptr<Session> shared_ptr;
148
 
  typedef Session& reference;
149
 
  typedef const Session& const_reference;
150
 
  typedef const Session* const_pointer;
151
 
  typedef Session* pointer;
152
 
 
153
 
  static shared_ptr make_shared(plugin::Client *client, catalog::Instance::shared_ptr instance_arg)
154
 
  {
155
 
    assert(instance_arg);
156
 
    return boost::make_shared<Session>(client, instance_arg);
157
 
  }
158
320
 
159
321
  /*
160
322
    MARK_COLUMNS_NONE:  Means mark_used_colums is not set and no indicator to
168
330
                        and update_row.
169
331
  */
170
332
  enum enum_mark_columns mark_used_columns;
 
333
  inline void* alloc(size_t size)
 
334
  {
 
335
    return mem_root->alloc_root(size);
 
336
  }
171
337
  inline void* calloc(size_t size)
172
338
  {
173
339
    void *ptr;
175
341
      memset(ptr, 0, size);
176
342
    return ptr;
177
343
  }
 
344
  inline char *strdup(const char *str)
 
345
  {
 
346
    return mem_root->strdup_root(str);
 
347
  }
178
348
  inline char *strmake(const char *str, size_t size)
179
349
  {
180
350
    return mem_root->strmake_root(str,size);
181
351
  }
182
 
 
 
352
  inline void *memdup(const void *str, size_t size)
 
353
  {
 
354
    return mem_root->memdup_root(str, size);
 
355
  }
183
356
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
184
357
  {
185
358
    void *ptr;
189
362
  }
190
363
  /** Frees all items attached to this Statement */
191
364
  void free_items();
192
 
 
193
365
  /**
194
366
   * List of items created in the parser for this query. Every item puts
195
367
   * itself to the list on creation (see Item::Item() for details))
228
400
  {
229
401
    return lex;
230
402
  }
231
 
 
232
 
  enum_sql_command getSqlCommand() const
233
 
  {
234
 
    return lex->sql_command;
235
 
  }
236
 
 
237
403
  /** query associated with this statement */
238
404
  typedef boost::shared_ptr<const std::string> QueryString;
239
 
 
240
405
private:
241
406
  boost::shared_ptr<std::string> query;
242
407
 
251
416
 
252
417
  void resetQueryString()
253
418
  {
254
 
    query.reset();
255
 
    _state.reset();
 
419
    return query.reset(new std::string);
256
420
  }
257
421
 
258
422
  /*
264
428
  {
265
429
    QueryString tmp_string(getQueryString());
266
430
 
267
 
    if (not tmp_string)
268
 
    {
269
 
      length= 0;
270
 
      return NULL;
271
 
    }
272
 
 
273
431
    length= tmp_string->length();
274
432
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
275
433
    return to_return;
276
434
  }
277
435
 
278
 
private:
279
 
  session::State::shared_ptr  _state; 
280
 
 
281
 
public:
282
 
 
283
 
  session::State::const_shared_ptr state()
284
 
  {
285
 
    return _state;
286
 
  }
287
 
 
288
436
  /**
289
437
    Name of the current (default) database.
290
438
 
297
445
    the Session of that thread); that thread is (and must remain, for now) the
298
446
    only responsible for freeing this member.
299
447
  */
300
 
private:
301
 
  util::string::shared_ptr _schema;
302
 
 
303
 
public:
304
 
 
305
 
  util::string::const_shared_ptr schema() const
 
448
  std::string db;
 
449
 
 
450
  const std::string &getSchema() const
306
451
  {
307
 
    if (_schema)
308
 
      return _schema;
309
 
 
310
 
    return util::string::const_shared_ptr(new std::string(""));
 
452
    return db;
311
453
  }
312
 
 
 
454
  std::string catalog;
313
455
  /* current cache key */
314
456
  std::string query_cache_key;
315
457
  /**
321
463
  static const char * const DEFAULT_WHERE;
322
464
 
323
465
  memory::Root warn_root; /**< Allocation area for warnings and errors */
324
 
private:
325
466
  plugin::Client *client; /**< Pointer to client object */
326
467
 
327
 
public:
328
 
 
329
468
  void setClient(plugin::Client *client_arg);
330
469
 
331
470
  plugin::Client *getClient()
333
472
    return client;
334
473
  }
335
474
 
336
 
  plugin::Client *getClient() const
337
 
  {
338
 
    return client;
339
 
  }
340
 
 
341
475
  plugin::Scheduler *scheduler; /**< Pointer to scheduler object */
342
476
  void *scheduler_arg; /**< Pointer to the optional scheduler argument */
343
477
 
344
478
  typedef boost::unordered_map< std::string, user_var_entry *, util::insensitive_hash, util::insensitive_equal_to> UserVars;
345
 
 
346
479
private:
347
480
  typedef std::pair< UserVars::iterator, UserVars::iterator > UserVarsRange;
348
481
  UserVars user_vars; /**< Hash of user variables defined during the session's lifetime */
349
482
 
350
483
public:
 
484
 
351
485
  const UserVars &getUserVariables() const
352
486
  {
353
487
    return user_vars;
354
488
  }
355
489
 
356
490
  drizzle_system_variables variables; /**< Mutable local variables local to the session */
357
 
 
358
 
  enum_tx_isolation getTxIsolation()
359
 
  {
360
 
    return (enum_tx_isolation)variables.tx_isolation;
361
 
  }
362
 
 
363
491
  struct system_status_var status_var; /**< Session-local status counters */
364
492
  THR_LOCK_INFO lock_info; /**< Locking information for this session */
365
493
  THR_LOCK_OWNER main_lock_id; /**< To use for conventional queries */
372
500
  char *thread_stack;
373
501
 
374
502
private:
375
 
  identifier::User::shared_ptr security_ctx;
 
503
  SecurityContext security_ctx;
376
504
 
377
505
  int32_t scoreboard_index;
378
506
 
380
508
  {
381
509
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
382
510
  }
383
 
 
384
511
public:
385
 
  identifier::User::const_shared_ptr user() const
 
512
  const SecurityContext& getSecurityContext() const
386
513
  {
387
 
    if (security_ctx)
388
 
      return security_ctx;
389
 
 
390
 
    return identifier::User::const_shared_ptr();
 
514
    return security_ctx;
391
515
  }
392
516
 
393
 
  void setUser(identifier::User::shared_ptr arg)
 
517
  SecurityContext& getSecurityContext()
394
518
  {
395
 
    security_ctx= arg;
 
519
    return security_ctx;
396
520
  }
397
521
 
398
522
  int32_t getScoreboardIndex()
408
532
  /**
409
533
   * Is this session viewable by the current user?
410
534
   */
411
 
  bool isViewable(identifier::User::const_reference) const;
 
535
  bool isViewable() const;
412
536
 
413
 
private:
414
537
  /**
415
538
    Used in error messages to tell user in what part of MySQL we found an
416
539
    error. E. g. when where= "having clause", if fix_fields() fails, user
417
540
    will know that the error was in having clause.
418
541
  */
419
 
  const char *_where;
420
 
 
421
 
public:
422
 
  const char *where()
423
 
  {
424
 
    return _where;
425
 
  }
426
 
 
427
 
  void setWhere(const char *arg)
428
 
  {
429
 
    _where= arg;
430
 
  }
 
542
  const char *where;
431
543
 
432
544
  /*
433
545
    One thread can hold up to one named user-level lock. This variable
435
547
    chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
436
548
  */
437
549
  uint32_t dbug_sentry; /**< watch for memory corruption */
438
 
 
439
550
private:
440
551
  boost::thread::id boost_thread_id;
441
552
  boost_thread_shared_ptr _thread;
442
553
  boost::this_thread::disable_interruption *interrupt;
443
554
 
444
555
  internal::st_my_thread_var *mysys_var;
 
556
public:
445
557
 
446
 
public:
447
558
  boost_thread_shared_ptr &getThread()
448
559
  {
449
560
    return _thread;
473
584
  uint32_t file_id;     /**< File ID for LOAD DATA INFILE */
474
585
  /* @note the following three members should likely move to Client */
475
586
  uint32_t max_client_packet_length; /**< Maximum number of bytes a client can send in a single packet */
476
 
 
477
 
private:
478
 
  boost::posix_time::ptime _epoch;
479
 
  boost::posix_time::ptime _connect_time;
480
 
  boost::posix_time::ptime _start_timer;
481
 
  boost::posix_time::ptime _end_timer;
482
 
 
483
 
  boost::posix_time::ptime _user_time;
484
 
public:
485
 
  uint64_t utime_after_lock; // This used by Innodb.
486
 
 
487
 
  void resetUserTime()
488
 
  {
489
 
    _user_time= boost::posix_time::not_a_date_time;
490
 
  }
491
 
 
492
 
  const boost::posix_time::ptime &start_timer() const
493
 
  {
494
 
    return _start_timer;
495
 
  }
496
 
 
497
 
  void getTimeDifference(boost::posix_time::time_duration &result_arg, const boost::posix_time::ptime &arg) const
498
 
  {
499
 
    result_arg=  arg - _start_timer;
500
 
  }
 
587
  time_t start_time;
 
588
  time_t user_time;
 
589
  uint64_t thr_create_utime; /**< track down slow pthread_create */
 
590
  uint64_t start_utime;
 
591
  uint64_t utime_after_lock;
501
592
 
502
593
  thr_lock_type update_lock_default;
503
594
 
518
609
  */
519
610
  query_id_t query_id;
520
611
  query_id_t warn_query_id;
521
 
 
522
612
public:
523
613
  void **getEngineData(const plugin::MonitoredInTransaction *monitored);
524
614
  ResourceContext *getResourceContext(const plugin::MonitoredInTransaction *monitored,
525
615
                                      size_t index= 0);
526
616
 
527
 
  session::Transactions transaction;
 
617
  /**
 
618
   * Structure used to manage "statement transactions" and
 
619
   * "normal transactions". In autocommit mode, the normal transaction is
 
620
   * equivalent to the statement transaction.
 
621
   *
 
622
   * Storage engines will be registered here when they participate in
 
623
   * a transaction. No engine is registered more than once.
 
624
   */
 
625
  struct st_transactions {
 
626
    std::deque<NamedSavepoint> savepoints;
 
627
 
 
628
    /**
 
629
     * The normal transaction (since BEGIN WORK).
 
630
     *
 
631
     * Contains a list of all engines that have participated in any of the
 
632
     * statement transactions started within the context of the normal
 
633
     * transaction.
 
634
     *
 
635
     * @note In autocommit mode, this is empty.
 
636
     */
 
637
    TransactionContext all;
 
638
 
 
639
    /**
 
640
     * The statment transaction.
 
641
     *
 
642
     * Contains a list of all engines participating in the given statement.
 
643
     *
 
644
     * @note In autocommit mode, this will be used to commit/rollback the
 
645
     * normal transaction.
 
646
     */
 
647
    TransactionContext stmt;
 
648
 
 
649
    XID_STATE xid_state;
 
650
 
 
651
    void cleanup()
 
652
    {
 
653
      savepoints.clear();
 
654
    }
 
655
    st_transactions() :
 
656
      savepoints(),
 
657
      all(),
 
658
      stmt(),
 
659
      xid_state()
 
660
    { }
 
661
  } transaction;
528
662
 
529
663
  Field *dup_field;
530
664
  sigset_t signals;
532
666
  // As of right now we do not allow a concurrent execute to launch itself
533
667
private:
534
668
  bool concurrent_execute_allowed;
535
 
 
536
669
public:
537
670
 
538
671
  void setConcurrentExecute(bool arg)
601
734
  uint64_t limit_found_rows;
602
735
  uint64_t options; /**< Bitmap of options */
603
736
  int64_t row_count_func; /**< For the ROW_COUNT() function */
604
 
 
605
 
  int64_t rowCount() const
606
 
  {
607
 
    return row_count_func;
608
 
  }
609
 
 
610
737
  ha_rows cuted_fields; /**< Count of "cut" or truncated fields. @todo Kill this friggin thing. */
611
738
 
612
739
  /** 
655
782
    create_sort_index(); may differ from examined_row_count.
656
783
  */
657
784
  uint32_t row_count;
658
 
 
659
 
  uint32_t getRowCount() const
660
 
  {
661
 
    return row_count;
662
 
  }
663
 
 
664
785
  session_id_t thread_id;
665
786
  uint32_t tmp_table;
666
787
  enum global_read_lock_t
684
805
    _global_read_lock= arg;
685
806
  }
686
807
 
687
 
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags);
 
808
  DrizzleLock *lockTables(Table **tables, uint32_t count, uint32_t flags, bool *need_reopen);
688
809
  bool lockGlobalReadLock();
689
810
  bool lock_table_names(TableList *table_list);
690
811
  bool lock_table_names_exclusively(TableList *table_list);
743
864
    return &_killed;
744
865
  }
745
866
 
746
 
  bool is_admin_connection;
747
867
  bool some_tables_deleted;
748
868
  bool no_errors;
749
869
  bool password;
752
872
    can not continue. In particular, disables activation of
753
873
    CONTINUE or EXIT handlers of stored routines.
754
874
    Reset in the end of processing of the current user request, in
755
 
    @see reset_session_for_next_command().
 
875
    @see mysql_reset_session_for_next_command().
756
876
  */
757
877
  bool is_fatal_error;
758
878
  /**
777
897
  bool substitute_null_with_insert_id;
778
898
  bool cleanup_done;
779
899
 
780
 
private:
781
900
  bool abort_on_warning;
782
 
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
783
 
 
784
 
public:
785
901
  bool got_warning; /**< Set on call to push_warning() */
786
902
  bool no_warnings_for_error; /**< no warnings on call to my_error() */
787
903
  /** set during loop of derived table processing */
788
904
  bool derived_tables_processing;
789
 
 
790
 
  bool doing_tablespace_operation(void)
791
 
  {
792
 
    return tablespace_op;
793
 
  }
794
 
 
795
 
  void setDoingTablespaceOperation(bool doing)
796
 
  {
797
 
    tablespace_op= doing;
798
 
  }
799
 
 
 
905
  bool tablespace_op; /**< This is true in DISCARD/IMPORT TABLESPACE */
800
906
 
801
907
  /** Used by the sys_var class to store temporary values */
802
908
  union
938
1044
    auto_inc_intervals_forced.append(next_id, UINT64_MAX, 0);
939
1045
  }
940
1046
 
941
 
  Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog);
 
1047
  Session(plugin::Client *client_arg);
942
1048
  virtual ~Session();
943
1049
 
944
1050
  void cleanup(void);
1021
1127
  bool endTransaction(enum enum_mysql_completiontype completion);
1022
1128
  bool endActiveTransaction();
1023
1129
  bool startTransaction(start_transaction_option_t opt= START_TRANS_NO_OPTIONS);
1024
 
  void markTransactionForRollback(bool all);
1025
1130
 
1026
1131
  /**
1027
1132
   * Authenticates users, with error reporting.
1042
1147
   */
1043
1148
  static bool schedule(Session::shared_ptr&);
1044
1149
 
1045
 
  static void unlink(session_id_t &session_id);
1046
1150
  static void unlink(Session::shared_ptr&);
1047
1151
 
1048
1152
  /*
1053
1157
  const char* enter_cond(boost::condition_variable_any &cond, boost::mutex &mutex, const char* msg);
1054
1158
  void exit_cond(const char* old_msg);
1055
1159
 
1056
 
  type::Time::epoch_t query_start()
1057
 
  {
1058
 
    return getCurrentTimestampEpoch();
1059
 
  }
1060
 
 
1061
 
  void set_time()
1062
 
  {
1063
 
    _end_timer= _start_timer= boost::posix_time::microsec_clock::universal_time();
1064
 
    utime_after_lock= (_start_timer - _epoch).total_microseconds();
1065
 
  }
1066
 
 
1067
 
  void set_time(time_t t) // This is done by a sys_var, as long as user_time is set, we will use that for all references to time
1068
 
  {
1069
 
    _user_time= boost::posix_time::from_time_t(t);
1070
 
  }
1071
 
 
1072
 
  void set_time_after_lock()
1073
 
  { 
1074
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1075
 
    utime_after_lock= (mytime - _epoch).total_microseconds();
1076
 
  }
1077
 
 
1078
 
  void set_end_timer()
1079
 
  {
1080
 
    _end_timer= boost::posix_time::microsec_clock::universal_time();
1081
 
    status_var.execution_time_nsec+=(_end_timer - _start_timer).total_microseconds();
1082
 
  }
1083
 
 
1084
 
  uint64_t getElapsedTime() const
1085
 
  {
1086
 
    return (_end_timer - _start_timer).total_microseconds();
1087
 
  }
1088
 
 
 
1160
  inline time_t query_start() { return start_time; }
 
1161
  inline void set_time()
 
1162
  {
 
1163
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1164
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1165
    start_utime= utime_after_lock= (mytime-epoch).total_microseconds();
 
1166
 
 
1167
    if (user_time)
 
1168
    {
 
1169
      start_time= user_time;
 
1170
      connect_microseconds= start_utime;
 
1171
    }
 
1172
    else 
 
1173
      start_time= (mytime-epoch).total_seconds();
 
1174
  }
 
1175
  inline void   set_current_time()    { start_time= time(NULL); }
 
1176
  inline void   set_time(time_t t)
 
1177
  {
 
1178
    start_time= user_time= t;
 
1179
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1180
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1181
    uint64_t t_mark= (mytime-epoch).total_microseconds();
 
1182
 
 
1183
    start_utime= utime_after_lock= t_mark;
 
1184
  }
 
1185
  void set_time_after_lock()  { 
 
1186
     boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1187
     boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1188
     utime_after_lock= (mytime-epoch).total_microseconds();
 
1189
  }
1089
1190
  /**
1090
1191
   * Returns the current micro-timestamp
1091
1192
   */
1092
 
  type::Time::epoch_t getCurrentTimestamp(bool actual= true) const
 
1193
  inline uint64_t getCurrentTimestamp()  
1093
1194
  { 
1094
 
    type::Time::epoch_t t_mark;
1095
 
 
1096
 
    if (actual)
1097
 
    {
1098
 
      boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::universal_time());
1099
 
      t_mark= (mytime - _epoch).total_microseconds();
1100
 
    }
1101
 
    else
1102
 
    {
1103
 
      t_mark= (_end_timer - _epoch).total_microseconds();
1104
 
    }
 
1195
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
 
1196
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
 
1197
    uint64_t t_mark= (mytime-epoch).total_microseconds();
1105
1198
 
1106
1199
    return t_mark; 
1107
1200
  }
1108
 
 
1109
 
  // We may need to set user on this
1110
 
  type::Time::epoch_t getCurrentTimestampEpoch() const
1111
 
  { 
1112
 
    if (not _user_time.is_not_a_date_time())
1113
 
      return (_user_time - _epoch).total_seconds();
1114
 
 
1115
 
    return (_start_timer - _epoch).total_seconds();
1116
 
  }
1117
 
 
1118
 
  type::Time::epoch_t getCurrentTimestampEpoch(type::Time::usec_t &fraction_arg) const
1119
 
  { 
1120
 
    if (not _user_time.is_not_a_date_time())
1121
 
    {
1122
 
      fraction_arg= 0;
1123
 
      return (_user_time - _epoch).total_seconds();
1124
 
    }
1125
 
 
1126
 
    fraction_arg= _start_timer.time_of_day().fractional_seconds() % 1000000;
1127
 
    return (_start_timer - _epoch).total_seconds();
1128
 
  }
1129
 
 
1130
 
  uint64_t found_rows(void) const
 
1201
  inline uint64_t found_rows(void)
1131
1202
  {
1132
1203
    return limit_found_rows;
1133
1204
  }
1134
 
 
1135
1205
  /** Returns whether the session is currently inside a transaction */
1136
 
  bool inTransaction() const
 
1206
  inline bool inTransaction()
1137
1207
  {
1138
1208
    return server_status & SERVER_STATUS_IN_TRANS;
1139
1209
  }
1140
 
 
1141
1210
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1142
1211
                              const char* str, uint32_t length,
1143
1212
                              bool allocate_lex_string);
1144
 
 
1145
1213
  LEX_STRING *make_lex_string(LEX_STRING *lex_str,
1146
1214
                              const std::string &str,
1147
1215
                              bool allocate_lex_string);
1148
1216
 
1149
1217
  int send_explain_fields(select_result *result);
1150
 
 
1151
1218
  /**
1152
1219
    Clear the current error, if any.
1153
1220
    We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
1217
1284
  }
1218
1285
  void send_kill_message() const;
1219
1286
  /* return true if we will abort query if we make a warning now */
1220
 
  inline bool abortOnWarning()
1221
 
  {
1222
 
    return abort_on_warning;
1223
 
  }
1224
 
 
1225
 
  inline void setAbortOnWarning(bool arg)
1226
 
  {
1227
 
    abort_on_warning= arg;
 
1287
  inline bool really_abort_on_warning()
 
1288
  {
 
1289
    return (abort_on_warning);
1228
1290
  }
1229
1291
 
1230
1292
  void setAbort(bool arg);
1247
1309
    database usually involves other actions, like switching other database
1248
1310
    attributes including security context. In the future, this operation
1249
1311
    will be made private and more convenient interface will be provided.
 
1312
 
 
1313
    @return Operation status
 
1314
      @retval false Success
 
1315
      @retval true  Out-of-memory error
1250
1316
  */
1251
 
  void set_db(const std::string &new_db);
 
1317
  bool set_db(const std::string &new_db);
1252
1318
 
1253
1319
  /*
1254
1320
    Copy the current database to the argument. Use the current arena to
1270
1336
    @param level the error level
1271
1337
    @return true if the error is handled
1272
1338
  */
1273
 
  virtual bool handle_error(drizzled::error_t sql_errno, const char *message,
 
1339
  virtual bool handle_error(uint32_t sql_errno, const char *message,
1274
1340
                            DRIZZLE_ERROR::enum_warning_level level);
1275
1341
 
1276
1342
  /**
1298
1364
   * updates any status variables necessary.
1299
1365
   *
1300
1366
   * @param errcode     Error code to print to console
 
1367
   * @param should_lock 1 if we have have to lock LOCK_thread_count
1301
1368
   *
1302
1369
   * @note  For the connection that is doing shutdown, this is called twice
1303
1370
   */
1304
 
  void disconnect(enum error_t errcode= EE_OK);
 
1371
  void disconnect(uint32_t errcode, bool lock);
1305
1372
 
1306
1373
  /**
1307
1374
   * Check if user exists and the password supplied is correct.
1321
1388
   * Returns the timestamp (in microseconds) of when the Session 
1322
1389
   * connected to the server.
1323
1390
   */
1324
 
  uint64_t getConnectMicroseconds() const
1325
 
  {
1326
 
    return (_connect_time - _epoch).total_microseconds();
1327
 
  }
1328
 
 
1329
 
  uint64_t getConnectSeconds() const
1330
 
  {
1331
 
    return (_connect_time - _epoch).total_seconds();
 
1391
  inline uint64_t getConnectMicroseconds() const
 
1392
  {
 
1393
    return connect_microseconds;
1332
1394
  }
1333
1395
 
1334
1396
  /**
1449
1511
  
1450
1512
  
1451
1513
 private:
 
1514
 /** Microsecond timestamp of when Session connected */
 
1515
  uint64_t connect_microseconds;
1452
1516
  const char *proc_info;
1453
1517
 
1454
1518
  /** The current internal error handler for this thread, or NULL. */
1541
1605
  void close_old_data_files(bool morph_locks= false,
1542
1606
                            bool send_refresh= false);
1543
1607
  void close_open_tables();
1544
 
  void close_data_files_and_morph_locks(const identifier::Table &identifier);
 
1608
  void close_data_files_and_morph_locks(const TableIdentifier &identifier);
1545
1609
 
1546
1610
private:
1547
 
  bool free_cached_table(boost::mutex::scoped_lock &scopedLock);
1548
 
 
 
1611
  bool free_cached_table();
1549
1612
public:
1550
1613
 
1551
1614
  /**
1579
1642
  Table *openTable(TableList *table_list, bool *refresh, uint32_t flags= 0);
1580
1643
 
1581
1644
  void unlink_open_table(Table *find);
1582
 
  void drop_open_table(Table *table, const identifier::Table &identifier);
 
1645
  void drop_open_table(Table *table, const TableIdentifier &identifier);
1583
1646
  void close_cached_table(Table *table);
1584
1647
 
1585
1648
  /* Create a lock in the cache */
1586
 
  table::Placeholder *table_cache_insert_placeholder(const identifier::Table &identifier);
1587
 
  bool lock_table_name_if_not_cached(const identifier::Table &identifier, Table **table);
1588
 
 
 
1649
  table::Placeholder *table_cache_insert_placeholder(const TableIdentifier &identifier);
 
1650
  bool lock_table_name_if_not_cached(const TableIdentifier &identifier, Table **table);
 
1651
 
 
1652
  typedef boost::unordered_map<std::string, message::Table, util::insensitive_hash, util::insensitive_equal_to> TableMessageCache;
 
1653
 
 
1654
  class TableMessages
 
1655
  {
 
1656
    TableMessageCache table_message_cache;
 
1657
 
 
1658
  public:
 
1659
    bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1660
    bool removeTableMessage(const TableIdentifier &identifier);
 
1661
    bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1662
    bool doesTableMessageExist(const TableIdentifier &identifier);
 
1663
    bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
 
1664
 
 
1665
  };
1589
1666
private:
1590
 
  session::TableMessages _table_message_cache;
 
1667
  TableMessages _table_message_cache;
1591
1668
 
1592
1669
public:
1593
 
  session::TableMessages &getMessageCache()
 
1670
  TableMessages &getMessageCache()
1594
1671
  {
1595
1672
    return _table_message_cache;
1596
1673
  }
1597
1674
 
1598
1675
  /* Reopen operations */
1599
 
  bool reopen_tables();
 
1676
  bool reopen_tables(bool get_locks, bool mark_share_as_old);
1600
1677
  bool close_cached_tables(TableList *tables, bool wait_for_refresh, bool wait_for_placeholders);
1601
1678
 
1602
1679
  void wait_for_condition(boost::mutex &mutex, boost::condition_variable_any &cond);
1605
1682
 
1606
1683
  drizzled::util::Storable *getProperty(const std::string &arg)
1607
1684
  {
1608
 
    return life_properties.getProperty(arg);
 
1685
    return life_properties[arg];
1609
1686
  }
1610
1687
 
1611
1688
  template<class T>
1612
1689
  bool setProperty(const std::string &arg, T *value)
1613
1690
  {
1614
 
    life_properties.setProperty(arg, value);
 
1691
    life_properties[arg]= value;
1615
1692
 
1616
1693
    return true;
1617
1694
  }
1633
1710
 
1634
1711
  void get_xid(DRIZZLE_XID *xid); // Innodb only
1635
1712
 
1636
 
  table::Singular *getInstanceTable();
1637
 
  table::Singular *getInstanceTable(List<CreateField> &field_list);
 
1713
  table::Instance *getInstanceTable();
 
1714
  table::Instance *getInstanceTable(List<CreateField> &field_list);
1638
1715
 
1639
1716
private:
1640
1717
  bool resetUsage()
1646
1723
 
1647
1724
    return true;
1648
1725
  }
1649
 
 
1650
1726
public:
1651
1727
 
1652
1728
  void setUsage(bool arg)
1659
1735
    return usage;
1660
1736
  }
1661
1737
 
1662
 
  catalog::Instance::const_reference catalog() const
1663
 
  {
1664
 
    return *(_catalog.get());
1665
 
  }
1666
 
 
1667
 
  catalog::Instance::reference catalog()
1668
 
  {
1669
 
    return *(_catalog.get());
1670
 
  }
1671
 
 
1672
1738
private:
1673
 
  catalog::Instance::shared_ptr _catalog;
1674
 
 
1675
1739
  // This lives throughout the life of Session
1676
1740
  bool use_usage;
1677
 
  session::PropertyMap life_properties;
1678
 
  std::vector<table::Singular *> temporary_shares;
 
1741
  PropertyMap life_properties;
 
1742
  std::vector<table::Instance *> temporary_shares;
1679
1743
  struct rusage usage;
1680
1744
};
1681
1745
 
1762
1826
namespace display  {
1763
1827
const std::string &type(drizzled::Session::global_read_lock_t type);
1764
1828
size_t max_string_length(drizzled::Session::global_read_lock_t type);
1765
 
 
1766
1829
} /* namespace display */
1767
1830
 
1768
1831
} /* namespace drizzled */