~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Patrick Crews
  • Date: 2011-01-29 14:17:35 UTC
  • mto: (2126.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: gleebix@gmail.com-20110129141735-3y2658vt5ur0a33o
Fixes to make test-dbqp

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