~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/table.h

Removed DBUG symbols and fixed TRUE/FALSE

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 */
 
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
 
 
16
 
 
17
/* Structs that defines the TABLE */
 
18
 
 
19
class Item;                             /* Needed by ORDER */
34
20
class Item_subselect;
35
21
class st_select_lex_unit;
36
22
class st_select_lex;
37
23
class COND_EQUAL;
38
24
class Security_context;
39
 
class TableList;
40
25
 
41
26
/*************************************************************************/
42
27
 
 
28
/* Order clause list element */
 
29
 
 
30
typedef struct st_order {
 
31
  struct st_order *next;
 
32
  Item   **item;                        /* Point at item in select fields */
 
33
  Item   *item_ptr;                     /* Storage for initial item */
 
34
  Item   **item_copy;                   /* For SPs; the original item ptr */
 
35
  int    counter;                       /* position in SELECT list, correct
 
36
                                           only if counter_used is true*/
 
37
  bool   asc;                           /* true if ascending */
 
38
  bool   free_me;                       /* true if item isn't shared  */
 
39
  bool   in_field_list;                 /* true if in select field list */
 
40
  bool   counter_used;                  /* parameter was counter of columns */
 
41
  Field  *field;                        /* If tmp-table group */
 
42
  char   *buff;                         /* If tmp-table group */
 
43
  table_map used, depend_map;
 
44
} ORDER;
 
45
 
43
46
enum tmp_table_type
44
47
{
45
48
  NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
46
49
  INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE, TMP_TABLE_FRM_FILE_ONLY
47
50
};
48
51
 
49
 
bool mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
 
52
enum frm_type_enum
 
53
{
 
54
  FRMTYPE_ERROR= 0,
 
55
  FRMTYPE_TABLE
 
56
};
 
57
 
 
58
frm_type_enum mysql_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
50
59
 
51
60
 
52
61
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
53
62
 
 
63
typedef struct st_filesort_info
 
64
{
 
65
  IO_CACHE *io_cache;           /* If sorted through filesort */
 
66
  uchar     **sort_keys;        /* Buffer for sorting keys */
 
67
  uchar     *buffpek;           /* Buffer for buffpek structures */
 
68
  uint      buffpek_len;        /* Max number of buffpeks in the buffer */
 
69
  uchar     *addon_buf;         /* Pointer to a buffer if sorted with fields */
 
70
  size_t    addon_length;       /* Length of the buffer */
 
71
  struct st_sort_addon_field *addon_field;     /* Pointer to the fields info */
 
72
  void    (*unpack)(struct st_sort_addon_field *, uchar *); /* To unpack back */
 
73
  uchar     *record_pointers;    /* If sorted in memory */
 
74
  ha_rows   found_records;      /* How many records in sort */
 
75
} FILESORT_INFO;
 
76
 
 
77
 
54
78
/*
55
79
  Values in this enum are used to indicate how a tables TIMESTAMP field
56
80
  should be treated. It can be set to the current timestamp on insert or
71
95
 
72
96
class Field_timestamp;
73
97
class Field_blob;
 
98
class Table_triggers_list;
74
99
 
75
100
/**
76
101
  Category of table found in the table share.
89
114
    - FLUSH TABLES WITH READ LOCK
90
115
    - SET GLOBAL READ_ONLY = ON
91
116
    do not apply to this table.
92
 
    Note that LOCK Table t FOR READ/WRITE
 
117
    Note that LOCK TABLE t FOR READ/WRITE
93
118
    can be used on temporary tables.
94
119
    Temporary tables are not part of the table cache.
95
120
  */
98
123
  /**
99
124
    User table.
100
125
    These tables do honor:
101
 
    - LOCK Table t FOR READ/WRITE
 
126
    - LOCK TABLE t FOR READ/WRITE
102
127
    - FLUSH TABLES WITH READ LOCK
103
128
    - SET GLOBAL READ_ONLY = ON
104
129
    User tables are cached in the table cache.
106
131
  TABLE_CATEGORY_USER=2,
107
132
 
108
133
  /**
 
134
    System table, maintained by the server.
 
135
    These tables do honor:
 
136
    - LOCK TABLE t FOR READ/WRITE
 
137
    - FLUSH TABLES WITH READ LOCK
 
138
    - SET GLOBAL READ_ONLY = ON
 
139
    Typically, writes to system tables are performed by
 
140
    the server implementation, not explicitly be a user.
 
141
    System tables are cached in the table cache.
 
142
  */
 
143
  TABLE_CATEGORY_SYSTEM=3,
 
144
 
 
145
  /**
109
146
    Information schema tables.
110
147
    These tables are an interface provided by the system
111
148
    to inspect the system metadata.
112
149
    These tables do *not* honor:
113
 
    - LOCK Table t FOR READ/WRITE
 
150
    - LOCK TABLE t FOR READ/WRITE
114
151
    - FLUSH TABLES WITH READ LOCK
115
152
    - SET GLOBAL READ_ONLY = ON
116
153
    as there is no point in locking explicitely
125
162
    to I_S tables in the table cache, which should use
126
163
    this table type.
127
164
  */
128
 
  TABLE_CATEGORY_INFORMATION
 
165
  TABLE_CATEGORY_INFORMATION=4
129
166
};
130
167
typedef enum enum_table_category TABLE_CATEGORY;
131
168
 
155
192
  struct st_table_share *next,          /* Link to unused shares */
156
193
    **prev;
157
194
 
158
 
  /* The following is copied to each Table on OPEN */
 
195
  /* The following is copied to each TABLE on OPEN */
159
196
  Field **field;
160
197
  Field **found_next_number_field;
161
198
  Field *timestamp_field;               /* Used only during open */
162
199
  KEY  *key_info;                       /* data of keys in database */
163
200
  uint  *blob_field;                    /* Index to blobs in Field arrray*/
164
201
 
165
 
  unsigned char *default_values;                /* row with default values */
 
202
  uchar *default_values;                /* row with default values */
166
203
  LEX_STRING comment;                   /* Comment about table */
167
 
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
 
204
  CHARSET_INFO *table_charset;          /* Default charset of string fields */
168
205
 
169
206
  MY_BITMAP all_set;
170
207
  /*
180
217
  LEX_STRING table_cache_key;
181
218
  LEX_STRING db;                        /* Pointer to db */
182
219
  LEX_STRING table_name;                /* Table name (for open) */
183
 
  LEX_STRING path;      /* Path to .frm file (from datadir) */
 
220
  LEX_STRING path;                      /* Path to .frm file (from datadir) */
184
221
  LEX_STRING normalized_path;           /* unpack_filename(path) */
185
222
  LEX_STRING connect_string;
186
223
 
187
 
  /*
 
224
  /* 
188
225
     Set of keys in use, implemented as a Bitmap.
189
 
     Excludes keys disabled by ALTER Table ... DISABLE KEYS.
 
226
     Excludes keys disabled by ALTER TABLE ... DISABLE KEYS.
190
227
  */
191
228
  key_map keys_in_use;
192
229
  key_map keys_for_keyread;
193
230
  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) */
 
231
  ulong   avg_row_length;               /* create information */
 
232
  ulong   version, mysql_version;
 
233
  ulong   timestamp_offset;             /* Set to offset+1 of record */
 
234
  ulong   reclength;                    /* Recordlength */
201
235
 
202
236
  plugin_ref db_plugin;                 /* storage engine plugin */
203
237
  inline handlerton *db_type() const    /* table_type for handler */
204
 
  {
205
 
    // assert(db_plugin);
 
238
  { 
 
239
    // DBUG_ASSERT(db_plugin);
206
240
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
207
241
  }
208
242
  enum row_type row_type;               /* How rows are stored */
210
244
  enum ha_choice transactional;
211
245
  enum ha_choice page_checksum;
212
246
 
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 */
 
247
  uint ref_count;                       /* How many TABLE objects uses this */
 
248
  uint open_count;                      /* Number of tables in open list */
 
249
  uint blob_ptr_size;                   /* 4 or 8 */
 
250
  uint key_block_size;                  /* create key_block_size, if used */
 
251
  uint null_bytes, last_null_bit_pos;
 
252
  uint fields;                          /* Number of fields */
 
253
  uint rec_buff_length;                 /* Size of table->record[] buffer */
 
254
  uint keys, key_parts;
 
255
  uint max_key_length, max_unique_length, total_key_length;
 
256
  uint uniques;                         /* Number of UNIQUE index */
 
257
  uint null_fields;                     /* number of null fields */
 
258
  uint blob_fields;                     /* number of blob fields */
 
259
  uint timestamp_field_offset;          /* Field number for timestamp field */
 
260
  uint varchar_fields;                  /* number of varchar fields */
 
261
  uint db_create_options;               /* Create options from database */
 
262
  uint db_options_in_use;               /* Options in use */
 
263
  uint db_record_offset;                /* if HA_REC_IN_SEQ */
 
264
  uint raid_type, raid_chunks;
 
265
  uint rowid_field_offset;              /* Field_nr +1 to rowid field */
233
266
  /* 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 */
 
267
  uint primary_key;
 
268
  uint next_number_index;               /* autoincrement key number */
 
269
  uint next_number_key_offset;          /* autoinc keypart offset in a key */
 
270
  uint next_number_keypart;             /* autoinc keypart number in a key */
 
271
  uint error, open_errno, errarg;       /* error from open_table_def() */
 
272
  uint column_bitmap_size;
 
273
  uchar frm_version;
242
274
  bool null_field_first;
 
275
  bool system;                          /* Set if system table (one record) */
 
276
  bool crypted;                         /* If .frm file is crypted */
243
277
  bool db_low_byte_first;               /* Portable row format */
244
278
  bool crashed;
245
279
  bool name_lock, replace_with_name_lock;
246
280
  bool waiting_on_cond;                 /* Protection against free */
247
 
  uint32_t table_map_id;                   /* for row-based replication */
 
281
  ulong table_map_id;                   /* for row-based replication */
248
282
  uint64_t table_map_version;
249
283
 
250
284
  /*
271
305
      appropriate values by using table cache key as their source.
272
306
  */
273
307
 
274
 
  void set_table_cache_key(char *key_buff, uint32_t key_length)
 
308
  void set_table_cache_key(char *key_buff, uint key_length)
275
309
  {
276
310
    table_cache_key.str= key_buff;
277
311
    table_cache_key.length= key_length;
301
335
      it should has same life-time as share itself.
302
336
  */
303
337
 
304
 
  void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
 
338
  void set_table_cache_key(char *key_buff, const char *key, uint key_length)
305
339
  {
306
340
    memcpy(key_buff, key, key_length);
307
341
    set_table_cache_key(key_buff, key_length);
309
343
 
310
344
  inline bool honor_global_locks()
311
345
  {
312
 
    return (table_category == TABLE_CATEGORY_USER);
 
346
    return ((table_category == TABLE_CATEGORY_USER)
 
347
            || (table_category == TABLE_CATEGORY_SYSTEM));
313
348
  }
314
349
 
315
 
  inline uint32_t get_table_def_version()
 
350
  inline ulong get_table_def_version()
316
351
  {
317
352
    return table_map_id;
318
353
  }
320
355
} TABLE_SHARE;
321
356
 
322
357
 
323
 
extern uint32_t refresh_version;
 
358
extern ulong refresh_version;
324
359
 
325
360
/* Information for one open table */
326
361
enum index_hint_type
330
365
  INDEX_HINT_FORCE
331
366
};
332
367
 
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:
 
368
struct st_table {
 
369
  st_table() {}                               /* Remove gcc warning */
 
370
 
348
371
  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
372
  handler       *file;
392
 
  Table *next, *prev;
 
373
  struct st_table *next, *prev;
393
374
 
394
375
  THD   *in_use;                        /* Which thread uses this */
395
376
  Field **field;                        /* Pointer to fields */
396
377
 
397
 
  unsigned char *record[2];                     /* Pointer to records */
398
 
  unsigned char *write_row_record;              /* Used as optimisation in
 
378
  uchar *record[2];                     /* Pointer to records */
 
379
  uchar *write_row_record;              /* Used as optimisation in
399
380
                                           THD::write_row */
400
 
  unsigned char *insert_values;                  /* used by INSERT ... UPDATE */
 
381
  uchar *insert_values;                  /* used by INSERT ... UPDATE */
401
382
  /* 
402
383
    Map of keys that can be used to retrieve all data from this table 
403
384
    needed by the query without reading the row.
408
389
    A set of keys that can be used in the query that references this
409
390
    table.
410
391
 
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
 
392
    All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be 
 
393
    subtracted from this set upon instantiation. Thus for any TABLE t it holds
413
394
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we 
414
395
    must not introduce any new keys here (see setup_tables).
415
396
 
425
406
  Field *next_number_field;             /* Set if next_number is activated */
426
407
  Field *found_next_number_field;       /* Set on open */
427
408
  Field_timestamp *timestamp_field;
428
 
  Field **vfield;                       /* Pointer to virtual fields*/
429
409
 
430
 
  TableList *pos_in_table_list;/* Element referring to this table */
431
 
  order_st *group;
 
410
  /* Table's triggers, 0 if there are no of them */
 
411
  Table_triggers_list *triggers;
 
412
  TABLE_LIST *pos_in_table_list;/* Element referring to this table */
 
413
  ORDER         *group;
432
414
  const char    *alias;                   /* alias or table name */
433
 
  unsigned char         *null_flags;
 
415
  uchar         *null_flags;
434
416
  my_bitmap_map *bitmap_init_value;
435
417
  MY_BITMAP     def_read_set, def_write_set, tmp_set; /* containers */
436
418
  MY_BITMAP     *read_set, *write_set;          /* Active column sets */
455
437
  query_id_t    query_id;
456
438
 
457
439
  /* 
458
 
    For each key that has quick_keys.is_set(key) == true: estimate of #records
 
440
    For each key that has quick_keys.is_set(key) == TRUE: estimate of #records
459
441
    and max #key parts that range access would use.
460
442
  */
461
443
  ha_rows       quick_rows[MAX_KEY];
491
473
  timestamp_auto_set_type timestamp_field_type;
492
474
  table_map     map;                    /* ID bit of table (1,2,4,8,16...) */
493
475
 
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 */
 
476
  uint          lock_position;          /* Position in MYSQL_LOCK.table */
 
477
  uint          lock_data_start;        /* Start pos. in MYSQL_LOCK.locks */
 
478
  uint          lock_count;             /* Number of locks */
497
479
  uint          tablenr,used_fields;
498
 
  uint32_t          temp_pool_slot;             /* Used by intern temp tables */
 
480
  uint          temp_pool_slot;         /* Used by intern temp tables */
499
481
  uint          status;                 /* What's in record[0] */
 
482
  uint          db_stat;                /* mode of file as in handler.h */
500
483
  /* number of select if it is derived table */
501
 
  uint32_t          derived_select_number;
 
484
  uint          derived_select_number;
502
485
  int           current_lock;           /* Type of lock on table */
503
 
  bool copy_blobs;                      /* copy_blobs when storing */
 
486
  my_bool copy_blobs;                   /* copy_blobs when storing */
504
487
 
505
488
  /*
506
489
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
507
490
    If maybe_null !=0, this table is inner w.r.t. some outer join operation,
508
491
    and null_row may be true.
509
492
  */
510
 
  bool maybe_null;
511
 
 
 
493
  uint maybe_null;
512
494
  /*
513
495
    If true, the current table row is considered to have all columns set to 
514
496
    NULL, including columns declared as "not null" (see maybe_null).
515
497
  */
516
 
  bool null_row;
 
498
  my_bool null_row;
517
499
 
518
 
  bool force_index;
519
 
  bool distinct,const_table,no_rows;
520
 
  bool key_read, no_keyread;
 
500
  /*
 
501
    TODO: Each of the following flags take up 8 bits. They can just as easily
 
502
    be put into one single unsigned long and instead of taking up 18
 
503
    bytes, it would take up 4.
 
504
  */
 
505
  my_bool force_index;
 
506
  my_bool distinct,const_table,no_rows;
 
507
  my_bool key_read, no_keyread;
521
508
  /*
522
509
    Placeholder for an open table which prevents other connections
523
510
    from taking name-locks on this table. Typically used with
535
522
    object associated with it (db_stat is always 0), but please do
536
523
    not rely on that.
537
524
  */
538
 
  bool open_placeholder;
539
 
  bool locked_by_logger;
540
 
  bool no_replicate;
541
 
  bool locked_by_name;
542
 
  bool no_cache;
 
525
  my_bool open_placeholder;
 
526
  my_bool locked_by_logger;
 
527
  my_bool no_replicate;
 
528
  my_bool locked_by_name;
 
529
  my_bool fulltext_searched;
 
530
  my_bool no_cache;
543
531
  /* To signal that the table is associated with a HANDLER statement */
544
 
  bool open_by_handler;
 
532
  my_bool open_by_handler;
545
533
  /*
546
534
    To indicate that a non-null value of the auto_increment field
547
535
    was provided by the user or retrieved from the current record.
548
536
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
549
537
  */
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 */
 
538
  my_bool auto_increment_field_not_null;
 
539
  my_bool insert_or_update;             /* Can be used by the handler */
 
540
  my_bool alias_name_used;              /* true if table_name is alias */
 
541
  my_bool get_fields_in_item_tree;      /* Signal to fix_field */
554
542
 
555
543
  REGINFO reginfo;                      /* field connections */
556
544
  MEM_ROOT mem_root;
557
 
  filesort_info_st sort;
 
545
  FILESORT_INFO sort;
558
546
 
559
547
  bool fill_item_list(List<Item> *item_list) const;
560
548
  void reset_item_list(List<Item> *item_list) const;
561
549
  void clear_column_bitmaps(void);
562
550
  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);
 
551
  void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map);
 
552
  void mark_columns_used_by_index(uint index);
565
553
  void restore_column_maps_after_mark_index();
566
554
  void mark_auto_increment_column(void);
567
555
  void mark_columns_needed_for_update(void);
568
556
  void mark_columns_needed_for_delete(void);
569
557
  void mark_columns_needed_for_insert(void);
570
 
  void mark_virtual_columns(void);
571
558
  inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
572
559
                                 MY_BITMAP *write_set_arg)
573
560
  {
582
569
    read_set= read_set_arg;
583
570
    write_set= write_set_arg;
584
571
  }
585
 
 
586
 
  void restore_column_map(my_bitmap_map *old);
587
 
 
588
 
  my_bitmap_map *use_all_columns(MY_BITMAP *bitmap);
589
572
  inline void use_all_columns()
590
573
  {
591
574
    column_bitmaps_set(&s->all_set, &s->all_set);
592
575
  }
593
 
 
594
576
  inline void default_column_bitmaps()
595
577
  {
596
578
    read_set= &def_read_set;
597
579
    write_set= &def_write_set;
598
580
  }
599
 
 
600
581
  /* Is table open or should be treated as such by name-locking? */
601
582
  inline bool is_name_opened() { return db_stat || open_placeholder; }
602
583
  /*
604
585
  */
605
586
  inline bool needs_reopen_or_name_lock()
606
587
  { return s->version != refresh_version; }
 
588
};
607
589
 
608
 
  int report_error(int error);
 
590
enum enum_schema_table_state
 
591
 
592
  NOT_PROCESSED= 0,
 
593
  PROCESSED_BY_CREATE_SORT_INDEX,
 
594
  PROCESSED_BY_JOIN_EXEC
609
595
};
610
596
 
611
597
typedef struct st_foreign_key_info
667
653
     For string-type columns, this is the maximum number of
668
654
     characters. Otherwise, it is the 'display-length' for the column.
669
655
  */
670
 
  uint32_t field_length;
 
656
  uint field_length;
671
657
  /**
672
658
     This denotes data type for the column. For the most part, there seems to
673
659
     be one entry in the enum for each SQL data type, although there seem to
683
669
     combine them using the bitwise or operator @c |. Both flags are
684
670
     defined in table.h.
685
671
   */
686
 
  uint32_t field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
 
672
  uint field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
687
673
  const char* old_name;
688
674
  /**
689
675
     This should be one of @c SKIP_OPEN_TABLE,
690
676
     @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
691
677
  */
692
 
  uint32_t open_method;
 
678
  uint open_method;
693
679
} ST_FIELD_INFO;
694
680
 
695
681
 
696
 
class TableList;
 
682
struct TABLE_LIST;
697
683
typedef class Item COND;
698
684
 
699
 
struct ST_SCHEMA_TABLE
 
685
typedef struct st_schema_table
700
686
{
701
687
  const char* table_name;
702
688
  ST_FIELD_INFO *fields_info;
703
689
  /* Create information_schema table */
704
 
  Table *(*create_table)  (THD *thd, TableList *table_list);
 
690
  TABLE *(*create_table)  (THD *thd, TABLE_LIST *table_list);
705
691
  /* Fill table with data */
706
 
  int (*fill_table) (THD *thd, TableList *tables, COND *cond);
 
692
  int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond);
707
693
  /* 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,
 
694
  int (*old_format) (THD *thd, struct st_schema_table *schema_table);
 
695
  int (*process_table) (THD *thd, TABLE_LIST *tables, TABLE *table,
710
696
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
711
697
  int idx_field1, idx_field2; 
712
698
  bool hidden;
713
 
  uint32_t i_s_requested_object;  /* the object we need to open(Table | VIEW) */
714
 
};
 
699
  uint i_s_requested_object;  /* the object we need to open(TABLE | VIEW) */
 
700
} ST_SCHEMA_TABLE;
715
701
 
716
702
 
717
703
#define JOIN_TYPE_LEFT  1
721
707
class select_union;
722
708
class TMP_TABLE_PARAM;
723
709
 
 
710
Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
 
711
                        const char *name);
 
712
 
724
713
struct Field_translator
725
714
{
726
715
  Item *item;
728
717
};
729
718
 
730
719
 
 
720
/*
 
721
  Column reference of a NATURAL/USING join. Since column references in
 
722
  joins can be both from views and stored tables, may point to either a
 
723
  Field (for tables), or a Field_translator (for views).
 
724
*/
 
725
 
 
726
class Natural_join_column: public Sql_alloc
 
727
{
 
728
public:
 
729
  Field_translator *view_field;  /* Column reference of merge view. */
 
730
  Field            *table_field; /* Column reference of table or temp view. */
 
731
  TABLE_LIST *table_ref; /* Original base table/view reference. */
 
732
  /*
 
733
    True if a common join column of two NATURAL/USING join operands. Notice
 
734
    that when we have a hierarchy of nested NATURAL/USING joins, a column can
 
735
    be common at some level of nesting but it may not be common at higher
 
736
    levels of nesting. Thus this flag may change depending on at which level
 
737
    we are looking at some column.
 
738
  */
 
739
  bool is_common;
 
740
public:
 
741
  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
 
742
  Natural_join_column(Field *field_param, TABLE_LIST *tab);
 
743
  const char *name();
 
744
  Item *create_item(THD *thd);
 
745
  Field *field();
 
746
  const char *table_name();
 
747
  const char *db_name();
 
748
};
 
749
 
 
750
 
 
751
/*
 
752
  Table reference in the FROM clause.
 
753
 
 
754
  These table references can be of several types that correspond to
 
755
  different SQL elements. Below we list all types of TABLE_LISTs with
 
756
  the necessary conditions to determine when a TABLE_LIST instance
 
757
  belongs to a certain type.
 
758
 
 
759
  1) table (TABLE_LIST::view == NULL)
 
760
     - base table
 
761
       (TABLE_LIST::derived == NULL)
 
762
     - subquery - TABLE_LIST::table is a temp table
 
763
       (TABLE_LIST::derived != NULL)
 
764
     - information schema table
 
765
       (TABLE_LIST::schema_table != NULL)
 
766
       NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
 
767
  2) view (TABLE_LIST::view != NULL)
 
768
     - merge    (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
 
769
           also (TABLE_LIST::field_translation != NULL)
 
770
     - tmptable (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
 
771
           also (TABLE_LIST::field_translation == NULL)
 
772
  3) nested table reference (TABLE_LIST::nested_join != NULL)
 
773
     - table sequence - e.g. (t1, t2, t3)
 
774
       TODO: how to distinguish from a JOIN?
 
775
     - general JOIN
 
776
       TODO: how to distinguish from a table sequence?
 
777
     - NATURAL JOIN
 
778
       (TABLE_LIST::natural_join != NULL)
 
779
       - JOIN ... USING
 
780
         (TABLE_LIST::join_using_fields != NULL)
 
781
     - semi-join
 
782
       ;
 
783
*/
 
784
 
 
785
class Index_hint;
 
786
struct TABLE_LIST
 
787
{
 
788
  TABLE_LIST() {}                          /* Remove gcc warning */
 
789
 
 
790
  /**
 
791
    Prepare TABLE_LIST that consists of one table instance to use in
 
792
    simple_open_and_lock_tables
 
793
  */
 
794
  inline void init_one_table(const char *db_name_arg,
 
795
                             const char *table_name_arg,
 
796
                             enum thr_lock_type lock_type_arg)
 
797
  {
 
798
    bzero((char*) this, sizeof(*this));
 
799
    db= (char*) db_name_arg;
 
800
    table_name= alias= (char*) table_name_arg;
 
801
    lock_type= lock_type_arg;
 
802
  }
 
803
 
 
804
  /*
 
805
    List of tables local to a subquery (used by SQL_LIST). Considers
 
806
    views as leaves (unlike 'next_leaf' below). Created at parse time
 
807
    in st_select_lex::add_table_to_list() -> table_list.link_in_list().
 
808
  */
 
809
  TABLE_LIST *next_local;
 
810
  /* link in a global list of all queries tables */
 
811
  TABLE_LIST *next_global, **prev_global;
 
812
  char          *db, *alias, *table_name, *schema_table_name;
 
813
  char          *option;                /* Used by cache index  */
 
814
  Item          *on_expr;               /* Used with outer join */
 
815
  Item          *sj_on_expr;
 
816
  /*
 
817
    (Valid only for semi-join nests) Bitmap of tables that are within the
 
818
    semi-join (this is different from bitmap of all nest's children because
 
819
    tables that were pulled out of the semi-join nest remain listed as
 
820
    nest's children).
 
821
  */
 
822
  table_map     sj_inner_tables;
 
823
  /* Number of IN-compared expressions */
 
824
  uint          sj_in_exprs; 
 
825
  /*
 
826
    The structure of ON expression presented in the member above
 
827
    can be changed during certain optimizations. This member
 
828
    contains a snapshot of AND-OR structure of the ON expression
 
829
    made after permanent transformations of the parse tree, and is
 
830
    used to restore ON clause before every reexecution of a prepared
 
831
    statement or stored procedure.
 
832
  */
 
833
  Item          *prep_on_expr;
 
834
  COND_EQUAL    *cond_equal;            /* Used with outer join */
 
835
  /*
 
836
    During parsing - left operand of NATURAL/USING join where 'this' is
 
837
    the right operand. After parsing (this->natural_join == this) iff
 
838
    'this' represents a NATURAL or USING join operation. Thus after
 
839
    parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
 
840
  */
 
841
  TABLE_LIST *natural_join;
 
842
  /*
 
843
    True if 'this' represents a nested join that is a NATURAL JOIN.
 
844
    For one of the operands of 'this', the member 'natural_join' points
 
845
    to the other operand of 'this'.
 
846
  */
 
847
  bool is_natural_join;
 
848
  /* Field names in a USING clause for JOIN ... USING. */
 
849
  List<String> *join_using_fields;
 
850
  /*
 
851
    Explicitly store the result columns of either a NATURAL/USING join or
 
852
    an operand of such a join.
 
853
  */
 
854
  List<Natural_join_column> *join_columns;
 
855
  /* TRUE if join_columns contains all columns of this table reference. */
 
856
  bool is_join_columns_complete;
 
857
 
 
858
  /*
 
859
    List of nodes in a nested join tree, that should be considered as
 
860
    leaves with respect to name resolution. The leaves are: views,
 
861
    top-most nodes representing NATURAL/USING joins, subqueries, and
 
862
    base tables. All of these TABLE_LIST instances contain a
 
863
    materialized list of columns. The list is local to a subquery.
 
864
  */
 
865
  TABLE_LIST *next_name_resolution_table;
 
866
  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
 
867
  List<Index_hint> *index_hints;
 
868
  TABLE        *table;                          /* opened table */
 
869
  uint          table_id; /* table id (from binlog) for opened table */
 
870
  /*
 
871
    select_result for derived table to pass it from table creation to table
 
872
    filling procedure
 
873
  */
 
874
  select_union  *derived_result;
 
875
  /*
 
876
    Reference from aux_tables to local list entry of main select of
 
877
    multi-delete statement:
 
878
    delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
 
879
    here it will be reference of first occurrence of t1 to second (as you
 
880
    can see this lists can't be merged)
 
881
  */
 
882
  TABLE_LIST    *correspondent_table;
 
883
  st_select_lex_unit *derived;          /* SELECT_LEX_UNIT of derived table */
 
884
  ST_SCHEMA_TABLE *schema_table;        /* Information_schema table */
 
885
  st_select_lex *schema_select_lex;
 
886
  /*
 
887
    True when the view field translation table is used to convert
 
888
    schema table fields for backwards compatibility with SHOW command.
 
889
  */
 
890
  bool schema_table_reformed;
 
891
  TMP_TABLE_PARAM *schema_table_param;
 
892
  /* link to select_lex where this table was used */
 
893
  st_select_lex *select_lex;
 
894
  Field_translator *field_translation;  /* array of VIEW fields */
 
895
  /* pointer to element after last one in translation table above */
 
896
  Field_translator *field_translation_end;
 
897
  /*
 
898
    List (based on next_local) of underlying tables of this view. I.e. it
 
899
    does not include the tables of subqueries used in the view. Is set only
 
900
    for merged views.
 
901
  */
 
902
  TABLE_LIST    *merge_underlying_list;
 
903
  /*
 
904
    - 0 for base tables
 
905
    - in case of the view it is the list of all (not only underlying
 
906
    tables but also used in subquery ones) tables of the view.
 
907
  */
 
908
  List<TABLE_LIST> *view_tables;
 
909
  /* most upper view this table belongs to */
 
910
  TABLE_LIST    *belong_to_view;
 
911
  /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
 
912
  TABLE_LIST    *parent_l;
 
913
  /*
 
914
    List of all base tables local to a subquery including all view
 
915
    tables. Unlike 'next_local', this in this list views are *not*
 
916
    leaves. Created in setup_tables() -> make_leaves_list().
 
917
  */
 
918
  TABLE_LIST    *next_leaf;
 
919
  /* data need by some engines in query cache*/
 
920
  uint64_t     engine_data;
 
921
  /* call back function for asking handler about caching in query cache */
 
922
  qc_engine_callback callback_func;
 
923
  thr_lock_type lock_type;
 
924
  uint          outer_join;             /* Which join type */
 
925
  uint          shared;                 /* Used in multi-upd */
 
926
  size_t        db_length;
 
927
  size_t        table_name_length;
 
928
  bool          straight;               /* optimize with prev table */
 
929
  bool          updating;               /* for replicate-do/ignore table */
 
930
  bool          force_index;            /* prefer index over table scan */
 
931
  bool          ignore_leaves;          /* preload only non-leaf nodes */
 
932
  table_map     dep_tables;             /* tables the table depends on      */
 
933
  table_map     on_expr_dep_tables;     /* tables on expression depends on  */
 
934
  struct st_nested_join *nested_join;   /* if the element is a nested join  */
 
935
  TABLE_LIST *embedding;             /* nested join containing the table */
 
936
  List<TABLE_LIST> *join_list;/* join list the table belongs to   */
 
937
  bool          cacheable_table;        /* stop PS caching */
 
938
  /* FRMTYPE_ERROR if any type is acceptable */
 
939
  enum frm_type_enum required_type;
 
940
  handlerton    *db_type;               /* table_type for handler */
 
941
  char          timestamp_buffer[20];   /* buffer for timestamp (19+1) */
 
942
  /*
 
943
    This TABLE_LIST object corresponds to the table to be created
 
944
    so it is possible that it does not exist (used in CREATE TABLE
 
945
    ... SELECT implementation).
 
946
  */
 
947
  bool          create;
 
948
  /* For transactional locking. */
 
949
  int           lock_timeout;           /* NOWAIT or WAIT [X]               */
 
950
  bool          lock_transactional;     /* If transactional lock requested. */
 
951
  bool          internal_tmp_table;
 
952
  /** TRUE if an alias for this table was specified in the SQL. */
 
953
  bool          is_alias;
 
954
  /** TRUE if the table is referred to in the statement using a fully
 
955
      qualified name (<db_name>.<table_name>).
 
956
  */
 
957
  bool          is_fqtn;
 
958
 
 
959
  uint i_s_requested_object;
 
960
  bool has_db_lookup_value;
 
961
  bool has_table_lookup_value;
 
962
  uint table_open_method;
 
963
  enum enum_schema_table_state schema_table_state;
 
964
  void set_underlying_merge();
 
965
  bool setup_underlying(THD *thd);
 
966
  void cleanup_items();
 
967
  /*
 
968
    If you change placeholder(), please check the condition in
 
969
    check_transactional_lock() too.
 
970
  */
 
971
  bool placeholder()
 
972
  {
 
973
    return derived || schema_table || (create && !table->db_stat) || !table;
 
974
  }
 
975
  void print(THD *thd, String *str, enum_query_type query_type);
 
976
  bool set_insert_values(MEM_ROOT *mem_root);
 
977
  TABLE_LIST *find_underlying_table(TABLE *table);
 
978
  TABLE_LIST *first_leaf_for_name_resolution();
 
979
  TABLE_LIST *last_leaf_for_name_resolution();
 
980
  bool is_leaf_for_name_resolution();
 
981
  inline TABLE_LIST *top_table()
 
982
    { return belong_to_view ? belong_to_view : this; }
 
983
 
 
984
  /*
 
985
    Cleanup for re-execution in a prepared statement or a stored
 
986
    procedure.
 
987
  */
 
988
  void reinit_before_use(THD *thd);
 
989
  Item_subselect *containing_subselect();
 
990
 
 
991
  /* 
 
992
    Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
 
993
    st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
 
994
    st_table::force_index and st_table::covering_keys.
 
995
  */
 
996
  bool process_index_hints(TABLE *table);
 
997
 
 
998
private:
 
999
  bool prep_where(THD *thd, Item **conds, bool no_where_clause);
 
1000
  /*
 
1001
    Cleanup for re-execution in a prepared statement or a stored
 
1002
    procedure.
 
1003
  */
 
1004
};
 
1005
 
 
1006
class Item;
 
1007
 
 
1008
/*
 
1009
  Iterator over the fields of a generic table reference.
 
1010
*/
 
1011
 
 
1012
class Field_iterator: public Sql_alloc
 
1013
{
 
1014
public:
 
1015
  Field_iterator() {}                         /* Remove gcc warning */
 
1016
  virtual ~Field_iterator() {}
 
1017
  virtual void set(TABLE_LIST *)= 0;
 
1018
  virtual void next()= 0;
 
1019
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
 
1020
  virtual const char *name()= 0;
 
1021
  virtual Item *create_item(THD *)= 0;
 
1022
  virtual Field *field()= 0;
 
1023
};
 
1024
 
 
1025
 
 
1026
/* 
 
1027
  Iterator over the fields of a base table, view with temporary
 
1028
  table, or subquery.
 
1029
*/
 
1030
 
 
1031
class Field_iterator_table: public Field_iterator
 
1032
{
 
1033
  Field **ptr;
 
1034
public:
 
1035
  Field_iterator_table() :ptr(0) {}
 
1036
  void set(TABLE_LIST *table) { ptr= table->table->field; }
 
1037
  void set_table(TABLE *table) { ptr= table->field; }
 
1038
  void next() { ptr++; }
 
1039
  bool end_of_fields() { return *ptr == 0; }
 
1040
  const char *name();
 
1041
  Item *create_item(THD *thd);
 
1042
  Field *field() { return *ptr; }
 
1043
};
 
1044
 
 
1045
 
 
1046
/* Iterator over the fields of a merge view. */
 
1047
 
 
1048
class Field_iterator_view: public Field_iterator
 
1049
{
 
1050
  Field_translator *ptr, *array_end;
 
1051
  TABLE_LIST *view;
 
1052
public:
 
1053
  Field_iterator_view() :ptr(0), array_end(0) {}
 
1054
  void set(TABLE_LIST *table);
 
1055
  void next() { ptr++; }
 
1056
  bool end_of_fields() { return ptr == array_end; }
 
1057
  const char *name();
 
1058
  Item *create_item(THD *thd);
 
1059
  Item **item_ptr() {return &ptr->item; }
 
1060
  Field *field() { return 0; }
 
1061
  inline Item *item() { return ptr->item; }
 
1062
  Field_translator *field_translator() { return ptr; }
 
1063
};
 
1064
 
 
1065
 
 
1066
/*
 
1067
  Field_iterator interface to the list of materialized fields of a
 
1068
  NATURAL/USING join.
 
1069
*/
 
1070
 
 
1071
class Field_iterator_natural_join: public Field_iterator
 
1072
{
 
1073
  List_iterator_fast<Natural_join_column> column_ref_it;
 
1074
  Natural_join_column *cur_column_ref;
 
1075
public:
 
1076
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
 
1077
  ~Field_iterator_natural_join() {}
 
1078
  void set(TABLE_LIST *table);
 
1079
  void next();
 
1080
  bool end_of_fields() { return !cur_column_ref; }
 
1081
  const char *name() { return cur_column_ref->name(); }
 
1082
  Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
 
1083
  Field *field() { return cur_column_ref->field(); }
 
1084
  Natural_join_column *column_ref() { return cur_column_ref; }
 
1085
};
 
1086
 
 
1087
 
 
1088
/*
 
1089
  Generic iterator over the fields of an arbitrary table reference.
 
1090
 
 
1091
  DESCRIPTION
 
1092
    This class unifies the various ways of iterating over the columns
 
1093
    of a table reference depending on the type of SQL entity it
 
1094
    represents. If such an entity represents a nested table reference,
 
1095
    this iterator encapsulates the iteration over the columns of the
 
1096
    members of the table reference.
 
1097
 
 
1098
  IMPLEMENTATION
 
1099
    The implementation assumes that all underlying NATURAL/USING table
 
1100
    references already contain their result columns and are linked into
 
1101
    the list TABLE_LIST::next_name_resolution_table.
 
1102
*/
 
1103
 
 
1104
class Field_iterator_table_ref: public Field_iterator
 
1105
{
 
1106
  TABLE_LIST *table_ref, *first_leaf, *last_leaf;
 
1107
  Field_iterator_table        table_field_it;
 
1108
  Field_iterator_view         view_field_it;
 
1109
  Field_iterator_natural_join natural_join_it;
 
1110
  Field_iterator *field_it;
 
1111
  void set_field_iterator();
 
1112
public:
 
1113
  Field_iterator_table_ref() :field_it(NULL) {}
 
1114
  void set(TABLE_LIST *table);
 
1115
  void next();
 
1116
  bool end_of_fields()
 
1117
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
 
1118
  const char *name() { return field_it->name(); }
 
1119
  const char *table_name();
 
1120
  const char *db_name();
 
1121
  Item *create_item(THD *thd) { return field_it->create_item(thd); }
 
1122
  Field *field() { return field_it->field(); }
 
1123
  Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref);
 
1124
  Natural_join_column *get_natural_column_ref();
 
1125
};
 
1126
 
 
1127
 
 
1128
typedef struct st_nested_join
 
1129
{
 
1130
  List<TABLE_LIST>  join_list;       /* list of elements in the nested join */
 
1131
  table_map         used_tables;     /* bitmap of tables in the nested join */
 
1132
  table_map         not_null_tables; /* tables that rejects nulls           */
 
1133
  struct st_join_table *first_nested;/* the first nested table in the plan  */
 
1134
  /* 
 
1135
    Used to count tables in the nested join in 2 isolated places:
 
1136
    1. In make_outerjoin_info(). 
 
1137
    2. check_interleaving_with_nj/restore_prev_nj_state (these are called
 
1138
       by the join optimizer. 
 
1139
    Before each use the counters are zeroed by reset_nj_counters.
 
1140
  */
 
1141
  uint              counter_;
 
1142
  nested_join_map   nj_map;          /* Bit used to identify this nested join*/
 
1143
  /*
 
1144
    (Valid only for semi-join nests) Bitmap of tables outside the semi-join
 
1145
    that are used within the semi-join's ON condition.
 
1146
  */
 
1147
  table_map         sj_depends_on;
 
1148
  /* Outer non-trivially correlated tables */
 
1149
  table_map         sj_corr_tables;
 
1150
  List<Item>        sj_outer_expr_list;
 
1151
} NESTED_JOIN;
 
1152
 
 
1153
 
731
1154
typedef struct st_changed_table_list
732
1155
{
733
1156
  struct        st_changed_table_list *next;
734
1157
  char          *key;
735
 
  uint32_t        key_length;
736
 
} CHANGED_TableList;
737
 
 
738
 
 
739
 
typedef struct st_open_table_list
740
 
{
 
1158
  uint32        key_length;
 
1159
} CHANGED_TABLE_LIST;
 
1160
 
 
1161
 
 
1162
typedef struct st_open_table_list{
741
1163
  struct st_open_table_list *next;
742
1164
  char  *db,*table;
743
 
  uint32_t in_use,locked;
744
 
} OPEN_TableList;
745
 
 
746
 
 
747
 
#endif /* DRIZZLED_TABLE_H */
 
1165
  uint32 in_use,locked;
 
1166
} OPEN_TABLE_LIST;
 
1167
 
 
1168
typedef struct st_table_field_w_type
 
1169
{
 
1170
  LEX_STRING name;
 
1171
  LEX_STRING type;
 
1172
  LEX_STRING cset;
 
1173
} TABLE_FIELD_W_TYPE;
 
1174
 
 
1175
 
 
1176
my_bool
 
1177
table_check_intact(TABLE *table, const uint table_f_count,
 
1178
                   const TABLE_FIELD_W_TYPE *table_def);
 
1179
 
 
1180
static inline my_bitmap_map *tmp_use_all_columns(TABLE *table,
 
1181
                                                 MY_BITMAP *bitmap)
 
1182
{
 
1183
  my_bitmap_map *old= bitmap->bitmap;
 
1184
  bitmap->bitmap= table->s->all_set.bitmap;
 
1185
  return old;
 
1186
}
 
1187
 
 
1188
 
 
1189
static inline void tmp_restore_column_map(MY_BITMAP *bitmap,
 
1190
                                          my_bitmap_map *old)
 
1191
{
 
1192
  bitmap->bitmap= old;
 
1193
}
 
1194
 
 
1195
/* The following is only needed for debugging */
 
1196
 
 
1197
static inline my_bitmap_map *dbug_tmp_use_all_columns(TABLE *table __attribute__((__unused__)),
 
1198
                                                      MY_BITMAP *bitmap __attribute__((__unused__)))
 
1199
{
 
1200
  return 0;
 
1201
}
 
1202
 
 
1203
static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap __attribute__((__unused__)),
 
1204
                                               my_bitmap_map *old __attribute__((__unused__)))
 
1205
{
 
1206
  return;
 
1207
}
 
1208
 
 
1209
size_t max_row_length(TABLE *table, const uchar *data);
 
1210