~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Daniel Nichter
  • Date: 2011-10-23 16:01:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2448.
  • Revision ID: daniel@percona.com-20111023160137-7ac3blgz8z4tf8za
Add Administration Getting Started and Logging.  Capitalize SQL clause keywords.

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
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
/* Structs that defines the Table */
22
 
 
23
 
#ifndef DRIZZLED_TABLE_H
24
 
#define DRIZZLED_TABLE_H
25
 
 
26
 
#include <storage/myisam/myisam.h>
 
21
#pragma once
 
22
 
 
23
#include <string>
 
24
#include <boost/dynamic_bitset.hpp>
 
25
 
27
26
#include <drizzled/order.h>
28
27
#include <drizzled/filesort_info.h>
29
28
#include <drizzled/natural_join_column.h>
30
29
#include <drizzled/field_iterator.h>
31
 
#include <mysys/hash.h>
32
 
#include <drizzled/handler.h>
 
30
#include <drizzled/cursor.h>
33
31
#include <drizzled/lex_string.h>
34
 
#include <drizzled/table_list.h>
35
 
 
36
 
class Item;
37
 
class Item_subselect;
38
 
class st_select_lex_unit;
39
 
class st_select_lex;
40
 
class COND_EQUAL;
41
 
class Security_context;
42
 
class TableList;
43
 
 
44
 
/*************************************************************************/
45
 
 
46
 
 
47
 
class Field_timestamp;
48
 
class Field_blob;
49
 
 
50
 
typedef enum enum_table_category TABLE_CATEGORY;
51
 
 
52
 
TABLE_CATEGORY get_table_category(const LEX_STRING *db,
53
 
                                  const LEX_STRING *name);
54
 
 
55
 
/*
56
 
  This structure is shared between different table objects. There is one
57
 
  instance of table share per one table in the database.
58
 
*/
59
 
 
60
 
typedef struct st_table_share
61
 
{
62
 
  st_table_share() {}                    /* Remove gcc warning */
63
 
 
64
 
  /** Category of this table. */
65
 
  TABLE_CATEGORY table_category;
66
 
 
67
 
  /* hash of field names (contains pointers to elements of field array) */
68
 
  HASH  name_hash;                      /* hash of field names */
69
 
  MEM_ROOT mem_root;
70
 
  TYPELIB keynames;                     /* Pointers to keynames */
71
 
  TYPELIB fieldnames;                   /* Pointer to fieldnames */
72
 
  TYPELIB *intervals;                   /* pointer to interval info */
73
 
  pthread_mutex_t mutex;                /* For locking the share  */
74
 
  pthread_cond_t cond;                  /* To signal that share is ready */
75
 
  struct st_table_share *next,          /* Link to unused shares */
76
 
    **prev;
77
 
 
78
 
  /* The following is copied to each Table on OPEN */
79
 
  Field **field;
80
 
  Field **found_next_number_field;
81
 
  Field *timestamp_field;               /* Used only during open */
82
 
  KEY  *key_info;                       /* data of keys in database */
83
 
  uint  *blob_field;                    /* Index to blobs in Field arrray*/
84
 
 
85
 
  unsigned char *default_values;                /* row with default values */
86
 
  LEX_STRING comment;                   /* Comment about table */
87
 
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
88
 
 
89
 
  MY_BITMAP all_set;
90
 
  /*
91
 
    Key which is used for looking-up table in table cache and in the list
92
 
    of thread's temporary tables. Has the form of:
93
 
      "database_name\0table_name\0" + optional part for temporary tables.
94
 
 
95
 
    Note that all three 'table_cache_key', 'db' and 'table_name' members
96
 
    must be set (and be non-zero) for tables in table cache. They also
97
 
    should correspond to each other.
98
 
    To ensure this one can use set_table_cache() methods.
99
 
  */
100
 
  LEX_STRING table_cache_key;
101
 
  LEX_STRING db;                        /* Pointer to db */
102
 
  LEX_STRING table_name;                /* Table name (for open) */
103
 
  LEX_STRING path;      /* Path to .frm file (from datadir) */
104
 
  LEX_STRING normalized_path;           /* unpack_filename(path) */
105
 
  LEX_STRING connect_string;
106
 
 
107
 
  /*
108
 
     Set of keys in use, implemented as a Bitmap.
109
 
     Excludes keys disabled by ALTER Table ... DISABLE KEYS.
110
 
  */
111
 
  key_map keys_in_use;
112
 
  key_map keys_for_keyread;
113
 
  ha_rows min_rows, max_rows;           /* create information */
114
 
  uint32_t   avg_row_length;            /* create information */
115
 
  uint32_t   block_size;                   /* create information */
116
 
  uint32_t   version, mysql_version;
117
 
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
118
 
  uint32_t   reclength;                 /* Recordlength */
119
 
  uint32_t   stored_rec_length;         /* Stored record length 
120
 
                                           (no generated-only virtual fields) */
121
 
 
122
 
  plugin_ref db_plugin;                 /* storage engine plugin */
123
 
  inline handlerton *db_type() const    /* table_type for handler */
124
 
  {
125
 
    // assert(db_plugin);
126
 
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
127
 
  }
128
 
  enum row_type row_type;               /* How rows are stored */
129
 
  enum tmp_table_type tmp_table;
130
 
  enum ha_choice transactional;
131
 
  enum ha_choice page_checksum;
132
 
 
133
 
  uint32_t ref_count;       /* How many Table objects uses this */
134
 
  uint32_t open_count;                  /* Number of tables in open list */
135
 
  uint32_t blob_ptr_size;                       /* 4 or 8 */
136
 
  uint32_t key_block_size;                      /* create key_block_size, if used */
137
 
  uint32_t null_bytes, last_null_bit_pos;
138
 
  uint32_t fields;                              /* Number of fields */
139
 
  uint32_t stored_fields;                   /* Number of stored fields 
140
 
                                           (i.e. without generated-only ones) */
141
 
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
142
 
  uint32_t keys, key_parts;
143
 
  uint32_t max_key_length, max_unique_length, total_key_length;
144
 
  uint32_t uniques;                         /* Number of UNIQUE index */
145
 
  uint32_t null_fields;                 /* number of null fields */
146
 
  uint32_t blob_fields;                 /* number of blob fields */
147
 
  uint32_t timestamp_field_offset;              /* Field number for timestamp field */
148
 
  uint32_t varchar_fields;                  /* number of varchar fields */
149
 
  uint32_t db_create_options;           /* Create options from database */
150
 
  uint32_t db_options_in_use;           /* Options in use */
151
 
  uint32_t db_record_offset;            /* if HA_REC_IN_SEQ */
152
 
  uint32_t rowid_field_offset;          /* Field_nr +1 to rowid field */
153
 
  /* Index of auto-updated TIMESTAMP field in field array */
154
 
  uint32_t primary_key;
155
 
  uint32_t next_number_index;               /* autoincrement key number */
156
 
  uint32_t next_number_key_offset;          /* autoinc keypart offset in a key */
157
 
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
158
 
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
159
 
  uint32_t column_bitmap_size;
160
 
 
161
 
  uint32_t vfields;                         /* Number of virtual fields */
162
 
  bool null_field_first;
163
 
  bool db_low_byte_first;               /* Portable row format */
164
 
  bool crashed;
165
 
  bool name_lock, replace_with_name_lock;
166
 
  bool waiting_on_cond;                 /* Protection against free */
167
 
  uint32_t table_map_id;                   /* for row-based replication */
168
 
  uint64_t table_map_version;
169
 
 
170
 
  /*
171
 
    Cache for row-based replication table share checks that does not
172
 
    need to be repeated. Possible values are: -1 when cache value is
173
 
    not calculated yet, 0 when table *shall not* be replicated, 1 when
174
 
    table *may* be replicated.
175
 
  */
176
 
  int cached_row_logging_check;
177
 
 
178
 
  /*
179
 
    Set share's table cache key and update its db and table name appropriately.
180
 
 
181
 
    SYNOPSIS
182
 
      set_table_cache_key()
183
 
        key_buff    Buffer with already built table cache key to be
184
 
                    referenced from share.
185
 
        key_length  Key length.
186
 
 
187
 
    NOTES
188
 
      Since 'key_buff' buffer will be referenced from share it should has same
189
 
      life-time as share itself.
190
 
      This method automatically ensures that TABLE_SHARE::table_name/db have
191
 
      appropriate values by using table cache key as their source.
192
 
  */
193
 
 
194
 
  void set_table_cache_key(char *key_buff, uint32_t key_length)
195
 
  {
196
 
    table_cache_key.str= key_buff;
197
 
    table_cache_key.length= key_length;
198
 
    /*
199
 
      Let us use the fact that the key is "db/0/table_name/0" + optional
200
 
      part for temporary tables.
201
 
    */
202
 
    db.str=            table_cache_key.str;
203
 
    db.length=         strlen(db.str);
204
 
    table_name.str=    db.str + db.length + 1;
205
 
    table_name.length= strlen(table_name.str);
206
 
  }
207
 
 
208
 
 
209
 
  /*
210
 
    Set share's table cache key and update its db and table name appropriately.
211
 
 
212
 
    SYNOPSIS
213
 
      set_table_cache_key()
214
 
        key_buff    Buffer to be used as storage for table cache key
215
 
                    (should be at least key_length bytes).
216
 
        key         Value for table cache key.
217
 
        key_length  Key length.
218
 
 
219
 
    NOTE
220
 
      Since 'key_buff' buffer will be used as storage for table cache key
221
 
      it should has same life-time as share itself.
222
 
  */
223
 
 
224
 
  void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
225
 
  {
226
 
    memcpy(key_buff, key, key_length);
227
 
    set_table_cache_key(key_buff, key_length);
228
 
  }
229
 
 
230
 
  inline bool honor_global_locks()
231
 
  {
232
 
    return (table_category == TABLE_CATEGORY_USER);
233
 
  }
234
 
 
235
 
  inline uint32_t get_table_def_version()
236
 
  {
237
 
    return table_map_id;
238
 
  }
239
 
 
240
 
} TABLE_SHARE;
241
 
 
242
 
 
243
 
extern uint32_t refresh_version;
244
 
 
245
 
typedef struct st_table_field_w_type
246
 
{
247
 
  LEX_STRING name;
248
 
  LEX_STRING type;
249
 
  LEX_STRING cset;
250
 
} TABLE_FIELD_W_TYPE;
251
 
 
252
 
bool create_myisam_from_heap(Session *session, Table *table,
253
 
                             MI_COLUMNDEF *start_recinfo,
254
 
                             MI_COLUMNDEF **recinfo, 
255
 
                             int error, bool ignore_last_dupp_key_error);
256
 
 
257
 
class Table {
258
 
 
259
 
public:
260
 
  TABLE_SHARE   *s;
261
 
  Table() {}                               /* Remove gcc warning */
262
 
 
263
 
  /* SHARE methods */
264
 
  inline TABLE_SHARE *getShare() { return s; } /* Get rid of this long term */
265
 
  inline void setShare(TABLE_SHARE *new_share) { s= new_share; } /* Get rid of this long term */
266
 
  inline uint32_t sizeKeys() { return s->keys; }
267
 
  inline uint32_t sizeFields() { return s->fields; }
268
 
  inline uint32_t getRecordLength() { return s->reclength; }
269
 
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
270
 
  inline uint32_t *getBlobField() { return s->blob_field; }
271
 
  inline uint32_t getNullBytes() { return s->null_bytes; }
272
 
  inline uint32_t getNullFields() { return s->null_fields; }
273
 
  inline unsigned char *getDefaultValues() { return s->default_values; }
274
 
 
275
 
  inline bool isNullFieldFirst() { return s->null_field_first; }
276
 
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; }         /* Portable row format */
277
 
  inline bool isCrashed() { return s->crashed; }
278
 
  inline bool isNameLock() { return s->name_lock; } 
279
 
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
280
 
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; }                 /* Protection against free */
281
 
 
282
 
  /* For TMP tables, should be pulled out as a class */
283
 
  void updateCreateInfo(HA_CREATE_INFO *create_info);
284
 
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
285
 
  bool create_myisam_tmp_table(KEY *keyinfo, 
286
 
                               MI_COLUMNDEF *start_recinfo,
287
 
                               MI_COLUMNDEF **recinfo, 
288
 
                               uint64_t options);
289
 
  void free_tmp_table(Session *session);
290
 
  bool open_tmp_table();
291
 
  size_t max_row_length(const unsigned char *data);
292
 
  uint32_t find_shortest_key(const key_map *usable_keys);
293
 
  bool compare_record(Field **ptr);
294
 
  bool compare_record();
295
 
 
296
 
  bool table_check_intact(const uint32_t table_f_count, const TABLE_FIELD_W_TYPE *table_def);
297
 
 
298
 
  /* See if this can be blown away */
299
 
  inline uint32_t getDBStat () { return db_stat; }
300
 
  inline uint32_t setDBStat () { return db_stat; }
301
 
  uint          db_stat;                /* mode of file as in handler.h */
302
 
 
303
 
  handler       *file;
304
 
  Table *next, *prev;
305
 
 
306
 
  Session       *in_use;                        /* Which thread uses this */
307
 
  Field **field;                        /* Pointer to fields */
308
 
 
309
 
  unsigned char *record[2];                     /* Pointer to records */
310
 
  unsigned char *write_row_record;              /* Used as optimisation in
311
 
                                           Session::write_row */
312
 
  unsigned char *insert_values;                  /* used by INSERT ... UPDATE */
313
 
  /* 
314
 
    Map of keys that can be used to retrieve all data from this table 
315
 
    needed by the query without reading the row.
316
 
  */
317
 
  key_map covering_keys;
318
 
  key_map quick_keys, merge_keys;
319
 
  /*
320
 
    A set of keys that can be used in the query that references this
321
 
    table.
322
 
 
323
 
    All indexes disabled on the table's TABLE_SHARE (see Table::s) will be 
324
 
    subtracted from this set upon instantiation. Thus for any Table t it holds
325
 
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we 
326
 
    must not introduce any new keys here (see setup_tables).
327
 
 
328
 
    The set is implemented as a bitmap.
329
 
  */
330
 
  key_map keys_in_use_for_query;
331
 
  /* Map of keys that can be used to calculate GROUP BY without sorting */
332
 
  key_map keys_in_use_for_group_by;
333
 
  /* Map of keys that can be used to calculate ORDER BY without sorting */
334
 
  key_map keys_in_use_for_order_by;
335
 
  KEY  *key_info;                       /* data of keys in database */
336
 
 
337
 
  Field *next_number_field;             /* Set if next_number is activated */
338
 
  Field *found_next_number_field;       /* Set on open */
339
 
  Field_timestamp *timestamp_field;
340
 
  Field **vfield;                       /* Pointer to virtual fields*/
341
 
 
342
 
  TableList *pos_in_table_list;/* Element referring to this table */
343
 
  order_st *group;
344
 
  const char    *alias;                   /* alias or table name */
345
 
  unsigned char         *null_flags;
346
 
  my_bitmap_map *bitmap_init_value;
347
 
  MY_BITMAP     def_read_set, def_write_set, tmp_set; /* containers */
348
 
  MY_BITMAP     *read_set, *write_set;          /* Active column sets */
349
 
  /*
350
 
   The ID of the query that opened and is using this table. Has different
351
 
   meanings depending on the table type.
352
 
 
353
 
   Temporary tables:
354
 
 
355
 
   table->query_id is set to session->query_id for the duration of a statement
356
 
   and is reset to 0 once it is closed by the same statement. A non-zero
357
 
   table->query_id means that a statement is using the table even if it's
358
 
   not the current statement (table is in use by some outer statement).
359
 
 
360
 
   Non-temporary tables:
361
 
 
362
 
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
363
 
   for the duration of a statement and is reset to 0 once it is closed by
364
 
   the same statement. A non-zero query_id is used to control which tables
365
 
   in the list of pre-opened and locked tables are actually being used.
366
 
  */
367
 
  query_id_t    query_id;
368
 
 
369
 
  /* 
370
 
    For each key that has quick_keys.is_set(key) == true: estimate of #records
371
 
    and max #key parts that range access would use.
372
 
  */
373
 
  ha_rows       quick_rows[MAX_KEY];
374
 
 
375
 
  /* Bitmaps of key parts that =const for the entire join. */
376
 
  key_part_map  const_key_parts[MAX_KEY];
377
 
 
378
 
  uint          quick_key_parts[MAX_KEY];
379
 
  uint          quick_n_ranges[MAX_KEY];
380
 
 
381
 
  /* 
382
 
    Estimate of number of records that satisfy SARGable part of the table
383
 
    condition, or table->file->records if no SARGable condition could be
384
 
    constructed.
385
 
    This value is used by join optimizer as an estimate of number of records
386
 
    that will pass the table condition (condition that depends on fields of 
387
 
    this table and constants)
388
 
  */
389
 
  ha_rows       quick_condition_rows;
390
 
 
391
 
  /*
392
 
    If this table has TIMESTAMP field with auto-set property (pointed by
393
 
    timestamp_field member) then this variable indicates during which
394
 
    operations (insert only/on update/in both cases) we should set this
395
 
    field to current timestamp. If there are no such field in this table
396
 
    or we should not automatically set its value during execution of current
397
 
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
398
 
 
399
 
    Value of this variable is set for each statement in open_table() and
400
 
    if needed cleared later in statement processing code (see mysql_update()
401
 
    as example).
402
 
  */
403
 
  timestamp_auto_set_type timestamp_field_type;
404
 
  table_map     map;                    /* ID bit of table (1,2,4,8,16...) */
405
 
 
406
 
  uint32_t          lock_position;          /* Position in DRIZZLE_LOCK.table */
407
 
  uint32_t          lock_data_start;        /* Start pos. in DRIZZLE_LOCK.locks */
408
 
  uint32_t          lock_count;             /* Number of locks */
409
 
  uint          tablenr,used_fields;
410
 
  uint32_t          temp_pool_slot;             /* Used by intern temp tables */
411
 
  uint          status;                 /* What's in record[0] */
 
32
#include <drizzled/table/instance.h>
 
33
#include <drizzled/atomics.h>
 
34
 
 
35
#include <drizzled/visibility.h>
 
36
 
 
37
namespace drizzled {
 
38
 
 
39
/**
 
40
 * Class representing a set of records, either in a temporary, 
 
41
 * normal, or derived table.
 
42
 */
 
43
class DRIZZLED_API Table 
 
44
{
 
45
  Field **field; /**< Pointer to fields collection */
 
46
 
 
47
public:
 
48
  Field **getFields() const
 
49
  {
 
50
    return field;
 
51
  }
 
52
 
 
53
  Field *getField(uint32_t arg) const
 
54
  {
 
55
    return field[arg];
 
56
  }
 
57
 
 
58
  void setFields(Field **arg)
 
59
  {
 
60
    field= arg;
 
61
  }
 
62
 
 
63
  void setFieldAt(Field *arg, uint32_t arg_pos)
 
64
  {
 
65
    field[arg_pos]= arg;
 
66
  }
 
67
 
 
68
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
 
69
 
 
70
private:
 
71
  Table *next;
 
72
 
 
73
public:
 
74
  Table *getNext() const
 
75
  {
 
76
    return next;
 
77
  }
 
78
 
 
79
  Table **getNextPtr()
 
80
  {
 
81
    return &next;
 
82
  }
 
83
 
 
84
  void setNext(Table *arg)
 
85
  {
 
86
    next= arg;
 
87
  }
 
88
 
 
89
  void unlink()
 
90
  {
 
91
    getNext()->setPrev(getPrev());              /* remove from used chain */
 
92
    getPrev()->setNext(getNext());
 
93
  }
 
94
 
 
95
private:
 
96
  Table *prev;
 
97
public:
 
98
  Table *getPrev() const
 
99
  {
 
100
    return prev;
 
101
  }
 
102
 
 
103
  Table **getPrevPtr()
 
104
  {
 
105
    return &prev;
 
106
  }
 
107
 
 
108
  void setPrev(Table *arg)
 
109
  {
 
110
    prev= arg;
 
111
  }
 
112
 
 
113
  boost::dynamic_bitset<> *read_set; /* Active column sets */
 
114
  boost::dynamic_bitset<> *write_set; /* Active column sets */
 
115
 
 
116
  uint32_t tablenr;
 
117
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
 
118
 
 
119
  boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
 
120
  boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
 
121
  boost::dynamic_bitset<> tmp_set; /* Not sure about this... */
 
122
 
 
123
  Session *in_use; /**< Pointer to the current session using this object */
 
124
  Session *getSession()
 
125
  {
 
126
    return in_use;
 
127
  }
 
128
 
 
129
  unsigned char *getInsertRecord() const
 
130
  {
 
131
    return record[0];
 
132
  }
 
133
 
 
134
  unsigned char *getUpdateRecord()
 
135
  {
 
136
    return record[1];
 
137
  }
 
138
 
 
139
  unsigned char *record[2]; /**< Pointer to "records" */
 
140
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
 
141
  KeyInfo  *key_info; /**< data of keys in database */
 
142
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
 
143
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
 
144
  field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
 
145
 
 
146
  TableList *pos_in_table_list; /* Element referring to this table */
 
147
  Order *group;
 
148
  
 
149
  const char *getAlias() const
 
150
  {
 
151
    return _alias.c_str();
 
152
  }
 
153
 
 
154
  void clearAlias()
 
155
  {
 
156
    _alias.clear();
 
157
  }
 
158
 
 
159
  void setAlias(const char *arg)
 
160
  {
 
161
    _alias= arg;
 
162
  }
 
163
 
 
164
private:
 
165
  std::string _alias; /**< alias or table name if no alias */
 
166
public:
 
167
 
 
168
  unsigned char *null_flags;
 
169
 
 
170
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
 
171
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
 
172
  uint32_t lock_count; /**< Number of locks */
 
173
  uint32_t used_fields;
 
174
  uint32_t status; /* What's in getInsertRecord() */
412
175
  /* number of select if it is derived table */
413
 
  uint32_t          derived_select_number;
414
 
  int           current_lock;           /* Type of lock on table */
415
 
  bool copy_blobs;                      /* copy_blobs when storing */
 
176
  uint32_t derived_select_number;
 
177
  int current_lock; /**< Type of lock on table */
 
178
  bool copy_blobs; /**< Should blobs by copied when storing? */
416
179
 
417
180
  /*
418
181
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
422
185
  bool maybe_null;
423
186
 
424
187
  /*
425
 
    If true, the current table row is considered to have all columns set to 
 
188
    If true, the current table row is considered to have all columns set to
426
189
    NULL, including columns declared as "not null" (see maybe_null).
427
190
  */
428
191
  bool null_row;
429
192
 
430
193
  bool force_index;
431
 
  bool distinct,const_table,no_rows;
432
 
  bool key_read, no_keyread;
 
194
  bool distinct;
 
195
  bool const_table;
 
196
  bool no_rows;
 
197
  bool key_read;
 
198
  bool no_keyread;
433
199
  /*
434
200
    Placeholder for an open table which prevents other connections
435
201
    from taking name-locks on this table. Typically used with
436
 
    TABLE_SHARE::version member to take an exclusive name-lock on
 
202
    TableShare::version member to take an exclusive name-lock on
437
203
    this table name -- a name lock that not only prevents other
438
204
    threads from opening the table, but also blocks other name
439
205
    locks. This is achieved by:
443
209
    - setting version to 0 - this will force other threads to close
444
210
      the instance of this table and wait (this is the same approach
445
211
      as used for usual name locks).
446
 
    An exclusively name-locked table currently can have no handler
 
212
    An exclusively name-locked table currently can have no Cursor
447
213
    object associated with it (db_stat is always 0), but please do
448
214
    not rely on that.
449
215
  */
450
216
  bool open_placeholder;
451
 
  bool locked_by_logger;
452
 
  bool no_replicate;
453
217
  bool locked_by_name;
454
218
  bool no_cache;
455
 
  /* To signal that the table is associated with a HANDLER statement */
456
 
  bool open_by_handler;
457
219
  /*
458
220
    To indicate that a non-null value of the auto_increment field
459
221
    was provided by the user or retrieved from the current record.
460
222
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
461
223
  */
462
224
  bool auto_increment_field_not_null;
463
 
  bool insert_or_update;             /* Can be used by the handler */
464
 
  bool alias_name_used;         /* true if table_name is alias */
465
 
  bool get_fields_in_item_tree;      /* Signal to fix_field */
466
 
 
467
 
  REGINFO reginfo;                      /* field connections */
468
 
  MEM_ROOT mem_root;
469
 
  filesort_info_st sort;
470
 
 
471
 
  bool fill_item_list(List<Item> *item_list) const;
472
 
  void reset_item_list(List<Item> *item_list) const;
 
225
  bool alias_name_used; /* true if table_name is alias */
 
226
 
 
227
  /*
 
228
   The ID of the query that opened and is using this table. Has different
 
229
   meanings depending on the table type.
 
230
 
 
231
   Temporary tables:
 
232
 
 
233
   table->query_id is set to session->query_id for the duration of a statement
 
234
   and is reset to 0 once it is closed by the same statement. A non-zero
 
235
   table->query_id means that a statement is using the table even if it's
 
236
   not the current statement (table is in use by some outer statement).
 
237
 
 
238
   Non-temporary tables:
 
239
 
 
240
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
 
241
   for the duration of a statement and is reset to 0 once it is closed by
 
242
   the same statement. A non-zero query_id is used to control which tables
 
243
   in the list of pre-opened and locked tables are actually being used.
 
244
  */
 
245
  query_id_t query_id;
 
246
 
 
247
  /**
 
248
   * Estimate of number of records that satisfy SARGable part of the table
 
249
   * condition, or table->cursor->records if no SARGable condition could be
 
250
   * constructed.
 
251
   * This value is used by join optimizer as an estimate of number of records
 
252
   * that will pass the table condition (condition that depends on fields of
 
253
   * this table and constants)
 
254
   */
 
255
  ha_rows quick_condition_rows;
 
256
 
 
257
  /*
 
258
    If this table has TIMESTAMP field with auto-set property (pointed by
 
259
    timestamp_field member) then this variable indicates during which
 
260
    operations (insert only/on update/in both cases) we should set this
 
261
    field to current timestamp. If there are no such field in this table
 
262
    or we should not automatically set its value during execution of current
 
263
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
 
264
 
 
265
    Value of this variable is set for each statement in open_table() and
 
266
    if needed cleared later in statement processing code (see update_query()
 
267
    as example).
 
268
  */
 
269
  timestamp_auto_set_type timestamp_field_type;
 
270
  table_map map; ///< ID bit of table (1,2,4,8,16...)
 
271
 
 
272
  RegInfo reginfo; /* field connections */
 
273
 
 
274
  /*
 
275
    Map of keys that can be used to retrieve all data from this table
 
276
    needed by the query without reading the row.
 
277
  */
 
278
  key_map covering_keys;
 
279
  key_map quick_keys;
 
280
  key_map merge_keys;
 
281
 
 
282
  /*
 
283
    A set of keys that can be used in the query that references this
 
284
    table.
 
285
 
 
286
    All indexes disabled on the table's TableShare (see Table::s) will be
 
287
    subtracted from this set upon instantiation. Thus for any Table t it holds
 
288
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
 
289
    must not introduce any new keys here (see setup_tables).
 
290
 
 
291
    The set is implemented as a bitmap.
 
292
  */
 
293
  key_map keys_in_use_for_query;
 
294
 
 
295
  /* Map of keys that can be used to calculate GROUP BY without sorting */
 
296
  key_map keys_in_use_for_group_by;
 
297
 
 
298
  /* Map of keys that can be used to calculate ORDER BY without sorting */
 
299
  key_map keys_in_use_for_order_by;
 
300
 
 
301
  /*
 
302
    For each key that has quick_keys.test(key) == true: estimate of #records
 
303
    and max #key parts that range access would use.
 
304
  */
 
305
  ha_rows quick_rows[MAX_KEY];
 
306
 
 
307
  /* Bitmaps of key parts that =const for the entire join. */
 
308
  key_part_map  const_key_parts[MAX_KEY];
 
309
 
 
310
  uint32_t quick_key_parts[MAX_KEY];
 
311
  uint32_t quick_n_ranges[MAX_KEY];
 
312
 
 
313
private:
 
314
  memory::Root mem_root;
 
315
 
 
316
  void init_mem_root()
 
317
  {
 
318
    if (not mem_root.alloc_root_inited())
 
319
      mem_root.init(TABLE_ALLOC_BLOCK_SIZE);
 
320
  }
 
321
public:
 
322
  memory::Root& mem()
 
323
  {
 
324
    init_mem_root();
 
325
    return mem_root;
 
326
  }
 
327
 
 
328
  unsigned char* alloc(size_t arg)
 
329
  {
 
330
    init_mem_root();
 
331
    return mem_root.alloc(arg);
 
332
  }
 
333
 
 
334
  char* strdup(const char* str_arg, size_t len_arg)
 
335
  {
 
336
    init_mem_root();
 
337
    return mem_root.strdup(str_arg, len_arg);
 
338
  }
 
339
 
 
340
  filesort_info sort;
 
341
 
 
342
  Table();
 
343
  virtual ~Table();
 
344
 
 
345
  int report_error(int error);
 
346
  /**
 
347
   * Free information allocated by openfrm
 
348
   *
 
349
   * @param If true if we also want to free table_share
 
350
   * @note this should all be the destructor
 
351
   */
 
352
  int delete_table(bool free_share= false);
 
353
 
 
354
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
 
355
 
 
356
  /* SHARE methods */
 
357
  virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
 
358
  virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
 
359
  virtual bool hasShare() const= 0; /* Get rid of this long term */
 
360
  virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
 
361
 
 
362
  virtual void release(void)= 0;
 
363
 
 
364
  uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
 
365
  uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
 
366
  uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
 
367
  uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
 
368
  uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
 
369
 
 
370
public:
 
371
  virtual bool hasVariableWidth() const
 
372
  {
 
373
    return getShare()->hasVariableWidth(); // We should calculate this.
 
374
  }
 
375
 
 
376
  virtual void setVariableWidth(void);
 
377
 
 
378
  Field_blob *getBlobFieldAt(uint32_t arg) const
 
379
  {
 
380
    if (arg < getShare()->blob_fields)
 
381
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
 
382
 
 
383
    return NULL;
 
384
  }
 
385
  inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
 
386
  inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
 
387
  inline uint32_t getNullFields() const { return getShare()->null_fields; }
 
388
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
 
389
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
 
390
  inline const char *getTableName()  const { return getShare()->getTableName(); }
 
391
 
 
392
  inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
 
393
  inline bool isNameLock() const { return open_placeholder; }
 
394
 
 
395
  uint32_t index_flags(uint32_t idx) const;
 
396
 
 
397
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
 
398
  {
 
399
    return getShare()->getEngine();
 
400
  }
 
401
 
 
402
  Cursor &getCursor() const /* table_type for handler */
 
403
  {
 
404
    assert(cursor);
 
405
    return *cursor;
 
406
  }
 
407
 
 
408
  size_t max_row_length(const unsigned char *data);
 
409
  uint32_t find_shortest_key(const key_map *usable_keys);
 
410
  bool compare_record(Field **ptr);
 
411
  bool records_are_comparable();
 
412
  bool compare_records();
 
413
  /* TODO: the (re)storeRecord's may be able to be further condensed */
 
414
  void storeRecord();
 
415
  void storeRecordAsInsert();
 
416
  void storeRecordAsDefault();
 
417
  void restoreRecord();
 
418
  void restoreRecordAsDefault();
 
419
  void emptyRecord();
 
420
 
 
421
 
 
422
  /* See if this can be blown away */
 
423
  inline uint32_t getDBStat () const { return db_stat; }
 
424
 
 
425
  /**
 
426
   * Create Item_field for each column in the table.
 
427
   *
 
428
   * @param[out] a pointer to an empty list used to store items
 
429
   *
 
430
   * @details
 
431
   *
 
432
   * Create Item_field object for each column in the table and
 
433
   * initialize it with the corresponding Field. New items are
 
434
   * created in the current Session memory root.
 
435
   *
 
436
   * @retval
 
437
   *  false on success
 
438
   * @retval
 
439
   *  true when out of memory
 
440
   */
 
441
  void fill_item_list(List<Item>&) const;
473
442
  void clear_column_bitmaps(void);
474
443
  void prepare_for_position(void);
475
 
  void mark_columns_used_by_index_no_reset(uint32_t index, MY_BITMAP *map);
 
444
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
 
445
  void mark_columns_used_by_index_no_reset(uint32_t index);
476
446
  void mark_columns_used_by_index(uint32_t index);
477
447
  void restore_column_maps_after_mark_index();
478
448
  void mark_auto_increment_column(void);
479
449
  void mark_columns_needed_for_update(void);
480
450
  void mark_columns_needed_for_delete(void);
481
451
  void mark_columns_needed_for_insert(void);
482
 
  void mark_virtual_columns(void);
483
 
  inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
484
 
                                 MY_BITMAP *write_set_arg)
485
 
  {
486
 
    read_set= read_set_arg;
487
 
    write_set= write_set_arg;
488
 
    if (file)
489
 
      file->column_bitmaps_signal();
490
 
  }
491
 
  inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
492
 
                                           MY_BITMAP *write_set_arg)
493
 
  {
494
 
    read_set= read_set_arg;
495
 
    write_set= write_set_arg;
496
 
  }
497
 
 
498
 
  void restore_column_map(my_bitmap_map *old);
499
 
 
500
 
  my_bitmap_map *use_all_columns(MY_BITMAP *bitmap);
 
452
  void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
 
453
                          boost::dynamic_bitset<>& write_set_arg);
 
454
 
 
455
  void restore_column_map(const boost::dynamic_bitset<>& old);
 
456
 
 
457
  const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
501
458
  inline void use_all_columns()
502
459
  {
503
 
    column_bitmaps_set(&s->all_set, &s->all_set);
 
460
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
504
461
  }
505
462
 
506
463
  inline void default_column_bitmaps()
509
466
    write_set= &def_write_set;
510
467
  }
511
468
 
 
469
  /* Both of the below should go away once we can move this bit to the field objects */
 
470
  inline bool isReadSet(uint32_t index) const
 
471
  {
 
472
    return read_set->test(index);
 
473
  }
 
474
 
 
475
  inline void setReadSet(uint32_t index)
 
476
  {
 
477
    read_set->set(index);
 
478
  }
 
479
 
 
480
  inline void setReadSet()
 
481
  {
 
482
    read_set->set();
 
483
  }
 
484
 
 
485
  inline void clearReadSet(uint32_t index)
 
486
  {
 
487
    read_set->reset(index);
 
488
  }
 
489
 
 
490
  inline void clearReadSet()
 
491
  {
 
492
    read_set->reset();
 
493
  }
 
494
 
 
495
  inline bool isWriteSet(uint32_t index)
 
496
  {
 
497
    return write_set->test(index);
 
498
  }
 
499
 
 
500
  inline void setWriteSet(uint32_t index)
 
501
  {
 
502
    write_set->set(index);
 
503
  }
 
504
 
 
505
  inline void setWriteSet()
 
506
  {
 
507
    write_set->set();
 
508
  }
 
509
 
 
510
  inline void clearWriteSet(uint32_t index)
 
511
  {
 
512
    write_set->reset(index);
 
513
  }
 
514
 
 
515
  inline void clearWriteSet()
 
516
  {
 
517
    write_set->reset();
 
518
  }
 
519
 
512
520
  /* Is table open or should be treated as such by name-locking? */
513
 
  inline bool is_name_opened() { return db_stat || open_placeholder; }
 
521
  bool is_name_opened() const
 
522
  {
 
523
    return db_stat || open_placeholder;
 
524
  }
 
525
 
514
526
  /*
515
527
    Is this instance of the table should be reopen or represents a name-lock?
516
528
  */
517
 
  inline bool needs_reopen_or_name_lock()
518
 
  { return s->version != refresh_version; }
519
 
 
520
 
  int report_error(int error);
521
 
};
522
 
 
523
 
Table *create_virtual_tmp_table(Session *session,
524
 
                                List<Create_field> &field_list);
525
 
 
526
 
typedef struct st_foreign_key_info
527
 
{
528
 
  LEX_STRING *forein_id;
529
 
  LEX_STRING *referenced_db;
530
 
  LEX_STRING *referenced_table;
531
 
  LEX_STRING *update_method;
532
 
  LEX_STRING *delete_method;
533
 
  LEX_STRING *referenced_key_name;
534
 
  List<LEX_STRING> foreign_fields;
535
 
  List<LEX_STRING> referenced_fields;
536
 
} FOREIGN_KEY_INFO;
537
 
 
538
 
typedef struct st_field_info
539
 
{
540
 
  /** 
541
 
      This is used as column name. 
542
 
  */
543
 
  const char* field_name;
544
 
  /**
545
 
     For string-type columns, this is the maximum number of
546
 
     characters. Otherwise, it is the 'display-length' for the column.
547
 
  */
548
 
  uint32_t field_length;
549
 
  /**
550
 
     This denotes data type for the column. For the most part, there seems to
551
 
     be one entry in the enum for each SQL data type, although there seem to
552
 
     be a number of additional entries in the enum.
553
 
  */
554
 
  enum enum_field_types field_type;
555
 
  int value;
556
 
  /**
557
 
     This is used to set column attributes. By default, columns are @c NOT
558
 
     @c NULL and @c SIGNED, and you can deviate from the default
559
 
     by setting the appopriate flags. You can use either one of the flags
560
 
     @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
561
 
     combine them using the bitwise or operator @c |. Both flags are
562
 
     defined in table.h.
563
 
   */
564
 
  uint32_t field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
565
 
  const char* old_name;
566
 
  /**
567
 
     This should be one of @c SKIP_OPEN_TABLE,
568
 
     @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
569
 
  */
570
 
  uint32_t open_method;
571
 
} ST_FIELD_INFO;
572
 
 
573
 
 
574
 
class TableList;
575
 
typedef class Item COND;
576
 
 
577
 
struct ST_SCHEMA_TABLE
578
 
{
579
 
  const char* table_name;
580
 
  ST_FIELD_INFO *fields_info;
581
 
  /* Create information_schema table */
582
 
  Table *(*create_table)  (Session *session, TableList *table_list);
583
 
  /* Fill table with data */
584
 
  int (*fill_table) (Session *session, TableList *tables, COND *cond);
585
 
  /* Handle fileds for old SHOW */
586
 
  int (*old_format) (Session *session, struct ST_SCHEMA_TABLE *schema_table);
587
 
  int (*process_table) (Session *session, TableList *tables, Table *table,
588
 
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
589
 
  int idx_field1, idx_field2; 
590
 
  bool hidden;
591
 
  uint32_t i_s_requested_object;  /* the object we need to open(Table | VIEW) */
592
 
};
593
 
 
594
 
 
595
 
#define JOIN_TYPE_LEFT  1
596
 
#define JOIN_TYPE_RIGHT 2
597
 
 
598
 
struct st_lex;
599
 
class select_union;
600
 
class TMP_TABLE_PARAM;
601
 
 
602
 
struct Field_translator
603
 
{
604
 
  Item *item;
605
 
  const char *name;
606
 
};
607
 
 
608
 
 
609
 
typedef struct st_changed_table_list
610
 
{
611
 
  struct        st_changed_table_list *next;
612
 
  char          *key;
613
 
  uint32_t        key_length;
614
 
} CHANGED_TableList;
615
 
 
616
 
 
617
 
typedef struct st_open_table_list
618
 
{
619
 
  struct st_open_table_list *next;
620
 
  char  *db,*table;
621
 
  uint32_t in_use,locked;
622
 
} OPEN_TableList;
623
 
 
624
 
 
625
 
inline void mark_as_null_row(Table *table)
626
 
{
627
 
  table->null_row=1;
628
 
  table->status|=STATUS_NULL_ROW;
629
 
  memset(table->null_flags, 255, table->s->null_bytes);
630
 
}
 
529
  bool needs_reopen_or_name_lock() const;
 
530
 
 
531
  /**
 
532
    clean/setup table fields and map.
 
533
 
 
534
    @param table        Table structure pointer (which should be setup)
 
535
    @param table_list   TableList structure pointer (owner of Table)
 
536
    @param tablenr     table number
 
537
  */
 
538
  void setup_table_map(TableList *table_list, uint32_t tablenr);
 
539
  inline void mark_as_null_row()
 
540
  {
 
541
    null_row= 1;
 
542
    status|= STATUS_NULL_ROW;
 
543
    memset(null_flags, 255, getShare()->null_bytes);
 
544
  }
 
545
 
 
546
  void free_io_cache();
 
547
  void filesort_free_buffers(bool full= false);
 
548
  void intern_close_table();
 
549
 
 
550
  void print_error(int error, myf errflag) const;
 
551
 
 
552
  /**
 
553
    @return
 
554
    key if error because of duplicated keys
 
555
  */
 
556
  uint32_t get_dup_key(int error) const
 
557
  {
 
558
    cursor->errkey  = (uint32_t) -1;
 
559
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
 
560
        error == HA_ERR_FOUND_DUPP_UNIQUE ||
 
561
        error == HA_ERR_DROP_INDEX_FK)
 
562
      cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
 
563
 
 
564
    return(cursor->errkey);
 
565
  }
 
566
 
 
567
  /*
 
568
    This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
 
569
  */
 
570
  bool operator<(const Table &right) const
 
571
  {
 
572
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
 
573
  }
 
574
 
 
575
  static bool compare(const Table *a, const Table *b)
 
576
  {
 
577
    return *a < *b;
 
578
  }
 
579
 
 
580
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
 
581
  {
 
582
    if (table.getShare())
 
583
    {
 
584
      output << "Table:(";
 
585
      output << table.getShare()->getSchemaName();
 
586
      output << ", ";
 
587
      output <<  table.getShare()->getTableName();
 
588
      output << ", ";
 
589
      output <<  table.getShare()->getTableTypeAsString();
 
590
      output << ")";
 
591
    }
 
592
    else
 
593
    {
 
594
      output << "Table:(has no share)";
 
595
    }
 
596
 
 
597
    return output;  // for multiple << operators.
 
598
  }
 
599
 
 
600
public:
 
601
  virtual bool isPlaceHolder(void) const
 
602
  {
 
603
    return false;
 
604
  }
 
605
};
631
606
 
632
607
/**
633
 
  clean/setup table fields and map.
634
 
 
635
 
  @param table        Table structure pointer (which should be setup)
636
 
  @param table_list   TableList structure pointer (owner of Table)
637
 
  @param tablenr     table number
638
 
*/
639
 
void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr);
640
 
 
641
 
#endif /* DRIZZLED_TABLE_H */
 
608
 * @class
 
609
 *  ForeignKeyInfo
 
610
 *
 
611
 * @brief
 
612
 *  This class defines the information for foreign keys.
 
613
 */
 
614
class ForeignKeyInfo
 
615
{
 
616
public:
 
617
    /**
 
618
     * @brief
 
619
     *  This is the constructor with all properties set.
 
620
     *
 
621
     * @param[in] in_foreign_id The id of the foreign key
 
622
     * @param[in] in_referenced_db The referenced database name of the foreign key
 
623
     * @param[in] in_referenced_table The referenced table name of the foreign key
 
624
     * @param[in] in_update_method The update method of the foreign key.
 
625
     * @param[in] in_delete_method The delete method of the foreign key.
 
626
     * @param[in] in_referenced_key_name The name of referenced key
 
627
     * @param[in] in_foreign_fields The foreign fields
 
628
     * @param[in] in_referenced_fields The referenced fields
 
629
     */
 
630
    ForeignKeyInfo(lex_string_t *in_foreign_id,
 
631
                   lex_string_t *in_referenced_db,
 
632
                   lex_string_t *in_referenced_table,
 
633
                   lex_string_t *in_update_method,
 
634
                   lex_string_t *in_delete_method,
 
635
                   lex_string_t *in_referenced_key_name,
 
636
                   List<lex_string_t> in_foreign_fields,
 
637
                   List<lex_string_t> in_referenced_fields)
 
638
    :
 
639
      foreign_id(in_foreign_id),
 
640
      referenced_db(in_referenced_db),
 
641
      referenced_table(in_referenced_table),
 
642
      update_method(in_update_method),
 
643
      delete_method(in_delete_method),
 
644
      referenced_key_name(in_referenced_key_name),
 
645
      foreign_fields(in_foreign_fields),
 
646
      referenced_fields(in_referenced_fields)
 
647
    {}
 
648
 
 
649
    /**
 
650
     * @brief
 
651
     *  This is the default constructor. All properties are set to default values for their types.
 
652
     */
 
653
    ForeignKeyInfo()
 
654
    : foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
 
655
      update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
 
656
    {}
 
657
 
 
658
    /**
 
659
     * @brief
 
660
     *  Gets the foreign id.
 
661
     *
 
662
     * @ retval  the foreign id
 
663
     */
 
664
    const lex_string_t *getForeignId() const
 
665
    {
 
666
        return foreign_id;
 
667
    }
 
668
 
 
669
    /**
 
670
     * @brief
 
671
     *  Gets the name of the referenced database.
 
672
     *
 
673
     * @ retval  the name of the referenced database
 
674
     */
 
675
    const lex_string_t *getReferencedDb() const
 
676
    {
 
677
        return referenced_db;
 
678
    }
 
679
 
 
680
    /**
 
681
     * @brief
 
682
     *  Gets the name of the referenced table.
 
683
     *
 
684
     * @ retval  the name of the referenced table
 
685
     */
 
686
    const lex_string_t *getReferencedTable() const
 
687
    {
 
688
        return referenced_table;
 
689
    }
 
690
 
 
691
    /**
 
692
     * @brief
 
693
     *  Gets the update method.
 
694
     *
 
695
     * @ retval  the update method
 
696
     */
 
697
    const lex_string_t *getUpdateMethod() const
 
698
    {
 
699
        return update_method;
 
700
    }
 
701
 
 
702
    /**
 
703
     * @brief
 
704
     *  Gets the delete method.
 
705
     *
 
706
     * @ retval  the delete method
 
707
     */
 
708
    const lex_string_t *getDeleteMethod() const
 
709
    {
 
710
        return delete_method;
 
711
    }
 
712
 
 
713
    /**
 
714
     * @brief
 
715
     *  Gets the name of the referenced key.
 
716
     *
 
717
     * @ retval  the name of the referenced key
 
718
     */
 
719
    const lex_string_t *getReferencedKeyName() const
 
720
    {
 
721
        return referenced_key_name;
 
722
    }
 
723
 
 
724
    /**
 
725
     * @brief
 
726
     *  Gets the foreign fields.
 
727
     *
 
728
     * @ retval  the foreign fields
 
729
     */
 
730
    const List<lex_string_t> &getForeignFields() const
 
731
    {
 
732
        return foreign_fields;
 
733
    }
 
734
 
 
735
    /**
 
736
     * @brief
 
737
     *  Gets the referenced fields.
 
738
     *
 
739
     * @ retval  the referenced fields
 
740
     */
 
741
    const List<lex_string_t> &getReferencedFields() const
 
742
    {
 
743
        return referenced_fields;
 
744
    }
 
745
private:
 
746
    /**
 
747
     * The foreign id.
 
748
     */
 
749
    lex_string_t *foreign_id;
 
750
    /**
 
751
     * The name of the reference database.
 
752
     */
 
753
    lex_string_t *referenced_db;
 
754
    /**
 
755
     * The name of the reference table.
 
756
     */
 
757
    lex_string_t *referenced_table;
 
758
    /**
 
759
     * The update method.
 
760
     */
 
761
    lex_string_t *update_method;
 
762
    /**
 
763
     * The delete method.
 
764
     */
 
765
    lex_string_t *delete_method;
 
766
    /**
 
767
     * The name of the referenced key.
 
768
     */
 
769
    lex_string_t *referenced_key_name;
 
770
    /**
 
771
     * The foreign fields.
 
772
     */
 
773
    List<lex_string_t> foreign_fields;
 
774
    /**
 
775
     * The referenced fields.
 
776
     */
 
777
    List<lex_string_t> referenced_fields;
 
778
};
 
779
 
 
780
#define JOIN_TYPE_LEFT  1
 
781
#define JOIN_TYPE_RIGHT 2
 
782
 
 
783
void free_blobs(Table *table);
 
784
int set_zone(int nr,int min_zone,int max_zone);
 
785
uint32_t convert_period_to_month(uint32_t period);
 
786
uint32_t convert_month_to_period(uint32_t month);
 
787
 
 
788
int test_if_number(char *str,int *res,bool allow_wildcards);
 
789
void change_byte(unsigned char *,uint,char,char);
 
790
void change_double_for_sort(double nr,unsigned char *to);
 
791
int get_quick_record(optimizer::SqlSelect *select);
 
792
 
 
793
void find_date(char *pos,uint32_t *vek,uint32_t flag);
 
794
TYPELIB* convert_strings_to_array_type(char** typelibs, char** end);
 
795
TYPELIB* typelib(memory::Root&, List<String>&);
 
796
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
 
797
void append_unescaped(String *res, const char *pos, uint32_t length);
 
798
 
 
799
bool check_column_name(const char *name);
 
800
bool check_table_name(const char *name, uint32_t length);
 
801
 
 
802
} /* namespace drizzled */
 
803
 
 
804
#include <drizzled/table/singular.h>
 
805
#include <drizzled/table/concurrent.h>
 
806