~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Jay Pipes
  • Date: 2008-12-18 15:55:03 UTC
  • mto: This revision was merged to the branch mainline in revision 717.
  • Revision ID: jpipes@serialcoder-20081218155503-u45ygyunrdyyvquq
Fix for Bug#308457.  Gave UTF8 enclosure and escape character on LOAD DATA INFILE and changed the error message to be more descriptive

Show diffs side-by-side

added added

removed removed

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