~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Brian Aker
  • Date: 2010-07-09 20:51:34 UTC
  • mfrom: (1643.4.3 drizzle)
  • Revision ID: brian@gaz-20100709205134-ru4s0889youfrmm5
Merge of Patrick

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <drizzled/sql_error.h>
32
32
#include <drizzled/file_exchange.h>
33
33
#include <drizzled/select_result_interceptor.h>
 
34
#include <drizzled/statistics_variables.h>
34
35
#include <drizzled/xid.h>
35
36
#include "drizzled/query_id.h"
36
37
#include "drizzled/named_savepoint.h"
59
60
{
60
61
class Client;
61
62
class Scheduler;
 
63
class EventObserverList;
62
64
}
 
65
 
63
66
namespace message
64
67
{
65
68
class Transaction;
75
78
class CopyField;
76
79
class Table_ident;
77
80
 
 
81
class TableShareInstance;
 
82
 
78
83
extern char internal_table_name[2];
79
84
extern char empty_c_string[1];
80
85
extern const char **errmesg;
222
227
namespace drizzled
223
228
{
224
229
 
225
 
/**
226
 
 * Per-session local status counters
227
 
 */
228
 
typedef struct system_status_var
229
 
{
230
 
  uint64_t bytes_received;
231
 
  uint64_t bytes_sent;
232
 
  ulong com_other;
233
 
  ulong com_stat[(uint32_t) SQLCOM_END];
234
 
  ulong created_tmp_disk_tables;
235
 
  ulong created_tmp_tables;
236
 
  ulong ha_commit_count;
237
 
  ulong ha_delete_count;
238
 
  ulong ha_read_first_count;
239
 
  ulong ha_read_last_count;
240
 
  ulong ha_read_key_count;
241
 
  ulong ha_read_next_count;
242
 
  ulong ha_read_prev_count;
243
 
  ulong ha_read_rnd_count;
244
 
  ulong ha_read_rnd_next_count;
245
 
  ulong ha_rollback_count;
246
 
  ulong ha_update_count;
247
 
  ulong ha_write_count;
248
 
  ulong ha_prepare_count;
249
 
  ulong ha_savepoint_count;
250
 
  ulong ha_savepoint_rollback_count;
251
 
 
252
 
  /* KEY_CACHE parts. These are copies of the original */
253
 
  ulong key_blocks_changed;
254
 
  ulong key_blocks_used;
255
 
  ulong key_cache_r_requests;
256
 
  ulong key_cache_read;
257
 
  ulong key_cache_w_requests;
258
 
  ulong key_cache_write;
259
 
  /* END OF KEY_CACHE parts */
260
 
 
261
 
  ulong net_big_packet_count;
262
 
  ulong select_full_join_count;
263
 
  ulong select_full_range_join_count;
264
 
  ulong select_range_count;
265
 
  ulong select_range_check_count;
266
 
  ulong select_scan_count;
267
 
  ulong long_query_count;
268
 
  ulong filesort_merge_passes;
269
 
  ulong filesort_range_count;
270
 
  ulong filesort_rows;
271
 
  ulong filesort_scan_count;
272
 
  /*
273
 
    Number of statements sent from the client
274
 
  */
275
 
  ulong questions;
276
 
 
277
 
  /*
278
 
    IMPORTANT!
279
 
    SEE last_system_status_var DEFINITION BELOW.
280
 
 
281
 
    Below 'last_system_status_var' are all variables which doesn't make any
282
 
    sense to add to the /global/ status variable counter.
283
 
  */
284
 
  double last_query_cost;
285
 
} system_status_var;
286
 
 
287
 
/*
288
 
  This is used for 'SHOW STATUS'. It must be updated to the last ulong
289
 
  variable in system_status_var which is makes sens to add to the global
290
 
  counter
291
 
*/
292
 
 
293
 
#define last_system_status_var questions
294
 
 
295
230
void mark_transaction_to_rollback(Session *session, bool all);
296
231
 
297
232
extern pthread_mutex_t LOCK_xid_cache;
298
233
extern HASH xid_cache;
299
234
 
300
 
 
301
235
/**
302
236
  Storage engine specific thread local data.
303
237
*/
367
301
  enum enum_mark_columns mark_used_columns;
368
302
  inline void* alloc(size_t size)
369
303
  {
370
 
    return alloc_root(mem_root,size);
 
304
    return mem_root->alloc_root(size);
371
305
  }
372
306
  inline void* calloc(size_t size)
373
307
  {
374
308
    void *ptr;
375
 
    if ((ptr= alloc_root(mem_root,size)))
 
309
    if ((ptr= mem_root->alloc_root(size)))
376
310
      memset(ptr, 0, size);
377
311
    return ptr;
378
312
  }
379
313
  inline char *strdup(const char *str)
380
314
  {
381
 
    return strdup_root(mem_root,str);
 
315
    return mem_root->strdup_root(str);
382
316
  }
383
317
  inline char *strmake(const char *str, size_t size)
384
318
  {
385
 
    return strmake_root(mem_root,str,size);
 
319
    return mem_root->strmake_root(str,size);
386
320
  }
387
321
  inline void *memdup(const void *str, size_t size)
388
322
  {
389
 
    return memdup_root(mem_root,str,size);
 
323
    return mem_root->memdup_root(str, size);
390
324
  }
391
325
  inline void *memdup_w_gap(const void *str, size_t size, uint32_t gap)
392
326
  {
393
327
    void *ptr;
394
 
    if ((ptr= alloc_root(mem_root,size+gap)))
 
328
    if ((ptr= mem_root->alloc_root(size + gap)))
395
329
      memcpy(ptr,str,size);
396
330
    return ptr;
397
331
  }
403
337
   */
404
338
  Item *free_list;
405
339
  memory::Root *mem_root; /**< Pointer to current memroot */
 
340
 
 
341
 
 
342
  memory::Root *getMemRoot()
 
343
  {
 
344
    return mem_root;
 
345
  }
406
346
  /**
407
347
   * Uniquely identifies each statement object in thread scope; change during
408
348
   * statement lifetime.
464
404
private:
465
405
  SecurityContext security_ctx;
466
406
 
 
407
  int32_t scoreboard_index;
 
408
 
467
409
  inline void checkSentry() const
468
410
  {
469
411
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
479
421
    return security_ctx;
480
422
  }
481
423
 
 
424
  int32_t getScoreboardIndex()
 
425
  {
 
426
    return scoreboard_index;
 
427
  }
 
428
 
 
429
  void setScoreboardIndex(int32_t in_scoreboard_index)
 
430
  {
 
431
    scoreboard_index= in_scoreboard_index;
 
432
  }
 
433
 
482
434
  /**
483
435
   * Is this session viewable by the current user?
484
436
   */
1104
1056
    return (abort_on_warning);
1105
1057
  }
1106
1058
  void set_status_var_init();
1107
 
  void reset_n_backup_open_tables_state(Open_tables_state *backup);
1108
 
  void restore_backup_open_tables_state(Open_tables_state *backup);
1109
1059
 
1110
1060
  /**
1111
1061
    Set the current database; use deep copy of C-string.
1252
1202
  /** Pointers to memory managed by the ReplicationServices component */
1253
1203
  message::Transaction *transaction_message;
1254
1204
  message::Statement *statement_message;
1255
 
  /** Microsecond timestamp of when Session connected */
 
1205
  plugin::EventObserverList *session_event_observers;
 
1206
  
 
1207
  /* Schema observers are mapped to databases. */
 
1208
  std::map<std::string, plugin::EventObserverList *> schema_event_observers;
 
1209
 
 
1210
 
 
1211
public:
 
1212
  plugin::EventObserverList *getSessionObservers() 
 
1213
  { 
 
1214
    return session_event_observers;
 
1215
  }
 
1216
  
 
1217
  void setSessionObservers(plugin::EventObserverList *observers) 
 
1218
  { 
 
1219
    session_event_observers= observers;
 
1220
  }
 
1221
  
 
1222
  /* For schema event observers there is one set of observers per database. */
 
1223
  plugin::EventObserverList *getSchemaObservers(const std::string &db_name) 
 
1224
  { 
 
1225
    std::map<std::string, plugin::EventObserverList *>::iterator it;
 
1226
    
 
1227
    it= schema_event_observers.find(db_name);
 
1228
    if (it == schema_event_observers.end())
 
1229
      return NULL;
 
1230
      
 
1231
    return it->second;
 
1232
  }
 
1233
  
 
1234
  void setSchemaObservers(const std::string &db_name, plugin::EventObserverList *observers) 
 
1235
  { 
 
1236
    std::map<std::string, plugin::EventObserverList *>::iterator it;
 
1237
 
 
1238
    it= schema_event_observers.find(db_name);
 
1239
    if (it != schema_event_observers.end())
 
1240
      schema_event_observers.erase(it);;
 
1241
 
 
1242
    if (observers)
 
1243
      schema_event_observers[db_name] = observers;
 
1244
  }
 
1245
  
 
1246
  
 
1247
 private:
 
1248
 /** Microsecond timestamp of when Session connected */
1256
1249
  uint64_t connect_microseconds;
1257
1250
  const char *proc_info;
1258
1251
 
1355
1348
                            bool send_refresh= false);
1356
1349
  void close_open_tables();
1357
1350
  void close_data_files_and_morph_locks(TableIdentifier &identifier);
1358
 
  void close_data_files_and_morph_locks(const char *db, const char *table_name);
1359
1351
 
1360
1352
private:
1361
1353
  bool free_cached_table();
1416
1408
  void close_cached_table(Table *table);
1417
1409
 
1418
1410
  /* Create a lock in the cache */
1419
 
  Table *table_cache_insert_placeholder(const char *key, uint32_t key_length);
 
1411
  Table *table_cache_insert_placeholder(const char *db_name, const char *table_name, const char *key, uint32_t key_length);
1420
1412
  bool lock_table_name_if_not_cached(TableIdentifier &identifier, Table **table);
1421
1413
  bool lock_table_name_if_not_cached(const char *db,
1422
1414
                                     const char *table_name, Table **table);
1423
1415
 
1424
 
  typedef drizzled::hash_map<std::string, message::Table> TableMessageCache;
 
1416
  typedef unordered_map<std::string, message::Table> TableMessageCache;
1425
1417
  TableMessageCache table_message_cache;
1426
1418
 
1427
 
  bool storeTableMessage(TableIdentifier &identifier, message::Table &table_message);
1428
 
  bool removeTableMessage(TableIdentifier &identifier);
1429
 
  bool getTableMessage(TableIdentifier &identifier, message::Table &table_message);
1430
 
  bool doesTableMessageExist(TableIdentifier &identifier);
1431
 
  bool renameTableMessage(TableIdentifier &from, TableIdentifier &to);
 
1419
  bool storeTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1420
  bool removeTableMessage(const TableIdentifier &identifier);
 
1421
  bool getTableMessage(const TableIdentifier &identifier, message::Table &table_message);
 
1422
  bool doesTableMessageExist(const TableIdentifier &identifier);
 
1423
  bool renameTableMessage(const TableIdentifier &from, const TableIdentifier &to);
1432
1424
 
1433
1425
  /* Work with temporary tables */
1434
1426
  Table *find_temporary_table(TableList *table_list);
1436
1428
  Table *find_temporary_table(TableIdentifier &identifier);
1437
1429
 
1438
1430
  void doGetTableNames(CachedDirectory &directory,
1439
 
                       SchemaIdentifier &schema_identifier,
 
1431
                       const SchemaIdentifier &schema_identifier,
1440
1432
                       std::set<std::string>& set_of_names);
1441
 
  void doGetTableNames(SchemaIdentifier &schema_identifier,
 
1433
  void doGetTableNames(const SchemaIdentifier &schema_identifier,
1442
1434
                       std::set<std::string>& set_of_names);
1443
1435
 
1444
1436
  void doGetTableIdentifiers(CachedDirectory &directory,
1445
 
                             SchemaIdentifier &schema_identifier,
 
1437
                             const SchemaIdentifier &schema_identifier,
1446
1438
                             TableIdentifiers &set_of_identifiers);
1447
 
  void doGetTableIdentifiers(SchemaIdentifier &schema_identifier,
 
1439
  void doGetTableIdentifiers(const SchemaIdentifier &schema_identifier,
1448
1440
                             TableIdentifiers &set_of_identifiers);
1449
1441
 
1450
 
  int doGetTableDefinition(drizzled::TableIdentifier &identifier,
 
1442
  int doGetTableDefinition(const drizzled::TableIdentifier &identifier,
1451
1443
                           message::Table &table_proto);
1452
 
  bool doDoesTableExist(TableIdentifier &identifier);
 
1444
  bool doDoesTableExist(const drizzled::TableIdentifier &identifier);
1453
1445
 
1454
1446
  void close_temporary_tables();
1455
1447
  void close_temporary_table(Table *table);
1462
1454
  void dumpTemporaryTableNames(const char *id);
1463
1455
  int drop_temporary_table(TableList *table_list);
1464
1456
  bool rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier);
1465
 
  bool rm_temporary_table(TableIdentifier &identifier);
 
1457
  bool rm_temporary_table(TableIdentifier &identifier, bool best_effort= false);
1466
1458
  Table *open_temporary_table(TableIdentifier &identifier,
1467
1459
                              bool link_in_list= true);
1468
1460
 
1475
1467
  int setup_conds(TableList *leaves, COND **conds);
1476
1468
  int lock_tables(TableList *tables, uint32_t count, bool *need_reopen);
1477
1469
 
 
1470
  Table *create_virtual_tmp_table(List<CreateField> &field_list);
 
1471
 
 
1472
 
1478
1473
 
1479
1474
  /**
1480
1475
    Return the default storage engine
1493
1488
 
1494
1489
  static void unlink(Session *session);
1495
1490
 
 
1491
  void get_xid(DRIZZLE_XID *xid); // Innodb only
 
1492
 
 
1493
private:
 
1494
  std::vector<TableShareInstance *> temporary_shares;
 
1495
 
 
1496
public:
 
1497
  TableShareInstance *getTemporaryShare(TableIdentifier::Type type_arg);
1496
1498
};
1497
1499
 
1498
 
class JOIN;
 
1500
class Join;
1499
1501
 
1500
1502
#define ESCAPE_CHARS "ntrb0ZN" // keep synchronous with READ_INFO::unescape
1501
1503
 
1572
1574
static const std::bitset<CF_BIT_SIZE> CF_SHOW_TABLE_COMMAND(1 << CF_BIT_SHOW_TABLE_COMMAND);
1573
1575
static const std::bitset<CF_BIT_SIZE> CF_WRITE_LOGS_COMMAND(1 << CF_BIT_WRITE_LOGS_COMMAND);
1574
1576
 
1575
 
/* Functions in sql_class.cc */
1576
 
void add_to_status(system_status_var *to_var, system_status_var *from_var);
1577
 
 
1578
 
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
1579
 
                        system_status_var *dec_var);
1580
 
 
1581
1577
} /* namespace drizzled */
1582
1578
 
1583
1579
#endif /* DRIZZLED_SESSION_H */