~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Monty Taylor
  • Date: 2009-01-30 21:02:37 UTC
  • mto: (779.7.3 devel)
  • mto: This revision was merged to the branch mainline in revision 823.
  • Revision ID: mordred@inaugust.com-20090130210237-3n6ld8a9jc084jko
Commented out a test in subselect_sj - I think it might be a regression. Jay?

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
 
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/field_iterator.h>
 
31
#include <mysys/hash.h>
 
32
#include <drizzled/handler.h>
 
33
#include <drizzled/lex_string.h>
 
34
#include <drizzled/table_list.h>
 
35
#include <drizzled/table_share.h>
 
36
 
 
37
class Item;
20
38
class Item_subselect;
21
39
class st_select_lex_unit;
22
40
class st_select_lex;
23
41
class COND_EQUAL;
24
42
class Security_context;
 
43
class TableList;
25
44
 
26
45
/*************************************************************************/
27
46
 
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
 
 
46
 
enum tmp_table_type
47
 
{
48
 
  NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
49
 
  INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE, TMP_TABLE_FRM_FILE_ONLY
50
 
};
51
 
 
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);
59
 
 
60
 
 
61
 
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
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
 
 
78
 
/*
79
 
  Values in this enum are used to indicate how a tables TIMESTAMP field
80
 
  should be treated. It can be set to the current timestamp on insert or
81
 
  update or both.
82
 
  WARNING: The values are used for bit operations. If you change the
83
 
  enum, you must keep the bitwise relation of the values. For example:
84
 
  (int) TIMESTAMP_AUTO_SET_ON_BOTH must be equal to
85
 
  (int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE.
86
 
  We use an enum here so that the debugger can display the value names.
87
 
*/
88
 
enum timestamp_auto_set_type
89
 
{
90
 
  TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1,
91
 
  TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3
92
 
};
93
 
#define clear_timestamp_auto_bits(_target_, _bits_) \
94
 
  (_target_)= (enum timestamp_auto_set_type)((int)(_target_) & ~(int)(_bits_))
95
47
 
96
48
class Field_timestamp;
97
49
class Field_blob;
98
50
 
99
 
/**
100
 
  Category of table found in the table share.
101
 
*/
102
 
enum enum_table_category
103
 
{
104
 
  /**
105
 
    Unknown value.
106
 
  */
107
 
  TABLE_UNKNOWN_CATEGORY=0,
108
 
 
109
 
  /**
110
 
    Temporary table.
111
 
    The table is visible only in the session.
112
 
    Therefore,
113
 
    - FLUSH TABLES WITH READ LOCK
114
 
    - SET GLOBAL READ_ONLY = ON
115
 
    do not apply to this table.
116
 
    Note that LOCK TABLE t FOR READ/WRITE
117
 
    can be used on temporary tables.
118
 
    Temporary tables are not part of the table cache.
119
 
  */
120
 
  TABLE_CATEGORY_TEMPORARY=1,
121
 
 
122
 
  /**
123
 
    User table.
124
 
    These tables do honor:
125
 
    - LOCK TABLE t FOR READ/WRITE
126
 
    - FLUSH TABLES WITH READ LOCK
127
 
    - SET GLOBAL READ_ONLY = ON
128
 
    User tables are cached in the table cache.
129
 
  */
130
 
  TABLE_CATEGORY_USER=2,
131
 
 
132
 
  /**
133
 
    Information schema tables.
134
 
    These tables are an interface provided by the system
135
 
    to inspect the system metadata.
136
 
    These tables do *not* honor:
137
 
    - LOCK TABLE t FOR READ/WRITE
138
 
    - FLUSH TABLES WITH READ LOCK
139
 
    - SET GLOBAL READ_ONLY = ON
140
 
    as there is no point in locking explicitely
141
 
    an INFORMATION_SCHEMA table.
142
 
    Nothing is directly written to information schema tables.
143
 
    Note that this value is not used currently,
144
 
    since information schema tables are not shared,
145
 
    but implemented as session specific temporary tables.
146
 
  */
147
 
  /*
148
 
    TODO: Fixing the performance issues of I_S will lead
149
 
    to I_S tables in the table cache, which should use
150
 
    this table type.
151
 
  */
152
 
  TABLE_CATEGORY_INFORMATION
153
 
};
154
51
typedef enum enum_table_category TABLE_CATEGORY;
155
52
 
156
53
TABLE_CATEGORY get_table_category(const LEX_STRING *db,
157
54
                                  const LEX_STRING *name);
158
55
 
159
 
/*
160
 
  This structure is shared between different table objects. There is one
161
 
  instance of table share per one table in the database.
162
 
*/
163
 
 
164
 
typedef struct st_table_share
165
 
{
166
 
  st_table_share() {}                    /* Remove gcc warning */
167
 
 
168
 
  /** Category of this table. */
169
 
  TABLE_CATEGORY table_category;
170
 
 
171
 
  /* hash of field names (contains pointers to elements of field array) */
172
 
  HASH  name_hash;                      /* hash of field names */
173
 
  MEM_ROOT mem_root;
174
 
  TYPELIB keynames;                     /* Pointers to keynames */
175
 
  TYPELIB fieldnames;                   /* Pointer to fieldnames */
176
 
  TYPELIB *intervals;                   /* pointer to interval info */
177
 
  pthread_mutex_t mutex;                /* For locking the share  */
178
 
  pthread_cond_t cond;                  /* To signal that share is ready */
179
 
  struct st_table_share *next,          /* Link to unused shares */
180
 
    **prev;
181
 
 
182
 
  /* The following is copied to each TABLE on OPEN */
183
 
  Field **field;
184
 
  Field **found_next_number_field;
185
 
  Field *timestamp_field;               /* Used only during open */
186
 
  KEY  *key_info;                       /* data of keys in database */
187
 
  uint  *blob_field;                    /* Index to blobs in Field arrray*/
188
 
 
189
 
  uchar *default_values;                /* row with default values */
190
 
  LEX_STRING comment;                   /* Comment about table */
191
 
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
192
 
 
193
 
  MY_BITMAP all_set;
194
 
  /*
195
 
    Key which is used for looking-up table in table cache and in the list
196
 
    of thread's temporary tables. Has the form of:
197
 
      "database_name\0table_name\0" + optional part for temporary tables.
198
 
 
199
 
    Note that all three 'table_cache_key', 'db' and 'table_name' members
200
 
    must be set (and be non-zero) for tables in table cache. They also
201
 
    should correspond to each other.
202
 
    To ensure this one can use set_table_cache() methods.
203
 
  */
204
 
  LEX_STRING table_cache_key;
205
 
  LEX_STRING db;                        /* Pointer to db */
206
 
  LEX_STRING table_name;                /* Table name (for open) */
207
 
  LEX_STRING path;                      /* Path to .frm file (from datadir) */
208
 
  LEX_STRING normalized_path;           /* unpack_filename(path) */
209
 
  LEX_STRING connect_string;
210
 
 
211
 
  /* 
212
 
     Set of keys in use, implemented as a Bitmap.
213
 
     Excludes keys disabled by ALTER TABLE ... DISABLE KEYS.
214
 
  */
215
 
  key_map keys_in_use;
216
 
  key_map keys_for_keyread;
217
 
  ha_rows min_rows, max_rows;           /* create information */
218
 
  ulong   avg_row_length;               /* create information */
219
 
  ulong   block_size;                   /* create information */
220
 
  ulong   version, mysql_version;
221
 
  ulong   timestamp_offset;             /* Set to offset+1 of record */
222
 
  ulong   reclength;                    /* Recordlength */
223
 
 
224
 
  plugin_ref db_plugin;                 /* storage engine plugin */
225
 
  inline handlerton *db_type() const    /* table_type for handler */
226
 
  { 
227
 
    // assert(db_plugin);
228
 
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
229
 
  }
230
 
  enum row_type row_type;               /* How rows are stored */
231
 
  enum tmp_table_type tmp_table;
232
 
  enum ha_choice transactional;
233
 
  enum ha_choice page_checksum;
234
 
 
235
 
  uint ref_count;                       /* How many TABLE objects uses this */
236
 
  uint open_count;                      /* Number of tables in open list */
237
 
  uint blob_ptr_size;                   /* 4 or 8 */
238
 
  uint key_block_size;                  /* create key_block_size, if used */
239
 
  uint null_bytes, last_null_bit_pos;
240
 
  uint fields;                          /* Number of fields */
241
 
  uint rec_buff_length;                 /* Size of table->record[] buffer */
242
 
  uint keys, key_parts;
243
 
  uint max_key_length, max_unique_length, total_key_length;
244
 
  uint uniques;                         /* Number of UNIQUE index */
245
 
  uint null_fields;                     /* number of null fields */
246
 
  uint blob_fields;                     /* number of blob fields */
247
 
  uint timestamp_field_offset;          /* Field number for timestamp field */
248
 
  uint varchar_fields;                  /* number of varchar fields */
249
 
  uint db_create_options;               /* Create options from database */
250
 
  uint db_options_in_use;               /* Options in use */
251
 
  uint db_record_offset;                /* if HA_REC_IN_SEQ */
252
 
  uint rowid_field_offset;              /* Field_nr +1 to rowid field */
253
 
  /* Index of auto-updated TIMESTAMP field in field array */
254
 
  uint primary_key;
255
 
  uint next_number_index;               /* autoincrement key number */
256
 
  uint next_number_key_offset;          /* autoinc keypart offset in a key */
257
 
  uint next_number_keypart;             /* autoinc keypart number in a key */
258
 
  uint error, open_errno, errarg;       /* error from open_table_def() */
259
 
  uint column_bitmap_size;
260
 
  uchar frm_version;
261
 
  bool null_field_first;
262
 
  bool system;                          /* Set if system table (one record) */
263
 
  bool db_low_byte_first;               /* Portable row format */
264
 
  bool crashed;
265
 
  bool name_lock, replace_with_name_lock;
266
 
  bool waiting_on_cond;                 /* Protection against free */
267
 
  ulong table_map_id;                   /* for row-based replication */
268
 
  uint64_t table_map_version;
269
 
 
270
 
  /*
271
 
    Cache for row-based replication table share checks that does not
272
 
    need to be repeated. Possible values are: -1 when cache value is
273
 
    not calculated yet, 0 when table *shall not* be replicated, 1 when
274
 
    table *may* be replicated.
275
 
  */
276
 
  int cached_row_logging_check;
277
 
 
278
 
  /*
279
 
    Set share's table cache key and update its db and table name appropriately.
280
 
 
281
 
    SYNOPSIS
282
 
      set_table_cache_key()
283
 
        key_buff    Buffer with already built table cache key to be
284
 
                    referenced from share.
285
 
        key_length  Key length.
286
 
 
287
 
    NOTES
288
 
      Since 'key_buff' buffer will be referenced from share it should has same
289
 
      life-time as share itself.
290
 
      This method automatically ensures that TABLE_SHARE::table_name/db have
291
 
      appropriate values by using table cache key as their source.
292
 
  */
293
 
 
294
 
  void set_table_cache_key(char *key_buff, uint key_length)
295
 
  {
296
 
    table_cache_key.str= key_buff;
297
 
    table_cache_key.length= key_length;
298
 
    /*
299
 
      Let us use the fact that the key is "db/0/table_name/0" + optional
300
 
      part for temporary tables.
301
 
    */
302
 
    db.str=            table_cache_key.str;
303
 
    db.length=         strlen(db.str);
304
 
    table_name.str=    db.str + db.length + 1;
305
 
    table_name.length= strlen(table_name.str);
306
 
  }
307
 
 
308
 
 
309
 
  /*
310
 
    Set share's table cache key and update its db and table name appropriately.
311
 
 
312
 
    SYNOPSIS
313
 
      set_table_cache_key()
314
 
        key_buff    Buffer to be used as storage for table cache key
315
 
                    (should be at least key_length bytes).
316
 
        key         Value for table cache key.
317
 
        key_length  Key length.
318
 
 
319
 
    NOTE
320
 
      Since 'key_buff' buffer will be used as storage for table cache key
321
 
      it should has same life-time as share itself.
322
 
  */
323
 
 
324
 
  void set_table_cache_key(char *key_buff, const char *key, uint key_length)
325
 
  {
326
 
    memcpy(key_buff, key, key_length);
327
 
    set_table_cache_key(key_buff, key_length);
328
 
  }
329
 
 
330
 
  inline bool honor_global_locks()
331
 
  {
332
 
    return (table_category == TABLE_CATEGORY_USER);
333
 
  }
334
 
 
335
 
  inline ulong get_table_def_version()
336
 
  {
337
 
    return table_map_id;
338
 
  }
339
 
 
340
 
} TABLE_SHARE;
341
 
 
342
 
 
343
 
extern ulong refresh_version;
344
 
 
345
 
/* Information for one open table */
346
 
enum index_hint_type
347
 
{
348
 
  INDEX_HINT_IGNORE,
349
 
  INDEX_HINT_USE,
350
 
  INDEX_HINT_FORCE
351
 
};
352
 
 
353
 
struct st_table {
354
 
  st_table() {}                               /* Remove gcc warning */
355
 
 
 
56
 
 
57
extern uint32_t refresh_version;
 
58
 
 
59
typedef struct st_table_field_w_type
 
60
{
 
61
  LEX_STRING name;
 
62
  LEX_STRING type;
 
63
  LEX_STRING cset;
 
64
} TABLE_FIELD_W_TYPE;
 
65
 
 
66
bool create_myisam_from_heap(Session *session, Table *table,
 
67
                             MI_COLUMNDEF *start_recinfo,
 
68
                             MI_COLUMNDEF **recinfo,
 
69
                             int error, bool ignore_last_dupp_key_error);
 
70
 
 
71
class Table {
 
72
 
 
73
public:
356
74
  TABLE_SHARE   *s;
 
75
  Table() {}                               /* Remove gcc warning */
 
76
 
 
77
  /* SHARE methods */
 
78
  inline TABLE_SHARE *getShare() { return s; } /* Get rid of this long term */
 
79
  inline void setShare(TABLE_SHARE *new_share) { s= new_share; } /* Get rid of this long term */
 
80
  inline uint32_t sizeKeys() { return s->keys; }
 
81
  inline uint32_t sizeFields() { return s->fields; }
 
82
  inline uint32_t getRecordLength() { return s->reclength; }
 
83
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
 
84
  inline uint32_t *getBlobField() { return s->blob_field; }
 
85
  inline uint32_t getNullBytes() { return s->null_bytes; }
 
86
  inline uint32_t getNullFields() { return s->null_fields; }
 
87
  inline unsigned char *getDefaultValues() { return s->default_values; }
 
88
 
 
89
  inline bool isNullFieldFirst() { return s->null_field_first; }
 
90
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; }         /* Portable row format */
 
91
  inline bool isCrashed() { return s->crashed; }
 
92
  inline bool isNameLock() { return s->name_lock; }
 
93
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
 
94
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; }                 /* Protection against free */
 
95
 
 
96
  /* For TMP tables, should be pulled out as a class */
 
97
  void updateCreateInfo(HA_CREATE_INFO *create_info);
 
98
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
 
99
  bool create_myisam_tmp_table(KEY *keyinfo,
 
100
                               MI_COLUMNDEF *start_recinfo,
 
101
                               MI_COLUMNDEF **recinfo,
 
102
                               uint64_t options);
 
103
  void free_tmp_table(Session *session);
 
104
  bool open_tmp_table();
 
105
  size_t max_row_length(const unsigned char *data);
 
106
  uint32_t find_shortest_key(const key_map *usable_keys);
 
107
  bool compare_record(Field **ptr);
 
108
  bool compare_record();
 
109
 
 
110
  bool table_check_intact(const uint32_t table_f_count, const TABLE_FIELD_W_TYPE *table_def);
 
111
 
 
112
  /* See if this can be blown away */
 
113
  inline uint32_t getDBStat () { return db_stat; }
 
114
  inline uint32_t setDBStat () { return db_stat; }
 
115
  uint          db_stat;                /* mode of file as in handler.h */
 
116
 
357
117
  handler       *file;
358
 
  struct st_table *next, *prev;
 
118
  Table *next, *prev;
359
119
 
360
 
  THD   *in_use;                        /* Which thread uses this */
 
120
  Session       *in_use;                        /* Which thread uses this */
361
121
  Field **field;                        /* Pointer to fields */
362
122
 
363
 
  uchar *record[2];                     /* Pointer to records */
364
 
  uchar *write_row_record;              /* Used as optimisation in
365
 
                                           THD::write_row */
366
 
  uchar *insert_values;                  /* used by INSERT ... UPDATE */
367
 
  /* 
368
 
    Map of keys that can be used to retrieve all data from this table 
 
123
  unsigned char *record[2];                     /* Pointer to records */
 
124
  unsigned char *write_row_record;              /* Used as optimisation in
 
125
                                           Session::write_row */
 
126
  unsigned char *insert_values;                  /* used by INSERT ... UPDATE */
 
127
  /*
 
128
    Map of keys that can be used to retrieve all data from this table
369
129
    needed by the query without reading the row.
370
130
  */
371
131
  key_map covering_keys;
374
134
    A set of keys that can be used in the query that references this
375
135
    table.
376
136
 
377
 
    All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be 
378
 
    subtracted from this set upon instantiation. Thus for any TABLE t it holds
379
 
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we 
 
137
    All indexes disabled on the table's TABLE_SHARE (see Table::s) will be
 
138
    subtracted from this set upon instantiation. Thus for any Table t it holds
 
139
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
380
140
    must not introduce any new keys here (see setup_tables).
381
141
 
382
142
    The set is implemented as a bitmap.
391
151
  Field *next_number_field;             /* Set if next_number is activated */
392
152
  Field *found_next_number_field;       /* Set on open */
393
153
  Field_timestamp *timestamp_field;
 
154
  Field **vfield;                       /* Pointer to virtual fields*/
394
155
 
395
 
  TABLE_LIST *pos_in_table_list;/* Element referring to this table */
396
 
  ORDER         *group;
 
156
  TableList *pos_in_table_list;/* Element referring to this table */
 
157
  order_st *group;
397
158
  const char    *alias;                   /* alias or table name */
398
 
  uchar         *null_flags;
 
159
  unsigned char         *null_flags;
399
160
  my_bitmap_map *bitmap_init_value;
400
161
  MY_BITMAP     def_read_set, def_write_set, tmp_set; /* containers */
401
162
  MY_BITMAP     *read_set, *write_set;          /* Active column sets */
405
166
 
406
167
   Temporary tables:
407
168
 
408
 
   table->query_id is set to thd->query_id for the duration of a statement
 
169
   table->query_id is set to session->query_id for the duration of a statement
409
170
   and is reset to 0 once it is closed by the same statement. A non-zero
410
171
   table->query_id means that a statement is using the table even if it's
411
172
   not the current statement (table is in use by some outer statement).
412
173
 
413
174
   Non-temporary tables:
414
175
 
415
 
   Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
 
176
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
416
177
   for the duration of a statement and is reset to 0 once it is closed by
417
178
   the same statement. A non-zero query_id is used to control which tables
418
179
   in the list of pre-opened and locked tables are actually being used.
419
180
  */
420
181
  query_id_t    query_id;
421
182
 
422
 
  /* 
 
183
  /*
423
184
    For each key that has quick_keys.is_set(key) == true: estimate of #records
424
185
    and max #key parts that range access would use.
425
186
  */
431
192
  uint          quick_key_parts[MAX_KEY];
432
193
  uint          quick_n_ranges[MAX_KEY];
433
194
 
434
 
  /* 
 
195
  /*
435
196
    Estimate of number of records that satisfy SARGable part of the table
436
197
    condition, or table->file->records if no SARGable condition could be
437
198
    constructed.
438
199
    This value is used by join optimizer as an estimate of number of records
439
 
    that will pass the table condition (condition that depends on fields of 
 
200
    that will pass the table condition (condition that depends on fields of
440
201
    this table and constants)
441
202
  */
442
203
  ha_rows       quick_condition_rows;
456
217
  timestamp_auto_set_type timestamp_field_type;
457
218
  table_map     map;                    /* ID bit of table (1,2,4,8,16...) */
458
219
 
459
 
  uint          lock_position;          /* Position in DRIZZLE_LOCK.table */
460
 
  uint          lock_data_start;        /* Start pos. in DRIZZLE_LOCK.locks */
461
 
  uint          lock_count;             /* Number of locks */
 
220
  uint32_t          lock_position;          /* Position in DRIZZLE_LOCK.table */
 
221
  uint32_t          lock_data_start;        /* Start pos. in DRIZZLE_LOCK.locks */
 
222
  uint32_t          lock_count;             /* Number of locks */
462
223
  uint          tablenr,used_fields;
463
 
  uint          temp_pool_slot;         /* Used by intern temp tables */
 
224
  uint32_t          temp_pool_slot;             /* Used by intern temp tables */
464
225
  uint          status;                 /* What's in record[0] */
465
 
  uint          db_stat;                /* mode of file as in handler.h */
466
226
  /* number of select if it is derived table */
467
 
  uint          derived_select_number;
 
227
  uint32_t          derived_select_number;
468
228
  int           current_lock;           /* Type of lock on table */
469
229
  bool copy_blobs;                      /* copy_blobs when storing */
470
230
 
473
233
    If maybe_null !=0, this table is inner w.r.t. some outer join operation,
474
234
    and null_row may be true.
475
235
  */
476
 
  uint maybe_null;
 
236
  bool maybe_null;
 
237
 
477
238
  /*
478
 
    If true, the current table row is considered to have all columns set to 
 
239
    If true, the current table row is considered to have all columns set to
479
240
    NULL, including columns declared as "not null" (see maybe_null).
480
241
  */
481
242
  bool null_row;
482
243
 
483
 
  /*
484
 
    TODO: Each of the following flags take up 8 bits. They can just as easily
485
 
    be put into one single unsigned long and instead of taking up 18
486
 
    bytes, it would take up 4.
487
 
  */
488
244
  bool force_index;
489
245
  bool distinct,const_table,no_rows;
490
246
  bool key_read, no_keyread;
524
280
 
525
281
  REGINFO reginfo;                      /* field connections */
526
282
  MEM_ROOT mem_root;
527
 
  FILESORT_INFO sort;
 
283
  filesort_info_st sort;
528
284
 
529
285
  bool fill_item_list(List<Item> *item_list) const;
530
286
  void reset_item_list(List<Item> *item_list) const;
531
287
  void clear_column_bitmaps(void);
532
288
  void prepare_for_position(void);
533
 
  void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map);
534
 
  void mark_columns_used_by_index(uint index);
 
289
  void mark_columns_used_by_index_no_reset(uint32_t index, MY_BITMAP *map);
 
290
  void mark_columns_used_by_index(uint32_t index);
535
291
  void restore_column_maps_after_mark_index();
536
292
  void mark_auto_increment_column(void);
537
293
  void mark_columns_needed_for_update(void);
538
294
  void mark_columns_needed_for_delete(void);
539
295
  void mark_columns_needed_for_insert(void);
 
296
  void mark_virtual_columns(void);
540
297
  inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
541
298
                                 MY_BITMAP *write_set_arg)
542
299
  {
551
308
    read_set= read_set_arg;
552
309
    write_set= write_set_arg;
553
310
  }
 
311
 
 
312
  void restore_column_map(my_bitmap_map *old);
 
313
 
 
314
  my_bitmap_map *use_all_columns(MY_BITMAP *bitmap);
554
315
  inline void use_all_columns()
555
316
  {
556
317
    column_bitmaps_set(&s->all_set, &s->all_set);
557
318
  }
 
319
 
558
320
  inline void default_column_bitmaps()
559
321
  {
560
322
    read_set= &def_read_set;
561
323
    write_set= &def_write_set;
562
324
  }
 
325
 
563
326
  /* Is table open or should be treated as such by name-locking? */
564
327
  inline bool is_name_opened() { return db_stat || open_placeholder; }
565
328
  /*
567
330
  */
568
331
  inline bool needs_reopen_or_name_lock()
569
332
  { return s->version != refresh_version; }
570
 
};
571
 
 
572
 
enum enum_schema_table_state
573
 
574
 
  NOT_PROCESSED= 0,
575
 
  PROCESSED_BY_CREATE_SORT_INDEX,
576
 
  PROCESSED_BY_JOIN_EXEC
577
 
};
 
333
 
 
334
  int report_error(int error);
 
335
  int closefrm(bool free_share);
 
336
  uint32_t tmpkeyval();
 
337
};
 
338
 
 
339
Table *create_virtual_tmp_table(Session *session,
 
340
                                List<Create_field> &field_list);
578
341
 
579
342
typedef struct st_foreign_key_info
580
343
{
588
351
  List<LEX_STRING> referenced_fields;
589
352
} FOREIGN_KEY_INFO;
590
353
 
591
 
/*
592
 
  Make sure that the order of schema_tables and enum_schema_tables are the same.
593
 
*/
594
 
 
595
 
enum enum_schema_tables
596
 
{
597
 
  SCH_CHARSETS= 0,
598
 
  SCH_COLLATIONS,
599
 
  SCH_COLLATION_CHARACTER_SET_APPLICABILITY,
600
 
  SCH_COLUMNS,
601
 
  SCH_GLOBAL_STATUS,
602
 
  SCH_GLOBAL_VARIABLES,
603
 
  SCH_KEY_COLUMN_USAGE,
604
 
  SCH_OPEN_TABLES,
605
 
  SCH_PLUGINS,
606
 
  SCH_PROCESSLIST,
607
 
  SCH_REFERENTIAL_CONSTRAINTS,
608
 
  SCH_SCHEMATA,
609
 
  SCH_SESSION_STATUS,
610
 
  SCH_SESSION_VARIABLES,
611
 
  SCH_STATISTICS,
612
 
  SCH_STATUS,
613
 
  SCH_TABLES,
614
 
  SCH_TABLE_CONSTRAINTS,
615
 
  SCH_TABLE_NAMES,
616
 
  SCH_VARIABLES
617
 
};
618
 
 
619
 
 
620
 
#define MY_I_S_MAYBE_NULL 1
621
 
#define MY_I_S_UNSIGNED   2
622
 
 
623
 
 
624
 
#define SKIP_OPEN_TABLE 0                // do not open table
625
 
#define OPEN_FRM_ONLY   1                // open FRM file only
626
 
#define OPEN_FULL_TABLE 2                // open FRM,MYD, MYI files
627
 
 
628
354
typedef struct st_field_info
629
355
{
630
 
  /** 
631
 
      This is used as column name. 
 
356
  /**
 
357
      This is used as column name.
632
358
  */
633
359
  const char* field_name;
634
360
  /**
635
361
     For string-type columns, this is the maximum number of
636
362
     characters. Otherwise, it is the 'display-length' for the column.
637
363
  */
638
 
  uint field_length;
 
364
  uint32_t field_length;
639
365
  /**
640
366
     This denotes data type for the column. For the most part, there seems to
641
367
     be one entry in the enum for each SQL data type, although there seem to
651
377
     combine them using the bitwise or operator @c |. Both flags are
652
378
     defined in table.h.
653
379
   */
654
 
  uint field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
 
380
  uint32_t field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
655
381
  const char* old_name;
656
382
  /**
657
383
     This should be one of @c SKIP_OPEN_TABLE,
658
384
     @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
659
385
  */
660
 
  uint open_method;
 
386
  uint32_t open_method;
661
387
} ST_FIELD_INFO;
662
388
 
663
389
 
664
 
struct TABLE_LIST;
 
390
class TableList;
665
391
typedef class Item COND;
666
392
 
667
 
typedef struct st_schema_table
 
393
struct ST_SCHEMA_TABLE
668
394
{
669
395
  const char* table_name;
670
396
  ST_FIELD_INFO *fields_info;
671
397
  /* Create information_schema table */
672
 
  TABLE *(*create_table)  (THD *thd, TABLE_LIST *table_list);
 
398
  Table *(*create_table)  (Session *session, TableList *table_list);
673
399
  /* Fill table with data */
674
 
  int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond);
 
400
  int (*fill_table) (Session *session, TableList *tables, COND *cond);
675
401
  /* Handle fileds for old SHOW */
676
 
  int (*old_format) (THD *thd, struct st_schema_table *schema_table);
677
 
  int (*process_table) (THD *thd, TABLE_LIST *tables, TABLE *table,
 
402
  int (*old_format) (Session *session, struct ST_SCHEMA_TABLE *schema_table);
 
403
  int (*process_table) (Session *session, TableList *tables, Table *table,
678
404
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
679
 
  int idx_field1, idx_field2; 
 
405
  int idx_field1, idx_field2;
680
406
  bool hidden;
681
 
  uint i_s_requested_object;  /* the object we need to open(TABLE | VIEW) */
682
 
} ST_SCHEMA_TABLE;
 
407
  uint32_t i_s_requested_object;  /* the object we need to open(Table | VIEW) */
 
408
};
683
409
 
684
410
 
685
411
#define JOIN_TYPE_LEFT  1
689
415
class select_union;
690
416
class TMP_TABLE_PARAM;
691
417
 
692
 
Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
693
 
                        const char *name);
694
 
 
695
 
struct Field_translator
696
 
{
697
 
  Item *item;
698
 
  const char *name;
699
 
};
700
 
 
701
 
 
702
 
/*
703
 
  Column reference of a NATURAL/USING join. Since column references in
704
 
  joins can be both from views and stored tables, may point to either a
705
 
  Field (for tables), or a Field_translator (for views).
706
 
*/
707
 
 
708
 
class Natural_join_column: public Sql_alloc
709
 
{
710
 
public:
711
 
  Field_translator *view_field;  /* Column reference of merge view. */
712
 
  Field            *table_field; /* Column reference of table or temp view. */
713
 
  TABLE_LIST *table_ref; /* Original base table/view reference. */
714
 
  /*
715
 
    True if a common join column of two NATURAL/USING join operands. Notice
716
 
    that when we have a hierarchy of nested NATURAL/USING joins, a column can
717
 
    be common at some level of nesting but it may not be common at higher
718
 
    levels of nesting. Thus this flag may change depending on at which level
719
 
    we are looking at some column.
720
 
  */
721
 
  bool is_common;
722
 
public:
723
 
  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
724
 
  Natural_join_column(Field *field_param, TABLE_LIST *tab);
725
 
  const char *name();
726
 
  Item *create_item(THD *thd);
727
 
  Field *field();
728
 
  const char *table_name();
729
 
  const char *db_name();
730
 
};
731
 
 
732
 
 
733
 
/*
734
 
  Table reference in the FROM clause.
735
 
 
736
 
  These table references can be of several types that correspond to
737
 
  different SQL elements. Below we list all types of TABLE_LISTs with
738
 
  the necessary conditions to determine when a TABLE_LIST instance
739
 
  belongs to a certain type.
740
 
 
741
 
  1) table (TABLE_LIST::view == NULL)
742
 
     - base table
743
 
       (TABLE_LIST::derived == NULL)
744
 
     - subquery - TABLE_LIST::table is a temp table
745
 
       (TABLE_LIST::derived != NULL)
746
 
     - information schema table
747
 
       (TABLE_LIST::schema_table != NULL)
748
 
       NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
749
 
  2) view (TABLE_LIST::view != NULL)
750
 
     - merge    (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
751
 
           also (TABLE_LIST::field_translation != NULL)
752
 
     - tmptable (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
753
 
           also (TABLE_LIST::field_translation == NULL)
754
 
  3) nested table reference (TABLE_LIST::nested_join != NULL)
755
 
     - table sequence - e.g. (t1, t2, t3)
756
 
       TODO: how to distinguish from a JOIN?
757
 
     - general JOIN
758
 
       TODO: how to distinguish from a table sequence?
759
 
     - NATURAL JOIN
760
 
       (TABLE_LIST::natural_join != NULL)
761
 
       - JOIN ... USING
762
 
         (TABLE_LIST::join_using_fields != NULL)
763
 
     - semi-join
764
 
       ;
765
 
*/
766
 
 
767
 
class Index_hint;
768
 
struct TABLE_LIST
769
 
{
770
 
  TABLE_LIST() {}                          /* Remove gcc warning */
771
 
 
772
 
  /**
773
 
    Prepare TABLE_LIST that consists of one table instance to use in
774
 
    simple_open_and_lock_tables
775
 
  */
776
 
  inline void init_one_table(const char *db_name_arg,
777
 
                             const char *table_name_arg,
778
 
                             enum thr_lock_type lock_type_arg)
779
 
  {
780
 
    memset(this, 0, sizeof(*this));
781
 
    db= (char*) db_name_arg;
782
 
    table_name= alias= (char*) table_name_arg;
783
 
    lock_type= lock_type_arg;
784
 
  }
785
 
 
786
 
  /*
787
 
    List of tables local to a subquery (used by SQL_LIST). Considers
788
 
    views as leaves (unlike 'next_leaf' below). Created at parse time
789
 
    in st_select_lex::add_table_to_list() -> table_list.link_in_list().
790
 
  */
791
 
  TABLE_LIST *next_local;
792
 
  /* link in a global list of all queries tables */
793
 
  TABLE_LIST *next_global, **prev_global;
794
 
  char          *db, *alias, *table_name, *schema_table_name;
795
 
  char          *option;                /* Used by cache index  */
796
 
  Item          *on_expr;               /* Used with outer join */
797
 
  Item          *sj_on_expr;
798
 
  /*
799
 
    (Valid only for semi-join nests) Bitmap of tables that are within the
800
 
    semi-join (this is different from bitmap of all nest's children because
801
 
    tables that were pulled out of the semi-join nest remain listed as
802
 
    nest's children).
803
 
  */
804
 
  table_map     sj_inner_tables;
805
 
  /* Number of IN-compared expressions */
806
 
  uint          sj_in_exprs; 
807
 
  /*
808
 
    The structure of ON expression presented in the member above
809
 
    can be changed during certain optimizations. This member
810
 
    contains a snapshot of AND-OR structure of the ON expression
811
 
    made after permanent transformations of the parse tree, and is
812
 
    used to restore ON clause before every reexecution of a prepared
813
 
    statement or stored procedure.
814
 
  */
815
 
  Item          *prep_on_expr;
816
 
  COND_EQUAL    *cond_equal;            /* Used with outer join */
817
 
  /*
818
 
    During parsing - left operand of NATURAL/USING join where 'this' is
819
 
    the right operand. After parsing (this->natural_join == this) iff
820
 
    'this' represents a NATURAL or USING join operation. Thus after
821
 
    parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
822
 
  */
823
 
  TABLE_LIST *natural_join;
824
 
  /*
825
 
    True if 'this' represents a nested join that is a NATURAL JOIN.
826
 
    For one of the operands of 'this', the member 'natural_join' points
827
 
    to the other operand of 'this'.
828
 
  */
829
 
  bool is_natural_join;
830
 
  /* Field names in a USING clause for JOIN ... USING. */
831
 
  List<String> *join_using_fields;
832
 
  /*
833
 
    Explicitly store the result columns of either a NATURAL/USING join or
834
 
    an operand of such a join.
835
 
  */
836
 
  List<Natural_join_column> *join_columns;
837
 
  /* true if join_columns contains all columns of this table reference. */
838
 
  bool is_join_columns_complete;
839
 
 
840
 
  /*
841
 
    List of nodes in a nested join tree, that should be considered as
842
 
    leaves with respect to name resolution. The leaves are: views,
843
 
    top-most nodes representing NATURAL/USING joins, subqueries, and
844
 
    base tables. All of these TABLE_LIST instances contain a
845
 
    materialized list of columns. The list is local to a subquery.
846
 
  */
847
 
  TABLE_LIST *next_name_resolution_table;
848
 
  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
849
 
  List<Index_hint> *index_hints;
850
 
  TABLE        *table;                          /* opened table */
851
 
  uint          table_id; /* table id (from binlog) for opened table */
852
 
  /*
853
 
    select_result for derived table to pass it from table creation to table
854
 
    filling procedure
855
 
  */
856
 
  select_union  *derived_result;
857
 
  /*
858
 
    Reference from aux_tables to local list entry of main select of
859
 
    multi-delete statement:
860
 
    delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
861
 
    here it will be reference of first occurrence of t1 to second (as you
862
 
    can see this lists can't be merged)
863
 
  */
864
 
  TABLE_LIST    *correspondent_table;
865
 
  st_select_lex_unit *derived;          /* SELECT_LEX_UNIT of derived table */
866
 
  ST_SCHEMA_TABLE *schema_table;        /* Information_schema table */
867
 
  st_select_lex *schema_select_lex;
868
 
  /*
869
 
    True when the view field translation table is used to convert
870
 
    schema table fields for backwards compatibility with SHOW command.
871
 
  */
872
 
  bool schema_table_reformed;
873
 
  TMP_TABLE_PARAM *schema_table_param;
874
 
  /* link to select_lex where this table was used */
875
 
  st_select_lex *select_lex;
876
 
  Field_translator *field_translation;  /* array of VIEW fields */
877
 
  /* pointer to element after last one in translation table above */
878
 
  Field_translator *field_translation_end;
879
 
  /*
880
 
    List (based on next_local) of underlying tables of this view. I.e. it
881
 
    does not include the tables of subqueries used in the view. Is set only
882
 
    for merged views.
883
 
  */
884
 
  TABLE_LIST    *merge_underlying_list;
885
 
  /*
886
 
    - 0 for base tables
887
 
    - in case of the view it is the list of all (not only underlying
888
 
    tables but also used in subquery ones) tables of the view.
889
 
  */
890
 
  List<TABLE_LIST> *view_tables;
891
 
  /* most upper view this table belongs to */
892
 
  TABLE_LIST    *belong_to_view;
893
 
  /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */
894
 
  TABLE_LIST    *parent_l;
895
 
  /*
896
 
    List of all base tables local to a subquery including all view
897
 
    tables. Unlike 'next_local', this in this list views are *not*
898
 
    leaves. Created in setup_tables() -> make_leaves_list().
899
 
  */
900
 
  TABLE_LIST    *next_leaf;
901
 
  /* data need by some engines in query cache*/
902
 
  uint64_t     engine_data;
903
 
  /* call back function for asking handler about caching in query cache */
904
 
  qc_engine_callback callback_func;
905
 
  thr_lock_type lock_type;
906
 
  uint          outer_join;             /* Which join type */
907
 
  uint          shared;                 /* Used in multi-upd */
908
 
  size_t        db_length;
909
 
  size_t        table_name_length;
910
 
  bool          straight;               /* optimize with prev table */
911
 
  bool          updating;               /* for replicate-do/ignore table */
912
 
  bool          force_index;            /* prefer index over table scan */
913
 
  bool          ignore_leaves;          /* preload only non-leaf nodes */
914
 
  table_map     dep_tables;             /* tables the table depends on      */
915
 
  table_map     on_expr_dep_tables;     /* tables on expression depends on  */
916
 
  struct st_nested_join *nested_join;   /* if the element is a nested join  */
917
 
  TABLE_LIST *embedding;             /* nested join containing the table */
918
 
  List<TABLE_LIST> *join_list;/* join list the table belongs to   */
919
 
  bool          cacheable_table;        /* stop PS caching */
920
 
  /* FRMTYPE_ERROR if any type is acceptable */
921
 
  enum frm_type_enum required_type;
922
 
  handlerton    *db_type;               /* table_type for handler */
923
 
  char          timestamp_buffer[20];   /* buffer for timestamp (19+1) */
924
 
  /*
925
 
    This TABLE_LIST object corresponds to the table to be created
926
 
    so it is possible that it does not exist (used in CREATE TABLE
927
 
    ... SELECT implementation).
928
 
  */
929
 
  bool          create;
930
 
  /* For transactional locking. */
931
 
  int           lock_timeout;           /* NOWAIT or WAIT [X]               */
932
 
  bool          lock_transactional;     /* If transactional lock requested. */
933
 
  bool          internal_tmp_table;
934
 
  /** true if an alias for this table was specified in the SQL. */
935
 
  bool          is_alias;
936
 
  /** true if the table is referred to in the statement using a fully
937
 
      qualified name (<db_name>.<table_name>).
938
 
  */
939
 
  bool          is_fqtn;
940
 
 
941
 
  uint i_s_requested_object;
942
 
  bool has_db_lookup_value;
943
 
  bool has_table_lookup_value;
944
 
  uint table_open_method;
945
 
  enum enum_schema_table_state schema_table_state;
946
 
  void set_underlying_merge();
947
 
  bool setup_underlying(THD *thd);
948
 
  void cleanup_items();
949
 
  /*
950
 
    If you change placeholder(), please check the condition in
951
 
    check_transactional_lock() too.
952
 
  */
953
 
  bool placeholder()
954
 
  {
955
 
    return derived || schema_table || (create && !table->db_stat) || !table;
956
 
  }
957
 
  void print(THD *thd, String *str, enum_query_type query_type);
958
 
  bool set_insert_values(MEM_ROOT *mem_root);
959
 
  TABLE_LIST *find_underlying_table(TABLE *table);
960
 
  TABLE_LIST *first_leaf_for_name_resolution();
961
 
  TABLE_LIST *last_leaf_for_name_resolution();
962
 
  bool is_leaf_for_name_resolution();
963
 
  inline TABLE_LIST *top_table()
964
 
    { return belong_to_view ? belong_to_view : this; }
965
 
 
966
 
  /*
967
 
    Cleanup for re-execution in a prepared statement or a stored
968
 
    procedure.
969
 
  */
970
 
  void reinit_before_use(THD *thd);
971
 
  Item_subselect *containing_subselect();
972
 
 
973
 
  /* 
974
 
    Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
975
 
    st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
976
 
    st_table::force_index and st_table::covering_keys.
977
 
  */
978
 
  bool process_index_hints(TABLE *table);
979
 
 
980
 
private:
981
 
  bool prep_where(THD *thd, Item **conds, bool no_where_clause);
982
 
  /*
983
 
    Cleanup for re-execution in a prepared statement or a stored
984
 
    procedure.
985
 
  */
986
 
};
987
 
 
988
 
class Item;
989
 
 
990
 
/*
991
 
  Iterator over the fields of a generic table reference.
992
 
*/
993
 
 
994
 
class Field_iterator: public Sql_alloc
995
 
{
996
 
public:
997
 
  Field_iterator() {}                         /* Remove gcc warning */
998
 
  virtual ~Field_iterator() {}
999
 
  virtual void set(TABLE_LIST *)= 0;
1000
 
  virtual void next()= 0;
1001
 
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
1002
 
  virtual const char *name()= 0;
1003
 
  virtual Item *create_item(THD *)= 0;
1004
 
  virtual Field *field()= 0;
1005
 
};
1006
 
 
1007
 
 
1008
 
/* 
1009
 
  Iterator over the fields of a base table, view with temporary
1010
 
  table, or subquery.
1011
 
*/
1012
 
 
1013
 
class Field_iterator_table: public Field_iterator
1014
 
{
1015
 
  Field **ptr;
1016
 
public:
1017
 
  Field_iterator_table() :ptr(0) {}
1018
 
  void set(TABLE_LIST *table) { ptr= table->table->field; }
1019
 
  void set_table(TABLE *table) { ptr= table->field; }
1020
 
  void next() { ptr++; }
1021
 
  bool end_of_fields() { return *ptr == 0; }
1022
 
  const char *name();
1023
 
  Item *create_item(THD *thd);
1024
 
  Field *field() { return *ptr; }
1025
 
};
1026
 
 
1027
 
 
1028
 
/* Iterator over the fields of a merge view. */
1029
 
 
1030
 
class Field_iterator_view: public Field_iterator
1031
 
{
1032
 
  Field_translator *ptr, *array_end;
1033
 
  TABLE_LIST *view;
1034
 
public:
1035
 
  Field_iterator_view() :ptr(0), array_end(0) {}
1036
 
  void set(TABLE_LIST *table);
1037
 
  void next() { ptr++; }
1038
 
  bool end_of_fields() { return ptr == array_end; }
1039
 
  const char *name();
1040
 
  Item *create_item(THD *thd);
1041
 
  Item **item_ptr() {return &ptr->item; }
1042
 
  Field *field() { return 0; }
1043
 
  inline Item *item() { return ptr->item; }
1044
 
  Field_translator *field_translator() { return ptr; }
1045
 
};
1046
 
 
1047
 
 
1048
 
/*
1049
 
  Field_iterator interface to the list of materialized fields of a
1050
 
  NATURAL/USING join.
1051
 
*/
1052
 
 
1053
 
class Field_iterator_natural_join: public Field_iterator
1054
 
{
1055
 
  List_iterator_fast<Natural_join_column> column_ref_it;
1056
 
  Natural_join_column *cur_column_ref;
1057
 
public:
1058
 
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
1059
 
  ~Field_iterator_natural_join() {}
1060
 
  void set(TABLE_LIST *table);
1061
 
  void next();
1062
 
  bool end_of_fields() { return !cur_column_ref; }
1063
 
  const char *name() { return cur_column_ref->name(); }
1064
 
  Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
1065
 
  Field *field() { return cur_column_ref->field(); }
1066
 
  Natural_join_column *column_ref() { return cur_column_ref; }
1067
 
};
1068
 
 
1069
 
 
1070
 
/*
1071
 
  Generic iterator over the fields of an arbitrary table reference.
1072
 
 
1073
 
  DESCRIPTION
1074
 
    This class unifies the various ways of iterating over the columns
1075
 
    of a table reference depending on the type of SQL entity it
1076
 
    represents. If such an entity represents a nested table reference,
1077
 
    this iterator encapsulates the iteration over the columns of the
1078
 
    members of the table reference.
1079
 
 
1080
 
  IMPLEMENTATION
1081
 
    The implementation assumes that all underlying NATURAL/USING table
1082
 
    references already contain their result columns and are linked into
1083
 
    the list TABLE_LIST::next_name_resolution_table.
1084
 
*/
1085
 
 
1086
 
class Field_iterator_table_ref: public Field_iterator
1087
 
{
1088
 
  TABLE_LIST *table_ref, *first_leaf, *last_leaf;
1089
 
  Field_iterator_table        table_field_it;
1090
 
  Field_iterator_view         view_field_it;
1091
 
  Field_iterator_natural_join natural_join_it;
1092
 
  Field_iterator *field_it;
1093
 
  void set_field_iterator();
1094
 
public:
1095
 
  Field_iterator_table_ref() :field_it(NULL) {}
1096
 
  void set(TABLE_LIST *table);
1097
 
  void next();
1098
 
  bool end_of_fields()
1099
 
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
1100
 
  const char *name() { return field_it->name(); }
1101
 
  const char *table_name();
1102
 
  const char *db_name();
1103
 
  Item *create_item(THD *thd) { return field_it->create_item(thd); }
1104
 
  Field *field() { return field_it->field(); }
1105
 
  Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref);
1106
 
  Natural_join_column *get_natural_column_ref();
1107
 
};
1108
 
 
1109
 
 
1110
 
typedef struct st_nested_join
1111
 
{
1112
 
  List<TABLE_LIST>  join_list;       /* list of elements in the nested join */
1113
 
  table_map         used_tables;     /* bitmap of tables in the nested join */
1114
 
  table_map         not_null_tables; /* tables that rejects nulls           */
1115
 
  struct st_join_table *first_nested;/* the first nested table in the plan  */
1116
 
  /* 
1117
 
    Used to count tables in the nested join in 2 isolated places:
1118
 
    1. In make_outerjoin_info(). 
1119
 
    2. check_interleaving_with_nj/restore_prev_nj_state (these are called
1120
 
       by the join optimizer. 
1121
 
    Before each use the counters are zeroed by reset_nj_counters.
1122
 
  */
1123
 
  uint              counter_;
1124
 
  nested_join_map   nj_map;          /* Bit used to identify this nested join*/
1125
 
  /*
1126
 
    (Valid only for semi-join nests) Bitmap of tables outside the semi-join
1127
 
    that are used within the semi-join's ON condition.
1128
 
  */
1129
 
  table_map         sj_depends_on;
1130
 
  /* Outer non-trivially correlated tables */
1131
 
  table_map         sj_corr_tables;
1132
 
  List<Item>        sj_outer_expr_list;
1133
 
} NESTED_JOIN;
1134
 
 
1135
 
 
1136
418
typedef struct st_changed_table_list
1137
419
{
1138
420
  struct        st_changed_table_list *next;
1139
421
  char          *key;
1140
422
  uint32_t        key_length;
1141
 
} CHANGED_TABLE_LIST;
1142
 
 
1143
 
 
1144
 
typedef struct st_open_table_list{
 
423
} CHANGED_TableList;
 
424
 
 
425
 
 
426
typedef struct st_open_table_list
 
427
{
1145
428
  struct st_open_table_list *next;
1146
429
  char  *db,*table;
1147
430
  uint32_t in_use,locked;
1148
 
} OPEN_TABLE_LIST;
1149
 
 
1150
 
typedef struct st_table_field_w_type
1151
 
{
1152
 
  LEX_STRING name;
1153
 
  LEX_STRING type;
1154
 
  LEX_STRING cset;
1155
 
} TABLE_FIELD_W_TYPE;
1156
 
 
1157
 
 
1158
 
bool
1159
 
table_check_intact(TABLE *table, const uint table_f_count,
1160
 
                   const TABLE_FIELD_W_TYPE *table_def);
1161
 
 
1162
 
static inline my_bitmap_map *tmp_use_all_columns(TABLE *table,
1163
 
                                                 MY_BITMAP *bitmap)
1164
 
{
1165
 
  my_bitmap_map *old= bitmap->bitmap;
1166
 
  bitmap->bitmap= table->s->all_set.bitmap;
1167
 
  return old;
1168
 
}
1169
 
 
1170
 
 
1171
 
static inline void tmp_restore_column_map(MY_BITMAP *bitmap,
1172
 
                                          my_bitmap_map *old)
1173
 
{
1174
 
  bitmap->bitmap= old;
1175
 
}
1176
 
 
1177
 
/* The following is only needed for debugging */
1178
 
 
1179
 
static inline my_bitmap_map *dbug_tmp_use_all_columns(TABLE *table __attribute__((unused)),
1180
 
                                                      MY_BITMAP *bitmap __attribute__((unused)))
1181
 
{
1182
 
  return 0;
1183
 
}
1184
 
 
1185
 
static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap __attribute__((unused)),
1186
 
                                               my_bitmap_map *old __attribute__((unused)))
1187
 
{
1188
 
  return;
1189
 
}
1190
 
 
1191
 
size_t max_row_length(TABLE *table, const uchar *data);
1192
 
 
 
431
} OPEN_TableList;
 
432
 
 
433
 
 
434
inline void mark_as_null_row(Table *table)
 
435
{
 
436
  table->null_row=1;
 
437
  table->status|=STATUS_NULL_ROW;
 
438
  memset(table->null_flags, 255, table->s->null_bytes);
 
439
}
 
440
 
 
441
/**
 
442
  clean/setup table fields and map.
 
443
 
 
444
  @param table        Table structure pointer (which should be setup)
 
445
  @param table_list   TableList structure pointer (owner of Table)
 
446
  @param tablenr     table number
 
447
*/
 
448
void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr);
 
449
 
 
450
#endif /* DRIZZLED_TABLE_H */