~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

Merge Stewart's dead code removal

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
20
20
 
21
21
/* Structs that defines the Table */
22
22
 
23
 
 
24
 
 
25
23
#ifndef DRIZZLED_TABLE_H
26
24
#define DRIZZLED_TABLE_H
27
25
 
28
26
#include <string>
29
 
#include <boost/dynamic_bitset.hpp>
30
27
 
 
28
#include "plugin/myisam/myisam.h"
 
29
#include "mysys/hash.h"
31
30
#include "drizzled/order.h"
32
31
#include "drizzled/filesort_info.h"
33
32
#include "drizzled/natural_join_column.h"
35
34
#include "drizzled/cursor.h"
36
35
#include "drizzled/lex_string.h"
37
36
#include "drizzled/table_list.h"
38
 
#include "drizzled/table/instance.h"
 
37
#include "drizzled/table_share.h"
39
38
#include "drizzled/atomics.h"
40
 
#include "drizzled/query_id.h"
41
 
 
42
 
#include "drizzled/visibility.h"
43
 
 
44
 
namespace drizzled
45
 
{
46
 
 
47
 
class COND_EQUAL;
48
 
class Field_blob;
 
39
 
49
40
class Item;
50
41
class Item_subselect;
51
 
class SecurityContext;
 
42
class Select_Lex_Unit;
52
43
class Select_Lex;
53
 
class Select_Lex_Unit;
 
44
class COND_EQUAL;
 
45
class Security_context;
54
46
class TableList;
55
 
namespace field { class Epoch; }
56
 
namespace plugin { class StorageEngine; }
 
47
class Field_timestamp;
 
48
class Field_blob;
 
49
 
 
50
extern drizzled::atomic<uint32_t> refresh_version;
57
51
 
58
52
typedef enum enum_table_category TABLE_CATEGORY;
59
 
typedef struct st_columndef MI_COLUMNDEF;
 
53
 
 
54
bool create_myisam_from_heap(Session *session, Table *table,
 
55
                             MI_COLUMNDEF *start_recinfo,
 
56
                             MI_COLUMNDEF **recinfo,
 
57
                             int error, bool ignore_last_dupp_key_error);
60
58
 
61
59
/**
62
60
 * Class representing a set of records, either in a temporary, 
63
61
 * normal, or derived table.
64
62
 */
65
 
class DRIZZLED_API Table 
 
63
class Table 
66
64
{
 
65
public:
 
66
 
 
67
  TableShare *s; /**< Pointer to the shared metadata about the table */
67
68
  Field **field; /**< Pointer to fields collection */
68
69
 
69
 
public:
70
 
  Field **getFields() const
71
 
  {
72
 
    return field;
73
 
  }
74
 
 
75
 
  Field *getField(uint32_t arg) const
76
 
  {
77
 
    return field[arg];
78
 
  }
79
 
 
80
 
  void setFields(Field **arg)
81
 
  {
82
 
    field= arg;
83
 
  }
84
 
 
85
 
  void setFieldAt(Field *arg, uint32_t arg_pos)
86
 
  {
87
 
    field[arg_pos]= arg;
88
 
  }
89
 
 
90
 
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
91
 
 
92
 
private:
 
70
  Cursor *file; /**< Pointer to the storage engine's Cursor managing this table */
93
71
  Table *next;
94
 
 
95
 
public:
96
 
  Table *getNext() const
97
 
  {
98
 
    return next;
99
 
  }
100
 
 
101
 
  Table **getNextPtr()
102
 
  {
103
 
    return &next;
104
 
  }
105
 
 
106
 
  void setNext(Table *arg)
107
 
  {
108
 
    next= arg;
109
 
  }
110
 
 
111
 
  void unlink()
112
 
  {
113
 
    getNext()->setPrev(getPrev());              /* remove from used chain */
114
 
    getPrev()->setNext(getNext());
115
 
  }
116
 
 
117
 
private:
118
72
  Table *prev;
119
 
public:
120
 
  Table *getPrev() const
121
 
  {
122
 
    return prev;
123
 
  }
124
 
 
125
 
  Table **getPrevPtr()
126
 
  {
127
 
    return &prev;
128
 
  }
129
 
 
130
 
  void setPrev(Table *arg)
131
 
  {
132
 
    prev= arg;
133
 
  }
134
 
 
135
 
  boost::dynamic_bitset<> *read_set; /* Active column sets */
136
 
  boost::dynamic_bitset<> *write_set; /* Active column sets */
 
73
 
 
74
  MyBitmap *read_set; /* Active column sets */
 
75
  MyBitmap *write_set; /* Active column sets */
137
76
 
138
77
  uint32_t tablenr;
139
 
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
 
78
  uint32_t db_stat; /**< information about the file as in Cursor.h */
140
79
 
141
 
  boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
142
 
  boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
143
 
  boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
 
80
  MyBitmap def_read_set; /**< Default read set of columns */
 
81
  MyBitmap def_write_set; /**< Default write set of columns */
 
82
  MyBitmap tmp_set; /* Not sure about this... */
144
83
 
145
84
  Session *in_use; /**< Pointer to the current session using this object */
146
 
  Session *getSession()
147
 
  {
148
 
    return in_use;
149
 
  }
150
 
 
151
 
  unsigned char *getInsertRecord() const
152
 
  {
153
 
    return record[0];
154
 
  }
155
 
 
156
 
  unsigned char *getUpdateRecord()
157
 
  {
158
 
    return record[1];
159
 
  }
160
85
 
161
86
  unsigned char *record[2]; /**< Pointer to "records" */
162
 
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
163
 
  KeyInfo  *key_info; /**< data of keys in database */
 
87
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
 
88
  KEY  *key_info; /**< data of keys in database */
164
89
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
165
90
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
166
 
  field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
 
91
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
167
92
 
168
93
  TableList *pos_in_table_list; /* Element referring to this table */
169
 
  Order *group;
170
 
  
171
 
  const char *getAlias() const
172
 
  {
173
 
    return _alias.c_str();
174
 
  }
175
 
 
176
 
  void clearAlias()
177
 
  {
178
 
    _alias.clear();
179
 
  }
180
 
 
181
 
  void setAlias(const char *arg)
182
 
  {
183
 
    _alias= arg;
184
 
  }
185
 
 
186
 
private:
187
 
  std::string _alias; /**< alias or table name if no alias */
188
 
public:
189
 
 
 
94
  order_st *group;
 
95
  const char *alias; /**< alias or table name if no alias */
190
96
  unsigned char *null_flags;
191
97
 
192
98
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
193
99
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
194
100
  uint32_t lock_count; /**< Number of locks */
195
101
  uint32_t used_fields;
196
 
  uint32_t status; /* What's in getInsertRecord() */
 
102
  uint32_t status; /* What's in record[0] */
197
103
  /* number of select if it is derived table */
198
104
  uint32_t derived_select_number;
199
105
  int current_lock; /**< Type of lock on table */
213
119
  bool null_row;
214
120
 
215
121
  bool force_index;
216
 
  bool distinct;
217
 
  bool const_table;
218
 
  bool no_rows;
 
122
  bool distinct,const_table,no_rows;
219
123
  bool key_read;
220
124
  bool no_keyread;
221
125
  /*
268
172
 
269
173
  /**
270
174
   * Estimate of number of records that satisfy SARGable part of the table
271
 
   * condition, or table->cursor->records if no SARGable condition could be
 
175
   * condition, or table->file->records if no SARGable condition could be
272
176
   * constructed.
273
177
   * This value is used by join optimizer as an estimate of number of records
274
178
   * that will pass the table condition (condition that depends on fields of
285
189
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
286
190
 
287
191
    Value of this variable is set for each statement in open_table() and
288
 
    if needed cleared later in statement processing code (see update_query()
 
192
    if needed cleared later in statement processing code (see mysql_update()
289
193
    as example).
290
194
  */
291
195
  timestamp_auto_set_type timestamp_field_type;
313
217
    The set is implemented as a bitmap.
314
218
  */
315
219
  key_map keys_in_use_for_query;
316
 
 
317
220
  /* Map of keys that can be used to calculate GROUP BY without sorting */
318
221
  key_map keys_in_use_for_group_by;
319
 
 
320
222
  /* Map of keys that can be used to calculate ORDER BY without sorting */
321
223
  key_map keys_in_use_for_order_by;
322
224
 
332
234
  uint32_t quick_key_parts[MAX_KEY];
333
235
  uint32_t quick_n_ranges[MAX_KEY];
334
236
 
335
 
private:
336
 
  memory::Root mem_root;
 
237
  MEM_ROOT mem_root;
 
238
  filesort_info_st sort;
337
239
 
338
 
  void init_mem_root()
 
240
  Table() : 
 
241
    s(NULL), 
 
242
    field(NULL),
 
243
    file(NULL),
 
244
    next(NULL),
 
245
    prev(NULL),
 
246
    read_set(NULL),
 
247
    write_set(NULL),
 
248
    tablenr(0),
 
249
    db_stat(0),
 
250
    in_use(NULL),
 
251
    insert_values(NULL),
 
252
    key_info(NULL),
 
253
    next_number_field(NULL),
 
254
    found_next_number_field(NULL),
 
255
    timestamp_field(NULL),
 
256
    pos_in_table_list(NULL),
 
257
    group(NULL),
 
258
    alias(NULL),
 
259
    null_flags(NULL),
 
260
    lock_position(0),
 
261
    lock_data_start(0),
 
262
    lock_count(0),
 
263
    used_fields(0),
 
264
    status(0),
 
265
    derived_select_number(0),
 
266
    current_lock(F_UNLCK),
 
267
    copy_blobs(false),
 
268
    maybe_null(false),
 
269
    null_row(false),
 
270
    force_index(false),
 
271
    distinct(false),
 
272
    const_table(false),
 
273
    no_rows(false),
 
274
    key_read(false),
 
275
    no_keyread(false),
 
276
    open_placeholder(false),
 
277
    locked_by_name(false),
 
278
    no_cache(false),
 
279
    auto_increment_field_not_null(false),
 
280
    alias_name_used(false),
 
281
    query_id(0), 
 
282
    quick_condition_rows(0),
 
283
    timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
 
284
    map(0)
339
285
  {
 
286
    record[0]= (unsigned char *) 0;
 
287
    record[1]= (unsigned char *) 0;
 
288
 
 
289
    covering_keys.reset();
 
290
 
 
291
    quick_keys.reset();
 
292
    merge_keys.reset();
 
293
 
 
294
    keys_in_use_for_query.reset();
 
295
    keys_in_use_for_group_by.reset();
 
296
    keys_in_use_for_order_by.reset();
 
297
 
 
298
    memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
 
299
    memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
 
300
 
 
301
    memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
 
302
    memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
 
303
 
340
304
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
341
 
  }
342
 
public:
343
 
  memory::Root *getMemRoot()
344
 
  {
345
 
    if (not mem_root.alloc_root_inited())
346
 
    {
347
 
      init_mem_root();
348
 
    }
349
 
 
350
 
    return &mem_root;
351
 
  }
352
 
 
353
 
  void *alloc_root(size_t arg)
354
 
  {
355
 
    if (not mem_root.alloc_root_inited())
356
 
    {
357
 
      init_mem_root();
358
 
    }
359
 
 
360
 
    return mem_root.alloc_root(arg);
361
 
  }
362
 
 
363
 
  char *strmake_root(const char *str_arg, size_t len_arg)
364
 
  {
365
 
    if (not mem_root.alloc_root_inited())
366
 
    {
367
 
      init_mem_root();
368
 
    }
369
 
 
370
 
    return mem_root.strmake_root(str_arg, len_arg);
371
 
  }
372
 
 
373
 
  filesort_info sort;
374
 
 
375
 
  Table();
376
 
  virtual ~Table();
 
305
    memset(&sort, 0, sizeof(filesort_info_st));
 
306
  }
377
307
 
378
308
  int report_error(int error);
379
309
  /**
380
310
   * Free information allocated by openfrm
381
311
   *
382
312
   * @param If true if we also want to free table_share
383
 
   * @note this should all be the destructor
384
313
   */
385
 
  int delete_table(bool free_share= false);
386
 
 
387
 
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
 
314
  int closefrm(bool free_share);
 
315
 
 
316
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg)
 
317
  {
 
318
    s= share;
 
319
    field= NULL;
 
320
 
 
321
    file= NULL;
 
322
    next= NULL;
 
323
    prev= NULL;
 
324
 
 
325
    read_set= NULL;
 
326
    write_set= NULL;
 
327
 
 
328
    tablenr= 0;
 
329
    db_stat= db_stat_arg;
 
330
 
 
331
    in_use= session;
 
332
    record[0]= (unsigned char *) 0;
 
333
    record[1]= (unsigned char *) 0;
 
334
 
 
335
    insert_values= NULL;
 
336
    key_info= NULL;
 
337
    next_number_field= NULL;
 
338
    found_next_number_field= NULL;
 
339
    timestamp_field= NULL;
 
340
 
 
341
    pos_in_table_list= NULL;
 
342
    group= NULL;
 
343
    alias= NULL;
 
344
    null_flags= NULL;
 
345
     
 
346
    lock_position= 0;
 
347
    lock_data_start= 0;
 
348
    lock_count= 0;
 
349
    used_fields= 0;
 
350
    status= 0;
 
351
    derived_select_number= 0;
 
352
    current_lock= F_UNLCK;
 
353
    copy_blobs= false;
 
354
 
 
355
    maybe_null= false;
 
356
 
 
357
    null_row= false;
 
358
 
 
359
    force_index= false;
 
360
    distinct= false;
 
361
    const_table= false;
 
362
    no_rows= false;
 
363
    key_read= false;
 
364
    no_keyread= false;
 
365
 
 
366
    open_placeholder= false;
 
367
    locked_by_name= false;
 
368
    no_cache= false;
 
369
 
 
370
    auto_increment_field_not_null= false;
 
371
    alias_name_used= false;
 
372
    
 
373
    query_id= 0;
 
374
    quick_condition_rows= 0;
 
375
     
 
376
    timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
 
377
    map= 0;
 
378
 
 
379
    reginfo.reset();
 
380
 
 
381
    covering_keys.reset();
 
382
 
 
383
    quick_keys.reset();
 
384
    merge_keys.reset();
 
385
 
 
386
    keys_in_use_for_query.reset();
 
387
    keys_in_use_for_group_by.reset();
 
388
    keys_in_use_for_order_by.reset();
 
389
 
 
390
    memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
 
391
    memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
 
392
 
 
393
    memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
 
394
    memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
 
395
 
 
396
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
397
    memset(&sort, 0, sizeof(filesort_info_st));
 
398
  }
388
399
 
389
400
  /* SHARE methods */
390
 
  virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
391
 
  virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
392
 
  virtual bool hasShare() const= 0; /* Get rid of this long term */
393
 
  virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
394
 
 
395
 
  virtual void release(void)= 0;
396
 
 
397
 
  uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
398
 
  uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
399
 
  uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
400
 
  uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
401
 
  uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
402
 
 
403
 
public:
404
 
  virtual bool hasVariableWidth() const
405
 
  {
406
 
    return getShare()->hasVariableWidth(); // We should calculate this.
407
 
  }
408
 
 
409
 
  virtual void setVariableWidth(void);
410
 
 
411
 
  Field_blob *getBlobFieldAt(uint32_t arg) const
412
 
  {
413
 
    if (arg < getShare()->blob_fields)
414
 
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
415
 
 
416
 
    return NULL;
417
 
  }
418
 
  inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
419
 
  inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
420
 
  inline uint32_t getNullFields() const { return getShare()->null_fields; }
421
 
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
422
 
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
423
 
  inline const char *getTableName()  const { return getShare()->getTableName(); }
424
 
 
425
 
  inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
426
 
  inline bool isNameLock() const { return open_placeholder; }
427
 
 
428
 
  uint32_t index_flags(uint32_t idx) const;
429
 
 
430
 
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
431
 
  {
432
 
    return getShare()->getEngine();
433
 
  }
434
 
 
435
 
  Cursor &getCursor() const /* table_type for handler */
436
 
  {
437
 
    assert(cursor);
438
 
    return *cursor;
439
 
  }
440
 
 
 
401
  inline TableShare *getShare() { return s; } /* Get rid of this long term */
 
402
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
 
403
  inline uint32_t sizeKeys() { return s->keys; }
 
404
  inline uint32_t sizeFields() { return s->fields; }
 
405
  inline uint32_t getRecordLength() { return s->reclength; }
 
406
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
 
407
  inline uint32_t *getBlobField() { return s->blob_field; }
 
408
  inline uint32_t getNullBytes() { return s->null_bytes; }
 
409
  inline uint32_t getNullFields() { return s->null_fields; }
 
410
  inline unsigned char *getDefaultValues() { return s->default_values; }
 
411
 
 
412
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
 
413
  inline bool isCrashed() { return s->crashed; }
 
414
  inline bool isNameLock() { return s->name_lock; }
 
415
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
416
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
 
417
 
 
418
  /* For TMP tables, should be pulled out as a class */
 
419
  void updateCreateInfo(HA_CREATE_INFO *create_info,
 
420
                        drizzled::message::Table *table_proto);
 
421
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
 
422
  bool create_myisam_tmp_table(KEY *keyinfo,
 
423
                               MI_COLUMNDEF *start_recinfo,
 
424
                               MI_COLUMNDEF **recinfo,
 
425
                               uint64_t options);
 
426
  void free_tmp_table(Session *session);
 
427
  bool open_tmp_table();
441
428
  size_t max_row_length(const unsigned char *data);
442
429
  uint32_t find_shortest_key(const key_map *usable_keys);
443
430
  bool compare_record(Field **ptr);
444
 
  bool records_are_comparable();
445
 
  bool compare_records();
 
431
  bool compare_record();
446
432
  /* TODO: the (re)storeRecord's may be able to be further condensed */
447
433
  void storeRecord();
448
434
  void storeRecordAsInsert();
451
437
  void restoreRecordAsDefault();
452
438
  void emptyRecord();
453
439
 
454
 
 
455
440
  /* See if this can be blown away */
456
441
  inline uint32_t getDBStat () { return db_stat; }
457
442
  inline uint32_t setDBStat () { return db_stat; }
474
459
  bool fill_item_list(List<Item> *item_list) const;
475
460
  void clear_column_bitmaps(void);
476
461
  void prepare_for_position(void);
477
 
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
 
462
  void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
478
463
  void mark_columns_used_by_index_no_reset(uint32_t index);
479
464
  void mark_columns_used_by_index(uint32_t index);
480
465
  void restore_column_maps_after_mark_index();
482
467
  void mark_columns_needed_for_update(void);
483
468
  void mark_columns_needed_for_delete(void);
484
469
  void mark_columns_needed_for_insert(void);
485
 
  void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
486
 
                          boost::dynamic_bitset<>& write_set_arg);
487
 
 
488
 
  void restore_column_map(const boost::dynamic_bitset<>& old);
489
 
 
490
 
  const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
 
470
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
 
471
                                 MyBitmap *write_set_arg)
 
472
  {
 
473
    read_set= read_set_arg;
 
474
    write_set= write_set_arg;
 
475
  }
 
476
  /**
 
477
   * Find field in table, no side effects, only purpose is to check for field
 
478
   * in table object and get reference to the field if found.
 
479
   *
 
480
   * @param Name of field searched for
 
481
   *
 
482
   * @retval
 
483
   *  0 field is not found
 
484
   * @retval
 
485
   *  non-0 pointer to field
 
486
   */
 
487
  Field *find_field_in_table_sef(const char *name);
 
488
 
 
489
  void restore_column_map(my_bitmap_map *old);
 
490
 
 
491
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
491
492
  inline void use_all_columns()
492
493
  {
493
 
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
 
494
    column_bitmaps_set(&s->all_set, &s->all_set);
494
495
  }
495
496
 
496
497
  inline void default_column_bitmaps()
502
503
  /* Both of the below should go away once we can move this bit to the field objects */
503
504
  inline bool isReadSet(uint32_t index)
504
505
  {
505
 
    return read_set->test(index);
 
506
    return read_set->isBitSet(index);
506
507
  }
507
508
 
508
509
  inline void setReadSet(uint32_t index)
509
510
  {
510
 
    read_set->set(index);
 
511
    read_set->setBit(index);
511
512
  }
512
513
 
513
514
  inline void setReadSet()
514
515
  {
515
 
    read_set->set();
 
516
    read_set->setAll();
516
517
  }
517
518
 
518
519
  inline void clearReadSet(uint32_t index)
519
520
  {
520
 
    read_set->reset(index);
 
521
    read_set->clearBit(index);
521
522
  }
522
523
 
523
524
  inline void clearReadSet()
524
525
  {
525
 
    read_set->reset();
 
526
    read_set->clearAll();
526
527
  }
527
528
 
528
529
  inline bool isWriteSet(uint32_t index)
529
530
  {
530
 
    return write_set->test(index);
 
531
    return write_set->isBitSet(index);
531
532
  }
532
533
 
533
534
  inline void setWriteSet(uint32_t index)
534
535
  {
535
 
    write_set->set(index);
 
536
    write_set->setBit(index);
536
537
  }
537
538
 
538
539
  inline void setWriteSet()
539
540
  {
540
 
    write_set->set();
 
541
    write_set->setAll();
541
542
  }
542
543
 
543
544
  inline void clearWriteSet(uint32_t index)
544
545
  {
545
 
    write_set->reset(index);
 
546
    write_set->clearBit(index);
546
547
  }
547
548
 
548
549
  inline void clearWriteSet()
549
550
  {
550
 
    write_set->reset();
 
551
    write_set->clearAll();
551
552
  }
552
553
 
553
554
  /* Is table open or should be treated as such by name-locking? */
555
556
  {
556
557
    return db_stat || open_placeholder;
557
558
  }
558
 
 
559
559
  /*
560
560
    Is this instance of the table should be reopen or represents a name-lock?
561
561
  */
562
 
  bool needs_reopen_or_name_lock() const;
 
562
  inline bool needs_reopen_or_name_lock()
 
563
  { 
 
564
    return s->version != refresh_version;
 
565
  }
563
566
 
564
567
  /**
565
568
    clean/setup table fields and map.
573
576
  {
574
577
    null_row= 1;
575
578
    status|= STATUS_NULL_ROW;
576
 
    memset(null_flags, 255, getShare()->null_bytes);
 
579
    memset(null_flags, 255, s->null_bytes);
577
580
  }
578
581
 
 
582
  bool rename_temporary_table(const char *db, const char *table_name);
579
583
  void free_io_cache();
580
584
  void filesort_free_buffers(bool full= false);
581
585
  void intern_close_table();
582
 
 
583
 
  void print_error(int error, myf errflag) const;
584
 
 
585
 
  /**
586
 
    @return
587
 
    key if error because of duplicated keys
588
 
  */
589
 
  uint32_t get_dup_key(int error) const
590
 
  {
591
 
    cursor->errkey  = (uint32_t) -1;
592
 
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
593
 
        error == HA_ERR_FOUND_DUPP_UNIQUE ||
594
 
        error == HA_ERR_DROP_INDEX_FK)
595
 
      cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
596
 
 
597
 
    return(cursor->errkey);
598
 
  }
599
 
 
600
 
  /*
601
 
    This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
602
 
  */
603
 
  bool operator<(const Table &right) const
604
 
  {
605
 
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
606
 
  }
607
 
 
608
 
  static bool compare(const Table *a, const Table *b)
609
 
  {
610
 
    return *a < *b;
611
 
  }
612
 
 
613
 
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
614
 
  {
615
 
    if (table.getShare())
616
 
    {
617
 
      output << "Table:(";
618
 
      output << table.getShare()->getSchemaName();
619
 
      output << ", ";
620
 
      output <<  table.getShare()->getTableName();
621
 
      output << ", ";
622
 
      output <<  table.getShare()->getTableTypeAsString();
623
 
      output << ")";
624
 
    }
625
 
    else
626
 
    {
627
 
      output << "Table:(has no share)";
628
 
    }
629
 
 
630
 
    return output;  // for multiple << operators.
631
 
  }
632
 
 
633
 
public:
634
 
  virtual bool isPlaceHolder(void) const
635
 
  {
636
 
    return false;
637
 
  }
638
586
};
639
587
 
640
 
/**
641
 
 * @class
642
 
 *  ForeignKeyInfo
643
 
 *
644
 
 * @brief
645
 
 *  This class defines the information for foreign keys.
646
 
 */
647
 
class ForeignKeyInfo
 
588
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
 
589
 
 
590
typedef struct st_foreign_key_info
648
591
{
649
 
public:
650
 
    /**
651
 
     * @brief
652
 
     *  This is the constructor with all properties set.
653
 
     *
654
 
     * @param[in] in_foreign_id The id of the foreign key
655
 
     * @param[in] in_referenced_db The referenced database name of the foreign key
656
 
     * @param[in] in_referenced_table The referenced table name of the foreign key
657
 
     * @param[in] in_update_method The update method of the foreign key.
658
 
     * @param[in] in_delete_method The delete method of the foreign key.
659
 
     * @param[in] in_referenced_key_name The name of referenced key
660
 
     * @param[in] in_foreign_fields The foreign fields
661
 
     * @param[in] in_referenced_fields The referenced fields
662
 
     */
663
 
    ForeignKeyInfo(LEX_STRING *in_foreign_id,
664
 
                   LEX_STRING *in_referenced_db,
665
 
                   LEX_STRING *in_referenced_table,
666
 
                   LEX_STRING *in_update_method,
667
 
                   LEX_STRING *in_delete_method,
668
 
                   LEX_STRING *in_referenced_key_name,
669
 
                   List<LEX_STRING> in_foreign_fields,
670
 
                   List<LEX_STRING> in_referenced_fields)
671
 
    :
672
 
      foreign_id(in_foreign_id),
673
 
      referenced_db(in_referenced_db),
674
 
      referenced_table(in_referenced_table),
675
 
      update_method(in_update_method),
676
 
      delete_method(in_delete_method),
677
 
      referenced_key_name(in_referenced_key_name),
678
 
      foreign_fields(in_foreign_fields),
679
 
      referenced_fields(in_referenced_fields)
680
 
    {}
681
 
 
682
 
    /**
683
 
     * @brief
684
 
     *  This is the default constructor. All properties are set to default values for their types.
685
 
     */
686
 
    ForeignKeyInfo()
687
 
    : foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
688
 
      update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
689
 
    {}
690
 
 
691
 
    /**
692
 
     * @brief
693
 
     *  Gets the foreign id.
694
 
     *
695
 
     * @ retval  the foreign id
696
 
     */
697
 
    const LEX_STRING *getForeignId() const
698
 
    {
699
 
        return foreign_id;
700
 
    }
701
 
 
702
 
    /**
703
 
     * @brief
704
 
     *  Gets the name of the referenced database.
705
 
     *
706
 
     * @ retval  the name of the referenced database
707
 
     */
708
 
    const LEX_STRING *getReferencedDb() const
709
 
    {
710
 
        return referenced_db;
711
 
    }
712
 
 
713
 
    /**
714
 
     * @brief
715
 
     *  Gets the name of the referenced table.
716
 
     *
717
 
     * @ retval  the name of the referenced table
718
 
     */
719
 
    const LEX_STRING *getReferencedTable() const
720
 
    {
721
 
        return referenced_table;
722
 
    }
723
 
 
724
 
    /**
725
 
     * @brief
726
 
     *  Gets the update method.
727
 
     *
728
 
     * @ retval  the update method
729
 
     */
730
 
    const LEX_STRING *getUpdateMethod() const
731
 
    {
732
 
        return update_method;
733
 
    }
734
 
 
735
 
    /**
736
 
     * @brief
737
 
     *  Gets the delete method.
738
 
     *
739
 
     * @ retval  the delete method
740
 
     */
741
 
    const LEX_STRING *getDeleteMethod() const
742
 
    {
743
 
        return delete_method;
744
 
    }
745
 
 
746
 
    /**
747
 
     * @brief
748
 
     *  Gets the name of the referenced key.
749
 
     *
750
 
     * @ retval  the name of the referenced key
751
 
     */
752
 
    const LEX_STRING *getReferencedKeyName() const
753
 
    {
754
 
        return referenced_key_name;
755
 
    }
756
 
 
757
 
    /**
758
 
     * @brief
759
 
     *  Gets the foreign fields.
760
 
     *
761
 
     * @ retval  the foreign fields
762
 
     */
763
 
    const List<LEX_STRING> &getForeignFields() const
764
 
    {
765
 
        return foreign_fields;
766
 
    }
767
 
 
768
 
    /**
769
 
     * @brief
770
 
     *  Gets the referenced fields.
771
 
     *
772
 
     * @ retval  the referenced fields
773
 
     */
774
 
    const List<LEX_STRING> &getReferencedFields() const
775
 
    {
776
 
        return referenced_fields;
777
 
    }
778
 
private:
779
 
    /**
780
 
     * The foreign id.
781
 
     */
782
 
    LEX_STRING *foreign_id;
783
 
    /**
784
 
     * The name of the reference database.
785
 
     */
786
 
    LEX_STRING *referenced_db;
787
 
    /**
788
 
     * The name of the reference table.
789
 
     */
790
 
    LEX_STRING *referenced_table;
791
 
    /**
792
 
     * The update method.
793
 
     */
794
 
    LEX_STRING *update_method;
795
 
    /**
796
 
     * The delete method.
797
 
     */
798
 
    LEX_STRING *delete_method;
799
 
    /**
800
 
     * The name of the referenced key.
801
 
     */
802
 
    LEX_STRING *referenced_key_name;
803
 
    /**
804
 
     * The foreign fields.
805
 
     */
806
 
    List<LEX_STRING> foreign_fields;
807
 
    /**
808
 
     * The referenced fields.
809
 
     */
810
 
    List<LEX_STRING> referenced_fields;
811
 
};
 
592
  LEX_STRING *forein_id;
 
593
  LEX_STRING *referenced_db;
 
594
  LEX_STRING *referenced_table;
 
595
  LEX_STRING *update_method;
 
596
  LEX_STRING *delete_method;
 
597
  LEX_STRING *referenced_key_name;
 
598
  List<LEX_STRING> foreign_fields;
 
599
  List<LEX_STRING> referenced_fields;
 
600
} FOREIGN_KEY_INFO;
 
601
 
 
602
 
812
603
 
813
604
class TableList;
814
605
 
815
 
#define JOIN_TYPE_LEFT  1
816
 
#define JOIN_TYPE_RIGHT 2
 
606
#define JOIN_TYPE_LEFT  1
 
607
#define JOIN_TYPE_RIGHT 2
817
608
 
818
609
struct st_lex;
819
610
class select_union;
820
611
class Tmp_Table_Param;
821
612
 
822
 
void free_blobs(Table *table);
823
 
int set_zone(int nr,int min_zone,int max_zone);
824
 
uint32_t convert_period_to_month(uint32_t period);
825
 
uint32_t convert_month_to_period(uint32_t month);
826
 
 
827
 
int test_if_number(char *str,int *res,bool allow_wildcards);
828
 
void change_byte(unsigned char *,uint,char,char);
829
 
 
830
 
namespace optimizer { class SqlSelect; }
831
 
 
832
 
void change_double_for_sort(double nr,unsigned char *to);
833
 
int get_quick_record(optimizer::SqlSelect *select);
834
 
 
835
 
void find_date(char *pos,uint32_t *vek,uint32_t flag);
836
 
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
837
 
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
838
 
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
839
 
void append_unescaped(String *res, const char *pos, uint32_t length);
840
 
 
841
 
DRIZZLED_API int rename_file_ext(const char * from,const char * to,const char * ext);
842
 
bool check_column_name(const char *name);
843
 
bool check_db_name(Session *session, identifier::Schema &schema);
844
 
bool check_table_name(const char *name, uint32_t length);
845
 
 
846
 
} /* namespace drizzled */
847
 
 
848
 
#include "drizzled/table/singular.h"
849
 
#include "drizzled/table/concurrent.h"
 
613
typedef struct st_changed_table_list
 
614
{
 
615
  struct        st_changed_table_list *next;
 
616
  char          *key;
 
617
  uint32_t key_length;
 
618
} CHANGED_TableList;
 
619
 
 
620
struct open_table_list_st
 
621
{
 
622
  std::string   db;
 
623
  std::string   table;
 
624
  uint32_t in_use;
 
625
  uint32_t locked;
 
626
 
 
627
  open_table_list_st() :
 
628
    in_use(0),
 
629
    locked(0)
 
630
  { }
 
631
 
 
632
};
850
633
 
851
634
#endif /* DRIZZLED_TABLE_H */