~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Jay Pipes
  • Date: 2008-09-11 16:03:22 UTC
  • mto: (383.5.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 386.
  • Revision ID: jay@mysql.com-20080911160322-vrl0k1djo6q6ytv1
Removed SQL_MODE variances from comment_table.test and ensured correct error thrown when a comment that is too long was input.  After moving to proto buffer definition for table, the 2048 length will go away.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
20
16
 
21
17
/* Structs that defines the Table */
22
18
 
23
19
#ifndef DRIZZLED_TABLE_H
24
20
#define DRIZZLED_TABLE_H
25
21
 
26
 
#include <string>
27
 
#include <boost/dynamic_bitset.hpp>
28
 
 
29
 
#include "drizzled/order.h"
30
 
#include "drizzled/filesort_info.h"
31
 
#include "drizzled/natural_join_column.h"
32
 
#include "drizzled/field_iterator.h"
33
 
#include "drizzled/cursor.h"
34
 
#include "drizzled/lex_string.h"
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
 
{
42
 
 
43
 
class Item;
 
22
#include <storage/myisam/myisam.h>
 
23
#include <drizzled/order.h>
 
24
#include <drizzled/filesort_info.h>
 
25
#include <drizzled/natural_join_column.h>
 
26
#include <drizzled/nested_join.h>
 
27
#include <drizzled/field_iterator.h>
 
28
 
 
29
class Item;                             /* Needed by order_st */
44
30
class Item_subselect;
45
 
class Select_Lex_Unit;
46
 
class Select_Lex;
 
31
class st_select_lex_unit;
 
32
class st_select_lex;
47
33
class COND_EQUAL;
48
 
class SecurityContext;
 
34
class Security_context;
49
35
class TableList;
 
36
 
 
37
/*************************************************************************/
 
38
 
 
39
enum tmp_table_type
 
40
{
 
41
  NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
 
42
  INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE, TMP_TABLE_FRM_FILE_ONLY
 
43
};
 
44
 
 
45
bool mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
 
46
 
 
47
 
 
48
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
 
49
 
 
50
/*
 
51
  Values in this enum are used to indicate how a tables TIMESTAMP field
 
52
  should be treated. It can be set to the current timestamp on insert or
 
53
  update or both.
 
54
  WARNING: The values are used for bit operations. If you change the
 
55
  enum, you must keep the bitwise relation of the values. For example:
 
56
  (int) TIMESTAMP_AUTO_SET_ON_BOTH must be equal to
 
57
  (int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE.
 
58
  We use an enum here so that the debugger can display the value names.
 
59
*/
 
60
enum timestamp_auto_set_type
 
61
{
 
62
  TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1,
 
63
  TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3
 
64
};
 
65
#define clear_timestamp_auto_bits(_target_, _bits_) \
 
66
  (_target_)= (enum timestamp_auto_set_type)((int)(_target_) & ~(int)(_bits_))
 
67
 
50
68
class Field_timestamp;
51
69
class Field_blob;
52
70
 
53
 
extern uint64_t refresh_version;
54
 
 
 
71
/**
 
72
  Category of table found in the table share.
 
73
*/
 
74
enum enum_table_category
 
75
{
 
76
  /**
 
77
    Unknown value.
 
78
  */
 
79
  TABLE_UNKNOWN_CATEGORY=0,
 
80
 
 
81
  /**
 
82
    Temporary table.
 
83
    The table is visible only in the session.
 
84
    Therefore,
 
85
    - FLUSH TABLES WITH READ LOCK
 
86
    - SET GLOBAL READ_ONLY = ON
 
87
    do not apply to this table.
 
88
    Note that LOCK Table t FOR READ/WRITE
 
89
    can be used on temporary tables.
 
90
    Temporary tables are not part of the table cache.
 
91
  */
 
92
  TABLE_CATEGORY_TEMPORARY=1,
 
93
 
 
94
  /**
 
95
    User table.
 
96
    These tables do honor:
 
97
    - LOCK Table t FOR READ/WRITE
 
98
    - FLUSH TABLES WITH READ LOCK
 
99
    - SET GLOBAL READ_ONLY = ON
 
100
    User tables are cached in the table cache.
 
101
  */
 
102
  TABLE_CATEGORY_USER=2,
 
103
 
 
104
  /**
 
105
    Information schema tables.
 
106
    These tables are an interface provided by the system
 
107
    to inspect the system metadata.
 
108
    These tables do *not* honor:
 
109
    - LOCK Table t FOR READ/WRITE
 
110
    - FLUSH TABLES WITH READ LOCK
 
111
    - SET GLOBAL READ_ONLY = ON
 
112
    as there is no point in locking explicitely
 
113
    an INFORMATION_SCHEMA table.
 
114
    Nothing is directly written to information schema tables.
 
115
    Note that this value is not used currently,
 
116
    since information schema tables are not shared,
 
117
    but implemented as session specific temporary tables.
 
118
  */
 
119
  /*
 
120
    TODO: Fixing the performance issues of I_S will lead
 
121
    to I_S tables in the table cache, which should use
 
122
    this table type.
 
123
  */
 
124
  TABLE_CATEGORY_INFORMATION
 
125
};
55
126
typedef enum enum_table_category TABLE_CATEGORY;
56
 
typedef struct st_columndef MI_COLUMNDEF;
57
 
 
58
 
/**
59
 
 * Class representing a set of records, either in a temporary, 
60
 
 * normal, or derived table.
61
 
 */
62
 
class Table 
63
 
{
64
 
  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:
89
 
  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
 
  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 */
132
 
 
133
 
  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
 
  }
155
 
 
156
 
  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 */
159
 
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
160
 
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
161
 
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
162
 
 
163
 
  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
 
 
185
 
  unsigned char *null_flags;
186
 
 
187
 
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
188
 
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
189
 
  uint32_t lock_count; /**< Number of locks */
190
 
  uint32_t used_fields;
191
 
  uint32_t status; /* What's in getInsertRecord() */
 
127
 
 
128
TABLE_CATEGORY get_table_category(const LEX_STRING *db,
 
129
                                  const LEX_STRING *name);
 
130
 
 
131
/*
 
132
  This structure is shared between different table objects. There is one
 
133
  instance of table share per one table in the database.
 
134
*/
 
135
 
 
136
typedef struct st_table_share
 
137
{
 
138
  st_table_share() {}                    /* Remove gcc warning */
 
139
 
 
140
  /** Category of this table. */
 
141
  TABLE_CATEGORY table_category;
 
142
 
 
143
  /* hash of field names (contains pointers to elements of field array) */
 
144
  HASH  name_hash;                      /* hash of field names */
 
145
  MEM_ROOT mem_root;
 
146
  TYPELIB keynames;                     /* Pointers to keynames */
 
147
  TYPELIB fieldnames;                   /* Pointer to fieldnames */
 
148
  TYPELIB *intervals;                   /* pointer to interval info */
 
149
  pthread_mutex_t mutex;                /* For locking the share  */
 
150
  pthread_cond_t cond;                  /* To signal that share is ready */
 
151
  struct st_table_share *next,          /* Link to unused shares */
 
152
    **prev;
 
153
 
 
154
  /* The following is copied to each Table on OPEN */
 
155
  Field **field;
 
156
  Field **found_next_number_field;
 
157
  Field *timestamp_field;               /* Used only during open */
 
158
  KEY  *key_info;                       /* data of keys in database */
 
159
  uint  *blob_field;                    /* Index to blobs in Field arrray*/
 
160
 
 
161
  uchar *default_values;                /* row with default values */
 
162
  LEX_STRING comment;                   /* Comment about table */
 
163
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
 
164
 
 
165
  MY_BITMAP all_set;
 
166
  /*
 
167
    Key which is used for looking-up table in table cache and in the list
 
168
    of thread's temporary tables. Has the form of:
 
169
      "database_name\0table_name\0" + optional part for temporary tables.
 
170
 
 
171
    Note that all three 'table_cache_key', 'db' and 'table_name' members
 
172
    must be set (and be non-zero) for tables in table cache. They also
 
173
    should correspond to each other.
 
174
    To ensure this one can use set_table_cache() methods.
 
175
  */
 
176
  LEX_STRING table_cache_key;
 
177
  LEX_STRING db;                        /* Pointer to db */
 
178
  LEX_STRING table_name;                /* Table name (for open) */
 
179
  LEX_STRING path;      /* Path to .frm file (from datadir) */
 
180
  LEX_STRING normalized_path;           /* unpack_filename(path) */
 
181
  LEX_STRING connect_string;
 
182
 
 
183
  /*
 
184
     Set of keys in use, implemented as a Bitmap.
 
185
     Excludes keys disabled by ALTER Table ... DISABLE KEYS.
 
186
  */
 
187
  key_map keys_in_use;
 
188
  key_map keys_for_keyread;
 
189
  ha_rows min_rows, max_rows;           /* create information */
 
190
  uint32_t   avg_row_length;            /* create information */
 
191
  uint32_t   block_size;                   /* create information */
 
192
  uint32_t   version, mysql_version;
 
193
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
 
194
  uint32_t   reclength;                 /* Recordlength */
 
195
 
 
196
  plugin_ref db_plugin;                 /* storage engine plugin */
 
197
  inline handlerton *db_type() const    /* table_type for handler */
 
198
  {
 
199
    // assert(db_plugin);
 
200
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
 
201
  }
 
202
  enum row_type row_type;               /* How rows are stored */
 
203
  enum tmp_table_type tmp_table;
 
204
  enum ha_choice transactional;
 
205
  enum ha_choice page_checksum;
 
206
 
 
207
  uint ref_count;                       /* How many Table objects uses this */
 
208
  uint open_count;                      /* Number of tables in open list */
 
209
  uint blob_ptr_size;                   /* 4 or 8 */
 
210
  uint key_block_size;                  /* create key_block_size, if used */
 
211
  uint null_bytes, last_null_bit_pos;
 
212
  uint fields;                          /* Number of fields */
 
213
  uint rec_buff_length;                 /* Size of table->record[] buffer */
 
214
  uint keys, key_parts;
 
215
  uint max_key_length, max_unique_length, total_key_length;
 
216
  uint uniques;                         /* Number of UNIQUE index */
 
217
  uint null_fields;                     /* number of null fields */
 
218
  uint blob_fields;                     /* number of blob fields */
 
219
  uint timestamp_field_offset;          /* Field number for timestamp field */
 
220
  uint varchar_fields;                  /* number of varchar fields */
 
221
  uint db_create_options;               /* Create options from database */
 
222
  uint db_options_in_use;               /* Options in use */
 
223
  uint db_record_offset;                /* if HA_REC_IN_SEQ */
 
224
  uint rowid_field_offset;              /* Field_nr +1 to rowid field */
 
225
  /* Index of auto-updated TIMESTAMP field in field array */
 
226
  uint primary_key;
 
227
  uint next_number_index;               /* autoincrement key number */
 
228
  uint next_number_key_offset;          /* autoinc keypart offset in a key */
 
229
  uint next_number_keypart;             /* autoinc keypart number in a key */
 
230
  uint error, open_errno, errarg;       /* error from open_table_def() */
 
231
  uint column_bitmap_size;
 
232
  uchar frm_version;
 
233
  bool null_field_first;
 
234
  bool db_low_byte_first;               /* Portable row format */
 
235
  bool crashed;
 
236
  bool name_lock, replace_with_name_lock;
 
237
  bool waiting_on_cond;                 /* Protection against free */
 
238
  uint32_t table_map_id;                   /* for row-based replication */
 
239
  uint64_t table_map_version;
 
240
 
 
241
  /*
 
242
    Cache for row-based replication table share checks that does not
 
243
    need to be repeated. Possible values are: -1 when cache value is
 
244
    not calculated yet, 0 when table *shall not* be replicated, 1 when
 
245
    table *may* be replicated.
 
246
  */
 
247
  int cached_row_logging_check;
 
248
 
 
249
  /*
 
250
    Set share's table cache key and update its db and table name appropriately.
 
251
 
 
252
    SYNOPSIS
 
253
      set_table_cache_key()
 
254
        key_buff    Buffer with already built table cache key to be
 
255
                    referenced from share.
 
256
        key_length  Key length.
 
257
 
 
258
    NOTES
 
259
      Since 'key_buff' buffer will be referenced from share it should has same
 
260
      life-time as share itself.
 
261
      This method automatically ensures that TABLE_SHARE::table_name/db have
 
262
      appropriate values by using table cache key as their source.
 
263
  */
 
264
 
 
265
  void set_table_cache_key(char *key_buff, uint key_length)
 
266
  {
 
267
    table_cache_key.str= key_buff;
 
268
    table_cache_key.length= key_length;
 
269
    /*
 
270
      Let us use the fact that the key is "db/0/table_name/0" + optional
 
271
      part for temporary tables.
 
272
    */
 
273
    db.str=            table_cache_key.str;
 
274
    db.length=         strlen(db.str);
 
275
    table_name.str=    db.str + db.length + 1;
 
276
    table_name.length= strlen(table_name.str);
 
277
  }
 
278
 
 
279
 
 
280
  /*
 
281
    Set share's table cache key and update its db and table name appropriately.
 
282
 
 
283
    SYNOPSIS
 
284
      set_table_cache_key()
 
285
        key_buff    Buffer to be used as storage for table cache key
 
286
                    (should be at least key_length bytes).
 
287
        key         Value for table cache key.
 
288
        key_length  Key length.
 
289
 
 
290
    NOTE
 
291
      Since 'key_buff' buffer will be used as storage for table cache key
 
292
      it should has same life-time as share itself.
 
293
  */
 
294
 
 
295
  void set_table_cache_key(char *key_buff, const char *key, uint key_length)
 
296
  {
 
297
    memcpy(key_buff, key, key_length);
 
298
    set_table_cache_key(key_buff, key_length);
 
299
  }
 
300
 
 
301
  inline bool honor_global_locks()
 
302
  {
 
303
    return (table_category == TABLE_CATEGORY_USER);
 
304
  }
 
305
 
 
306
  inline uint32_t get_table_def_version()
 
307
  {
 
308
    return table_map_id;
 
309
  }
 
310
 
 
311
} TABLE_SHARE;
 
312
 
 
313
 
 
314
extern uint32_t refresh_version;
 
315
 
 
316
/* Information for one open table */
 
317
enum index_hint_type
 
318
{
 
319
  INDEX_HINT_IGNORE,
 
320
  INDEX_HINT_USE,
 
321
  INDEX_HINT_FORCE
 
322
};
 
323
 
 
324
typedef struct st_table_field_w_type
 
325
{
 
326
  LEX_STRING name;
 
327
  LEX_STRING type;
 
328
  LEX_STRING cset;
 
329
} TABLE_FIELD_W_TYPE;
 
330
 
 
331
bool create_myisam_from_heap(THD *thd, Table *table,
 
332
                             MI_COLUMNDEF *start_recinfo,
 
333
                             MI_COLUMNDEF **recinfo, 
 
334
                             int error, bool ignore_last_dupp_key_error);
 
335
 
 
336
class Table {
 
337
 
 
338
public:
 
339
  TABLE_SHARE   *s;
 
340
  Table() {}                               /* Remove gcc warning */
 
341
 
 
342
  /* SHARE methods */
 
343
  inline TABLE_SHARE *getShare() { return s; } /* Get rid of this long term */
 
344
  inline void setShare(TABLE_SHARE *new_share) { s= new_share; } /* Get rid of this long term */
 
345
  inline uint sizeKeys() { return s->keys; }
 
346
  inline uint sizeFields() { return s->fields; }
 
347
  inline uint getRecordLength() { return s->reclength; }
 
348
  inline uint sizeBlobFields() { return s->blob_fields; }
 
349
  inline uint *getBlobField() { return s->blob_field; }
 
350
  inline uint getNullBytes() { return s->null_bytes; }
 
351
  inline uint getNullFields() { return s->null_fields; }
 
352
  inline unsigned char *getDefaultValues() { return s->default_values; }
 
353
 
 
354
  inline bool isNullFieldFirst() { return s->null_field_first; }
 
355
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; }         /* Portable row format */
 
356
  inline bool isCrashed() { return s->crashed; }
 
357
  inline bool isNameLock() { return s->name_lock; } 
 
358
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
359
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; }                 /* Protection against free */
 
360
 
 
361
  /* For TMP tables, should be pulled out as a class */
 
362
  void updateCreateInfo(HA_CREATE_INFO *create_info);
 
363
  void setup_tmp_table_column_bitmaps(uchar *bitmaps);
 
364
  bool create_myisam_tmp_table(KEY *keyinfo, 
 
365
                               MI_COLUMNDEF *start_recinfo,
 
366
                               MI_COLUMNDEF **recinfo, 
 
367
                               uint64_t options);
 
368
  void free_tmp_table(THD *thd);
 
369
  bool open_tmp_table();
 
370
  size_t max_row_length(const uchar *data);
 
371
  uint find_shortest_key(const key_map *usable_keys);
 
372
  bool compare_record(Field **ptr);
 
373
  bool compare_record();
 
374
 
 
375
  bool table_check_intact(const uint table_f_count, const TABLE_FIELD_W_TYPE *table_def);
 
376
 
 
377
  /* See if this can be blown away */
 
378
  inline uint getDBStat () { return db_stat; }
 
379
  inline uint setDBStat () { return db_stat; }
 
380
  uint          db_stat;                /* mode of file as in handler.h */
 
381
 
 
382
  handler       *file;
 
383
  Table *next, *prev;
 
384
 
 
385
  THD   *in_use;                        /* Which thread uses this */
 
386
  Field **field;                        /* Pointer to fields */
 
387
 
 
388
  uchar *record[2];                     /* Pointer to records */
 
389
  uchar *write_row_record;              /* Used as optimisation in
 
390
                                           THD::write_row */
 
391
  uchar *insert_values;                  /* used by INSERT ... UPDATE */
 
392
  /* 
 
393
    Map of keys that can be used to retrieve all data from this table 
 
394
    needed by the query without reading the row.
 
395
  */
 
396
  key_map covering_keys;
 
397
  key_map quick_keys, merge_keys;
 
398
  /*
 
399
    A set of keys that can be used in the query that references this
 
400
    table.
 
401
 
 
402
    All indexes disabled on the table's TABLE_SHARE (see Table::s) will be 
 
403
    subtracted from this set upon instantiation. Thus for any Table t it holds
 
404
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we 
 
405
    must not introduce any new keys here (see setup_tables).
 
406
 
 
407
    The set is implemented as a bitmap.
 
408
  */
 
409
  key_map keys_in_use_for_query;
 
410
  /* Map of keys that can be used to calculate GROUP BY without sorting */
 
411
  key_map keys_in_use_for_group_by;
 
412
  /* Map of keys that can be used to calculate ORDER BY without sorting */
 
413
  key_map keys_in_use_for_order_by;
 
414
  KEY  *key_info;                       /* data of keys in database */
 
415
 
 
416
  Field *next_number_field;             /* Set if next_number is activated */
 
417
  Field *found_next_number_field;       /* Set on open */
 
418
  Field_timestamp *timestamp_field;
 
419
 
 
420
  TableList *pos_in_table_list;/* Element referring to this table */
 
421
  order_st *group;
 
422
  const char    *alias;                   /* alias or table name */
 
423
  uchar         *null_flags;
 
424
  my_bitmap_map *bitmap_init_value;
 
425
  MY_BITMAP     def_read_set, def_write_set, tmp_set; /* containers */
 
426
  MY_BITMAP     *read_set, *write_set;          /* Active column sets */
 
427
  /*
 
428
   The ID of the query that opened and is using this table. Has different
 
429
   meanings depending on the table type.
 
430
 
 
431
   Temporary tables:
 
432
 
 
433
   table->query_id is set to thd->query_id for the duration of a statement
 
434
   and is reset to 0 once it is closed by the same statement. A non-zero
 
435
   table->query_id means that a statement is using the table even if it's
 
436
   not the current statement (table is in use by some outer statement).
 
437
 
 
438
   Non-temporary tables:
 
439
 
 
440
   Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
 
441
   for the duration of a statement and is reset to 0 once it is closed by
 
442
   the same statement. A non-zero query_id is used to control which tables
 
443
   in the list of pre-opened and locked tables are actually being used.
 
444
  */
 
445
  query_id_t    query_id;
 
446
 
 
447
  /* 
 
448
    For each key that has quick_keys.is_set(key) == true: estimate of #records
 
449
    and max #key parts that range access would use.
 
450
  */
 
451
  ha_rows       quick_rows[MAX_KEY];
 
452
 
 
453
  /* Bitmaps of key parts that =const for the entire join. */
 
454
  key_part_map  const_key_parts[MAX_KEY];
 
455
 
 
456
  uint          quick_key_parts[MAX_KEY];
 
457
  uint          quick_n_ranges[MAX_KEY];
 
458
 
 
459
  /* 
 
460
    Estimate of number of records that satisfy SARGable part of the table
 
461
    condition, or table->file->records if no SARGable condition could be
 
462
    constructed.
 
463
    This value is used by join optimizer as an estimate of number of records
 
464
    that will pass the table condition (condition that depends on fields of 
 
465
    this table and constants)
 
466
  */
 
467
  ha_rows       quick_condition_rows;
 
468
 
 
469
  /*
 
470
    If this table has TIMESTAMP field with auto-set property (pointed by
 
471
    timestamp_field member) then this variable indicates during which
 
472
    operations (insert only/on update/in both cases) we should set this
 
473
    field to current timestamp. If there are no such field in this table
 
474
    or we should not automatically set its value during execution of current
 
475
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
 
476
 
 
477
    Value of this variable is set for each statement in open_table() and
 
478
    if needed cleared later in statement processing code (see mysql_update()
 
479
    as example).
 
480
  */
 
481
  timestamp_auto_set_type timestamp_field_type;
 
482
  table_map     map;                    /* ID bit of table (1,2,4,8,16...) */
 
483
 
 
484
  uint          lock_position;          /* Position in DRIZZLE_LOCK.table */
 
485
  uint          lock_data_start;        /* Start pos. in DRIZZLE_LOCK.locks */
 
486
  uint          lock_count;             /* Number of locks */
 
487
  uint          tablenr,used_fields;
 
488
  uint          temp_pool_slot;         /* Used by intern temp tables */
 
489
  uint          status;                 /* What's in record[0] */
192
490
  /* number of select if it is derived table */
193
 
  uint32_t derived_select_number;
194
 
  int current_lock; /**< Type of lock on table */
195
 
  bool copy_blobs; /**< Should blobs by copied when storing? */
 
491
  uint          derived_select_number;
 
492
  int           current_lock;           /* Type of lock on table */
 
493
  bool copy_blobs;                      /* copy_blobs when storing */
196
494
 
197
495
  /*
198
496
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
202
500
  bool maybe_null;
203
501
 
204
502
  /*
205
 
    If true, the current table row is considered to have all columns set to
 
503
    If true, the current table row is considered to have all columns set to 
206
504
    NULL, including columns declared as "not null" (see maybe_null).
207
505
  */
208
506
  bool null_row;
209
507
 
210
508
  bool force_index;
211
 
  bool distinct;
212
 
  bool const_table;
213
 
  bool no_rows;
214
 
  bool key_read;
215
 
  bool no_keyread;
 
509
  bool distinct,const_table,no_rows;
 
510
  bool key_read, no_keyread;
216
511
  /*
217
512
    Placeholder for an open table which prevents other connections
218
513
    from taking name-locks on this table. Typically used with
219
 
    TableShare::version member to take an exclusive name-lock on
 
514
    TABLE_SHARE::version member to take an exclusive name-lock on
220
515
    this table name -- a name lock that not only prevents other
221
516
    threads from opening the table, but also blocks other name
222
517
    locks. This is achieved by:
226
521
    - setting version to 0 - this will force other threads to close
227
522
      the instance of this table and wait (this is the same approach
228
523
      as used for usual name locks).
229
 
    An exclusively name-locked table currently can have no Cursor
 
524
    An exclusively name-locked table currently can have no handler
230
525
    object associated with it (db_stat is always 0), but please do
231
526
    not rely on that.
232
527
  */
233
528
  bool open_placeholder;
 
529
  bool locked_by_logger;
 
530
  bool no_replicate;
234
531
  bool locked_by_name;
235
532
  bool no_cache;
 
533
  /* To signal that the table is associated with a HANDLER statement */
 
534
  bool open_by_handler;
236
535
  /*
237
536
    To indicate that a non-null value of the auto_increment field
238
537
    was provided by the user or retrieved from the current record.
239
538
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
240
539
  */
241
540
  bool auto_increment_field_not_null;
242
 
  bool alias_name_used; /* true if table_name is alias */
243
 
 
244
 
  /*
245
 
   The ID of the query that opened and is using this table. Has different
246
 
   meanings depending on the table type.
247
 
 
248
 
   Temporary tables:
249
 
 
250
 
   table->query_id is set to session->query_id for the duration of a statement
251
 
   and is reset to 0 once it is closed by the same statement. A non-zero
252
 
   table->query_id means that a statement is using the table even if it's
253
 
   not the current statement (table is in use by some outer statement).
254
 
 
255
 
   Non-temporary tables:
256
 
 
257
 
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
258
 
   for the duration of a statement and is reset to 0 once it is closed by
259
 
   the same statement. A non-zero query_id is used to control which tables
260
 
   in the list of pre-opened and locked tables are actually being used.
261
 
  */
262
 
  query_id_t query_id;
263
 
 
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
 
   */
272
 
  ha_rows quick_condition_rows;
273
 
 
274
 
  /*
275
 
    If this table has TIMESTAMP field with auto-set property (pointed by
276
 
    timestamp_field member) then this variable indicates during which
277
 
    operations (insert only/on update/in both cases) we should set this
278
 
    field to current timestamp. If there are no such field in this table
279
 
    or we should not automatically set its value during execution of current
280
 
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
281
 
 
282
 
    Value of this variable is set for each statement in open_table() and
283
 
    if needed cleared later in statement processing code (see mysql_update()
284
 
    as example).
285
 
  */
286
 
  timestamp_auto_set_type timestamp_field_type;
287
 
  table_map map; ///< ID bit of table (1,2,4,8,16...)
288
 
 
289
 
  RegInfo reginfo; /* field connections */
290
 
 
291
 
  /*
292
 
    Map of keys that can be used to retrieve all data from this table
293
 
    needed by the query without reading the row.
294
 
  */
295
 
  key_map covering_keys;
296
 
  key_map quick_keys;
297
 
  key_map merge_keys;
298
 
 
299
 
  /*
300
 
    A set of keys that can be used in the query that references this
301
 
    table.
302
 
 
303
 
    All indexes disabled on the table's TableShare (see Table::s) will be
304
 
    subtracted from this set upon instantiation. Thus for any Table t it holds
305
 
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
306
 
    must not introduce any new keys here (see setup_tables).
307
 
 
308
 
    The set is implemented as a bitmap.
309
 
  */
310
 
  key_map keys_in_use_for_query;
311
 
  /* Map of keys that can be used to calculate GROUP BY without sorting */
312
 
  key_map keys_in_use_for_group_by;
313
 
  /* Map of keys that can be used to calculate ORDER BY without sorting */
314
 
  key_map keys_in_use_for_order_by;
315
 
 
316
 
  /*
317
 
    For each key that has quick_keys.test(key) == true: estimate of #records
318
 
    and max #key parts that range access would use.
319
 
  */
320
 
  ha_rows quick_rows[MAX_KEY];
321
 
 
322
 
  /* Bitmaps of key parts that =const for the entire join. */
323
 
  key_part_map  const_key_parts[MAX_KEY];
324
 
 
325
 
  uint32_t quick_key_parts[MAX_KEY];
326
 
  uint32_t quick_n_ranges[MAX_KEY];
327
 
 
328
 
private:
329
 
  memory::Root mem_root;
330
 
 
331
 
  void init_mem_root()
332
 
  {
333
 
    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();
370
 
 
371
 
  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);
381
 
 
382
 
  /* 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
 
 
437
 
  size_t max_row_length(const unsigned char *data);
438
 
  uint32_t find_shortest_key(const key_map *usable_keys);
439
 
  bool compare_record(Field **ptr);
440
 
  bool records_are_comparable();
441
 
  bool compare_records();
442
 
  /* TODO: the (re)storeRecord's may be able to be further condensed */
443
 
  void storeRecord();
444
 
  void storeRecordAsInsert();
445
 
  void storeRecordAsDefault();
446
 
  void restoreRecord();
447
 
  void restoreRecordAsDefault();
448
 
  void emptyRecord();
449
 
 
450
 
 
451
 
  /* See if this can be blown away */
452
 
  inline uint32_t getDBStat () { return db_stat; }
453
 
  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
 
   */
 
541
  bool insert_or_update;             /* Can be used by the handler */
 
542
  bool alias_name_used;         /* true if table_name is alias */
 
543
  bool get_fields_in_item_tree;      /* Signal to fix_field */
 
544
 
 
545
  REGINFO reginfo;                      /* field connections */
 
546
  MEM_ROOT mem_root;
 
547
  filesort_info_st sort;
 
548
 
470
549
  bool fill_item_list(List<Item> *item_list) const;
 
550
  void reset_item_list(List<Item> *item_list) const;
471
551
  void clear_column_bitmaps(void);
472
552
  void prepare_for_position(void);
473
 
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
474
 
  void mark_columns_used_by_index_no_reset(uint32_t index);
475
 
  void mark_columns_used_by_index(uint32_t index);
 
553
  void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map);
 
554
  void mark_columns_used_by_index(uint index);
476
555
  void restore_column_maps_after_mark_index();
477
556
  void mark_auto_increment_column(void);
478
557
  void mark_columns_needed_for_update(void);
479
558
  void mark_columns_needed_for_delete(void);
480
559
  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);
 
560
  inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
 
561
                                 MY_BITMAP *write_set_arg)
 
562
  {
 
563
    read_set= read_set_arg;
 
564
    write_set= write_set_arg;
 
565
    if (file)
 
566
      file->column_bitmaps_signal();
 
567
  }
 
568
  inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
 
569
                                           MY_BITMAP *write_set_arg)
 
570
  {
 
571
    read_set= read_set_arg;
 
572
    write_set= write_set_arg;
 
573
  }
 
574
 
 
575
  void restore_column_map(my_bitmap_map *old);
 
576
 
 
577
  my_bitmap_map *use_all_columns(MY_BITMAP *bitmap);
487
578
  inline void use_all_columns()
488
579
  {
489
 
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
 
580
    column_bitmaps_set(&s->all_set, &s->all_set);
490
581
  }
491
582
 
492
583
  inline void default_column_bitmaps()
495
586
    write_set= &def_write_set;
496
587
  }
497
588
 
498
 
  /* Both of the below should go away once we can move this bit to the field objects */
499
 
  inline bool isReadSet(uint32_t index)
500
 
  {
501
 
    return read_set->test(index);
502
 
  }
503
 
 
504
 
  inline void setReadSet(uint32_t index)
505
 
  {
506
 
    read_set->set(index);
507
 
  }
508
 
 
509
 
  inline void setReadSet()
510
 
  {
511
 
    read_set->set();
512
 
  }
513
 
 
514
 
  inline void clearReadSet(uint32_t index)
515
 
  {
516
 
    read_set->reset(index);
517
 
  }
518
 
 
519
 
  inline void clearReadSet()
520
 
  {
521
 
    read_set->reset();
522
 
  }
523
 
 
524
 
  inline bool isWriteSet(uint32_t index)
525
 
  {
526
 
    return write_set->test(index);
527
 
  }
528
 
 
529
 
  inline void setWriteSet(uint32_t index)
530
 
  {
531
 
    write_set->set(index);
532
 
  }
533
 
 
534
 
  inline void setWriteSet()
535
 
  {
536
 
    write_set->set();
537
 
  }
538
 
 
539
 
  inline void clearWriteSet(uint32_t index)
540
 
  {
541
 
    write_set->reset(index);
542
 
  }
543
 
 
544
 
  inline void clearWriteSet()
545
 
  {
546
 
    write_set->reset();
547
 
  }
548
 
 
549
589
  /* Is table open or should be treated as such by name-locking? */
550
 
  inline bool is_name_opened()
551
 
  {
552
 
    return db_stat || open_placeholder;
553
 
  }
 
590
  inline bool is_name_opened() { return db_stat || open_placeholder; }
554
591
  /*
555
592
    Is this instance of the table should be reopen or represents a name-lock?
556
593
  */
557
594
  inline bool needs_reopen_or_name_lock()
558
 
  { 
559
 
    return getShare()->getVersion() != refresh_version;
560
 
  }
561
 
 
562
 
  /**
563
 
    clean/setup table fields and map.
564
 
 
565
 
    @param table        Table structure pointer (which should be setup)
566
 
    @param table_list   TableList structure pointer (owner of Table)
567
 
    @param tablenr     table number
568
 
  */
569
 
  void setup_table_map(TableList *table_list, uint32_t tablenr);
570
 
  inline void mark_as_null_row()
571
 
  {
572
 
    null_row= 1;
573
 
    status|= STATUS_NULL_ROW;
574
 
    memset(null_flags, 255, getShare()->null_bytes);
575
 
  }
576
 
 
577
 
  void free_io_cache();
578
 
  void filesort_free_buffers(bool full= false);
579
 
  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
 
};
640
 
 
641
 
/**
642
 
 * @class
643
 
 *  ForeignKeyInfo
644
 
 *
645
 
 * @brief
646
 
 *  This class defines the information for foreign keys.
647
 
 */
648
 
class ForeignKeyInfo
649
 
{
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
 
};
 
595
  { return s->version != refresh_version; }
 
596
 
 
597
  int report_error(int error);
 
598
};
 
599
 
 
600
typedef struct st_foreign_key_info
 
601
{
 
602
  LEX_STRING *forein_id;
 
603
  LEX_STRING *referenced_db;
 
604
  LEX_STRING *referenced_table;
 
605
  LEX_STRING *update_method;
 
606
  LEX_STRING *delete_method;
 
607
  LEX_STRING *referenced_key_name;
 
608
  List<LEX_STRING> foreign_fields;
 
609
  List<LEX_STRING> referenced_fields;
 
610
} FOREIGN_KEY_INFO;
 
611
 
 
612
/*
 
613
  Make sure that the order of schema_tables and enum_schema_tables are the same.
 
614
*/
 
615
 
 
616
enum enum_schema_tables
 
617
{
 
618
  SCH_CHARSETS= 0,
 
619
  SCH_COLLATIONS,
 
620
  SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
 
621
  SCH_COLUMNS,
 
622
  SCH_GLOBAL_STATUS,
 
623
  SCH_GLOBAL_VARIABLES,
 
624
  SCH_KEY_COLUMN_USAGE,
 
625
  SCH_OPEN_TABLES,
 
626
  SCH_PLUGINS,
 
627
  SCH_PROCESSLIST,
 
628
  SCH_REFERENTIAL_CONSTRAINTS,
 
629
  SCH_SCHEMATA,
 
630
  SCH_SESSION_STATUS,
 
631
  SCH_SESSION_VARIABLES,
 
632
  SCH_STATISTICS,
 
633
  SCH_STATUS,
 
634
  SCH_TABLES,
 
635
  SCH_TABLE_CONSTRAINTS,
 
636
  SCH_TABLE_NAMES,
 
637
  SCH_VARIABLES
 
638
};
 
639
 
 
640
 
 
641
#define MY_I_S_MAYBE_NULL 1
 
642
#define MY_I_S_UNSIGNED   2
 
643
 
 
644
 
 
645
#define SKIP_OPEN_TABLE 0                // do not open table
 
646
#define OPEN_FRM_ONLY   1                // open FRM file only
 
647
#define OPEN_FULL_TABLE 2                // open FRM,MYD, MYI files
 
648
 
 
649
typedef struct st_field_info
 
650
{
 
651
  /** 
 
652
      This is used as column name. 
 
653
  */
 
654
  const char* field_name;
 
655
  /**
 
656
     For string-type columns, this is the maximum number of
 
657
     characters. Otherwise, it is the 'display-length' for the column.
 
658
  */
 
659
  uint field_length;
 
660
  /**
 
661
     This denotes data type for the column. For the most part, there seems to
 
662
     be one entry in the enum for each SQL data type, although there seem to
 
663
     be a number of additional entries in the enum.
 
664
  */
 
665
  enum enum_field_types field_type;
 
666
  int value;
 
667
  /**
 
668
     This is used to set column attributes. By default, columns are @c NOT
 
669
     @c NULL and @c SIGNED, and you can deviate from the default
 
670
     by setting the appopriate flags. You can use either one of the flags
 
671
     @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
 
672
     combine them using the bitwise or operator @c |. Both flags are
 
673
     defined in table.h.
 
674
   */
 
675
  uint field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
 
676
  const char* old_name;
 
677
  /**
 
678
     This should be one of @c SKIP_OPEN_TABLE,
 
679
     @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
 
680
  */
 
681
  uint open_method;
 
682
} ST_FIELD_INFO;
 
683
 
813
684
 
814
685
class TableList;
815
 
 
816
 
#define JOIN_TYPE_LEFT  1
817
 
#define JOIN_TYPE_RIGHT 2
 
686
typedef class Item COND;
 
687
 
 
688
struct ST_SCHEMA_TABLE
 
689
{
 
690
  const char* table_name;
 
691
  ST_FIELD_INFO *fields_info;
 
692
  /* Create information_schema table */
 
693
  Table *(*create_table)  (THD *thd, TableList *table_list);
 
694
  /* Fill table with data */
 
695
  int (*fill_table) (THD *thd, TableList *tables, COND *cond);
 
696
  /* Handle fileds for old SHOW */
 
697
  int (*old_format) (THD *thd, struct ST_SCHEMA_TABLE *schema_table);
 
698
  int (*process_table) (THD *thd, TableList *tables, Table *table,
 
699
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
 
700
  int idx_field1, idx_field2; 
 
701
  bool hidden;
 
702
  uint i_s_requested_object;  /* the object we need to open(Table | VIEW) */
 
703
};
 
704
 
 
705
 
 
706
#define JOIN_TYPE_LEFT  1
 
707
#define JOIN_TYPE_RIGHT 2
818
708
 
819
709
struct st_lex;
820
710
class select_union;
821
 
class Tmp_Table_Param;
822
 
 
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"
 
711
class TMP_TABLE_PARAM;
 
712
 
 
713
struct Field_translator
 
714
{
 
715
  Item *item;
 
716
  const char *name;
 
717
};
 
718
 
 
719
 
 
720
typedef struct st_changed_table_list
 
721
{
 
722
  struct        st_changed_table_list *next;
 
723
  char          *key;
 
724
  uint32_t        key_length;
 
725
} CHANGED_TableList;
 
726
 
 
727
 
 
728
typedef struct st_open_table_list
 
729
{
 
730
  struct st_open_table_list *next;
 
731
  char  *db,*table;
 
732
  uint32_t in_use,locked;
 
733
} OPEN_TableList;
 
734
 
853
735
 
854
736
#endif /* DRIZZLED_TABLE_H */