~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Monty Taylor
  • Date: 2008-07-28 02:47:38 UTC
  • mto: (212.5.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 219.
  • Revision ID: monty@inaugust.com-20080728024738-366ikqnoqv7d8g6l
Fixed the includes in places to make the myisam header file move work.

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