~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Stewart Smith
  • Date: 2009-10-06 05:50:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1170.
  • Revision ID: stewart@flamingspork.com-20091006055022-uh79cvwppcszr3xk
removeĀ unusedĀ HA_KEYTYPE_BIT

Show diffs side-by-side

added added

removed removed

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