~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
1 by brian
clean slate
20
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
21
/* Structs that defines the Table */
1 by brian
clean slate
22
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
23
#ifndef DRIZZLED_TABLE_H
24
#define DRIZZLED_TABLE_H
25
26
#include <storage/myisam/myisam.h>
327.2.3 by Brian Aker
Refactoring of class Table
27
#include <drizzled/order.h>
28
#include <drizzled/filesort_info.h>
327.2.4 by Brian Aker
Refactoring table.h
29
#include <drizzled/natural_join_column.h>
353 by Brian Aker
Moved Field iterator out to its own definition.
30
#include <drizzled/field_iterator.h>
520.8.6 by Monty Taylor
Removed handler from common_includes.
31
#include <mysys/hash.h>
32
#include <drizzled/handler.h>
575.4.5 by Monty Taylor
Added lex_string.h header.
33
#include <drizzled/lex_string.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
34
#include <drizzled/table_list.h>
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
35
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
36
class Item;
1 by brian
clean slate
37
class Item_subselect;
38
class st_select_lex_unit;
39
class st_select_lex;
40
class COND_EQUAL;
41
class Security_context;
327.2.4 by Brian Aker
Refactoring table.h
42
class TableList;
1 by brian
clean slate
43
44
/*************************************************************************/
45
46
47
class Field_timestamp;
48
class Field_blob;
49
50
typedef enum enum_table_category TABLE_CATEGORY;
51
52
TABLE_CATEGORY get_table_category(const LEX_STRING *db,
53
                                  const LEX_STRING *name);
54
55
/*
56
  This structure is shared between different table objects. There is one
57
  instance of table share per one table in the database.
58
*/
59
60
typedef struct st_table_share
61
{
62
  st_table_share() {}                    /* Remove gcc warning */
63
64
  /** Category of this table. */
65
  TABLE_CATEGORY table_category;
66
67
  /* hash of field names (contains pointers to elements of field array) */
68
  HASH	name_hash;			/* hash of field names */
69
  MEM_ROOT mem_root;
70
  TYPELIB keynames;			/* Pointers to keynames */
71
  TYPELIB fieldnames;			/* Pointer to fieldnames */
72
  TYPELIB *intervals;			/* pointer to interval info */
73
  pthread_mutex_t mutex;                /* For locking the share  */
74
  pthread_cond_t cond;			/* To signal that share is ready */
75
  struct st_table_share *next,		/* Link to unused shares */
76
    **prev;
77
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
78
  /* The following is copied to each Table on OPEN */
1 by brian
clean slate
79
  Field **field;
80
  Field **found_next_number_field;
81
  Field *timestamp_field;               /* Used only during open */
82
  KEY  *key_info;			/* data of keys in database */
83
  uint	*blob_field;			/* Index to blobs in Field arrray*/
84
481 by Brian Aker
Remove all of uchar.
85
  unsigned char	*default_values;		/* row with default values */
1 by brian
clean slate
86
  LEX_STRING comment;			/* Comment about table */
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
87
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
1 by brian
clean slate
88
89
  MY_BITMAP all_set;
90
  /*
91
    Key which is used for looking-up table in table cache and in the list
92
    of thread's temporary tables. Has the form of:
93
      "database_name\0table_name\0" + optional part for temporary tables.
94
95
    Note that all three 'table_cache_key', 'db' and 'table_name' members
96
    must be set (and be non-zero) for tables in table cache. They also
97
    should correspond to each other.
98
    To ensure this one can use set_table_cache() methods.
99
  */
100
  LEX_STRING table_cache_key;
101
  LEX_STRING db;                        /* Pointer to db */
102
  LEX_STRING table_name;                /* Table name (for open) */
366 by Patrick Galbraith
Ulong conversion
103
  LEX_STRING path;	/* Path to .frm file (from datadir) */
1 by brian
clean slate
104
  LEX_STRING normalized_path;		/* unpack_filename(path) */
105
  LEX_STRING connect_string;
106
366 by Patrick Galbraith
Ulong conversion
107
  /*
1 by brian
clean slate
108
     Set of keys in use, implemented as a Bitmap.
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
109
     Excludes keys disabled by ALTER Table ... DISABLE KEYS.
1 by brian
clean slate
110
  */
111
  key_map keys_in_use;
112
  key_map keys_for_keyread;
113
  ha_rows min_rows, max_rows;		/* create information */
366 by Patrick Galbraith
Ulong conversion
114
  uint32_t   avg_row_length;		/* create information */
115
  uint32_t   block_size;                   /* create information */
116
  uint32_t   version, mysql_version;
117
  uint32_t   timestamp_offset;		/* Set to offset+1 of record */
118
  uint32_t   reclength;			/* Recordlength */
383.7.1 by Andrey Zhakov
Initial submit of code and tests
119
  uint32_t   stored_rec_length;         /* Stored record length 
120
                                           (no generated-only virtual fields) */
1 by brian
clean slate
121
122
  plugin_ref db_plugin;			/* storage engine plugin */
123
  inline handlerton *db_type() const	/* table_type for handler */
366 by Patrick Galbraith
Ulong conversion
124
  {
51.1.70 by Jay Pipes
Removed/replaced DBUG symbols and removed sql_test.cc from Makefile
125
    // assert(db_plugin);
1 by brian
clean slate
126
    return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL;
127
  }
128
  enum row_type row_type;		/* How rows are stored */
129
  enum tmp_table_type tmp_table;
130
  enum ha_choice transactional;
131
  enum ha_choice page_checksum;
132
481.3.1 by Monty Taylor
Merged vcol stuff.
133
  uint32_t ref_count;       /* How many Table objects uses this */
482 by Brian Aker
Remove uint.
134
  uint32_t open_count;			/* Number of tables in open list */
135
  uint32_t blob_ptr_size;			/* 4 or 8 */
136
  uint32_t key_block_size;			/* create key_block_size, if used */
137
  uint32_t null_bytes, last_null_bit_pos;
138
  uint32_t fields;				/* Number of fields */
481.3.1 by Monty Taylor
Merged vcol stuff.
139
  uint32_t stored_fields;                   /* Number of stored fields 
383.7.1 by Andrey Zhakov
Initial submit of code and tests
140
                                           (i.e. without generated-only ones) */
482 by Brian Aker
Remove uint.
141
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
142
  uint32_t keys, key_parts;
143
  uint32_t max_key_length, max_unique_length, total_key_length;
144
  uint32_t uniques;                         /* Number of UNIQUE index */
145
  uint32_t null_fields;			/* number of null fields */
146
  uint32_t blob_fields;			/* number of blob fields */
147
  uint32_t timestamp_field_offset;		/* Field number for timestamp field */
148
  uint32_t varchar_fields;                  /* number of varchar fields */
149
  uint32_t db_create_options;		/* Create options from database */
150
  uint32_t db_options_in_use;		/* Options in use */
151
  uint32_t db_record_offset;		/* if HA_REC_IN_SEQ */
152
  uint32_t rowid_field_offset;		/* Field_nr +1 to rowid field */
1 by brian
clean slate
153
  /* Index of auto-updated TIMESTAMP field in field array */
482 by Brian Aker
Remove uint.
154
  uint32_t primary_key;
155
  uint32_t next_number_index;               /* autoincrement key number */
156
  uint32_t next_number_key_offset;          /* autoinc keypart offset in a key */
157
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
158
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
159
  uint32_t column_bitmap_size;
590.1.4 by Stewart Smith
remove frm_version from TABLE_SHARE
160
481.3.1 by Monty Taylor
Merged vcol stuff.
161
  uint32_t vfields;                         /* Number of virtual fields */
1 by brian
clean slate
162
  bool null_field_first;
163
  bool db_low_byte_first;		/* Portable row format */
164
  bool crashed;
165
  bool name_lock, replace_with_name_lock;
166
  bool waiting_on_cond;                 /* Protection against free */
366 by Patrick Galbraith
Ulong conversion
167
  uint32_t table_map_id;                   /* for row-based replication */
1 by brian
clean slate
168
  uint64_t table_map_version;
169
170
  /*
171
    Cache for row-based replication table share checks that does not
172
    need to be repeated. Possible values are: -1 when cache value is
173
    not calculated yet, 0 when table *shall not* be replicated, 1 when
174
    table *may* be replicated.
175
  */
176
  int cached_row_logging_check;
177
178
  /*
179
    Set share's table cache key and update its db and table name appropriately.
180
181
    SYNOPSIS
182
      set_table_cache_key()
183
        key_buff    Buffer with already built table cache key to be
184
                    referenced from share.
185
        key_length  Key length.
186
187
    NOTES
188
      Since 'key_buff' buffer will be referenced from share it should has same
189
      life-time as share itself.
190
      This method automatically ensures that TABLE_SHARE::table_name/db have
191
      appropriate values by using table cache key as their source.
192
  */
193
482 by Brian Aker
Remove uint.
194
  void set_table_cache_key(char *key_buff, uint32_t key_length)
1 by brian
clean slate
195
  {
196
    table_cache_key.str= key_buff;
197
    table_cache_key.length= key_length;
198
    /*
199
      Let us use the fact that the key is "db/0/table_name/0" + optional
200
      part for temporary tables.
201
    */
202
    db.str=            table_cache_key.str;
203
    db.length=         strlen(db.str);
204
    table_name.str=    db.str + db.length + 1;
205
    table_name.length= strlen(table_name.str);
206
  }
207
208
209
  /*
210
    Set share's table cache key and update its db and table name appropriately.
211
212
    SYNOPSIS
213
      set_table_cache_key()
214
        key_buff    Buffer to be used as storage for table cache key
215
                    (should be at least key_length bytes).
216
        key         Value for table cache key.
217
        key_length  Key length.
218
219
    NOTE
220
      Since 'key_buff' buffer will be used as storage for table cache key
221
      it should has same life-time as share itself.
222
  */
223
482 by Brian Aker
Remove uint.
224
  void set_table_cache_key(char *key_buff, const char *key, uint32_t key_length)
1 by brian
clean slate
225
  {
226
    memcpy(key_buff, key, key_length);
227
    set_table_cache_key(key_buff, key_length);
228
  }
229
230
  inline bool honor_global_locks()
231
  {
326 by Brian Aker
Remove server based system tables (we no longer have them).
232
    return (table_category == TABLE_CATEGORY_USER);
1 by brian
clean slate
233
  }
234
366 by Patrick Galbraith
Ulong conversion
235
  inline uint32_t get_table_def_version()
1 by brian
clean slate
236
  {
237
    return table_map_id;
238
  }
239
240
} TABLE_SHARE;
241
242
366 by Patrick Galbraith
Ulong conversion
243
extern uint32_t refresh_version;
1 by brian
clean slate
244
327.2.3 by Brian Aker
Refactoring of class Table
245
typedef struct st_table_field_w_type
246
{
247
  LEX_STRING name;
248
  LEX_STRING type;
249
  LEX_STRING cset;
250
} TABLE_FIELD_W_TYPE;
251
520.1.22 by Brian Aker
Second pass of thd cleanup
252
bool create_myisam_from_heap(Session *session, Table *table,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
253
                             MI_COLUMNDEF *start_recinfo,
254
                             MI_COLUMNDEF **recinfo, 
255
                             int error, bool ignore_last_dupp_key_error);
256
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
257
class Table {
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
258
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
259
public:
1 by brian
clean slate
260
  TABLE_SHARE	*s;
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
261
  Table() {}                               /* Remove gcc warning */
262
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
263
  /* SHARE methods */
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
264
  inline TABLE_SHARE *getShare() { return s; } /* Get rid of this long term */
265
  inline void setShare(TABLE_SHARE *new_share) { s= new_share; } /* Get rid of this long term */
482 by Brian Aker
Remove uint.
266
  inline uint32_t sizeKeys() { return s->keys; }
267
  inline uint32_t sizeFields() { return s->fields; }
268
  inline uint32_t getRecordLength() { return s->reclength; }
269
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
270
  inline uint32_t *getBlobField() { return s->blob_field; }
271
  inline uint32_t getNullBytes() { return s->null_bytes; }
272
  inline uint32_t getNullFields() { return s->null_fields; }
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
273
  inline unsigned char *getDefaultValues() { return s->default_values; }
274
275
  inline bool isNullFieldFirst() { return s->null_field_first; }
276
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; }		/* Portable row format */
277
  inline bool isCrashed() { return s->crashed; }
278
  inline bool isNameLock() { return s->name_lock; } 
279
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
280
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; }                 /* Protection against free */
281
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
282
  /* For TMP tables, should be pulled out as a class */
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
283
  void updateCreateInfo(HA_CREATE_INFO *create_info);
481 by Brian Aker
Remove all of uchar.
284
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
285
  bool create_myisam_tmp_table(KEY *keyinfo, 
286
                               MI_COLUMNDEF *start_recinfo,
287
                               MI_COLUMNDEF **recinfo, 
288
                               uint64_t options);
520.1.22 by Brian Aker
Second pass of thd cleanup
289
  void free_tmp_table(Session *session);
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
290
  bool open_tmp_table();
481 by Brian Aker
Remove all of uchar.
291
  size_t max_row_length(const unsigned char *data);
482 by Brian Aker
Remove uint.
292
  uint32_t find_shortest_key(const key_map *usable_keys);
355 by Brian Aker
More Table cleanup
293
  bool compare_record(Field **ptr);
294
  bool compare_record();
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
295
482 by Brian Aker
Remove uint.
296
  bool table_check_intact(const uint32_t table_f_count, const TABLE_FIELD_W_TYPE *table_def);
327.2.3 by Brian Aker
Refactoring of class Table
297
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
298
  /* See if this can be blown away */
482 by Brian Aker
Remove uint.
299
  inline uint32_t getDBStat () { return db_stat; }
300
  inline uint32_t setDBStat () { return db_stat; }
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
301
  uint		db_stat;		/* mode of file as in handler.h */
302
1 by brian
clean slate
303
  handler	*file;
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
304
  Table *next, *prev;
1 by brian
clean slate
305
520.1.21 by Brian Aker
THD -> Session rename
306
  Session	*in_use;                        /* Which thread uses this */
1 by brian
clean slate
307
  Field **field;			/* Pointer to fields */
308
481 by Brian Aker
Remove all of uchar.
309
  unsigned char *record[2];			/* Pointer to records */
310
  unsigned char *write_row_record;		/* Used as optimisation in
520.1.21 by Brian Aker
THD -> Session rename
311
					   Session::write_row */
481 by Brian Aker
Remove all of uchar.
312
  unsigned char *insert_values;                  /* used by INSERT ... UPDATE */
1 by brian
clean slate
313
  /* 
314
    Map of keys that can be used to retrieve all data from this table 
315
    needed by the query without reading the row.
316
  */
317
  key_map covering_keys;
318
  key_map quick_keys, merge_keys;
319
  /*
320
    A set of keys that can be used in the query that references this
321
    table.
322
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
323
    All indexes disabled on the table's TABLE_SHARE (see Table::s) will be 
324
    subtracted from this set upon instantiation. Thus for any Table t it holds
1 by brian
clean slate
325
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we 
326
    must not introduce any new keys here (see setup_tables).
327
328
    The set is implemented as a bitmap.
329
  */
330
  key_map keys_in_use_for_query;
331
  /* Map of keys that can be used to calculate GROUP BY without sorting */
332
  key_map keys_in_use_for_group_by;
333
  /* Map of keys that can be used to calculate ORDER BY without sorting */
334
  key_map keys_in_use_for_order_by;
335
  KEY  *key_info;			/* data of keys in database */
336
337
  Field *next_number_field;		/* Set if next_number is activated */
338
  Field *found_next_number_field;	/* Set on open */
339
  Field_timestamp *timestamp_field;
383.7.1 by Andrey Zhakov
Initial submit of code and tests
340
  Field **vfield;                       /* Pointer to virtual fields*/
1 by brian
clean slate
341
327.2.4 by Brian Aker
Refactoring table.h
342
  TableList *pos_in_table_list;/* Element referring to this table */
327.2.3 by Brian Aker
Refactoring of class Table
343
  order_st *group;
1 by brian
clean slate
344
  const char	*alias;            	  /* alias or table name */
481 by Brian Aker
Remove all of uchar.
345
  unsigned char		*null_flags;
1 by brian
clean slate
346
  my_bitmap_map	*bitmap_init_value;
347
  MY_BITMAP     def_read_set, def_write_set, tmp_set; /* containers */
348
  MY_BITMAP     *read_set, *write_set;          /* Active column sets */
349
  /*
350
   The ID of the query that opened and is using this table. Has different
351
   meanings depending on the table type.
352
353
   Temporary tables:
354
520.1.22 by Brian Aker
Second pass of thd cleanup
355
   table->query_id is set to session->query_id for the duration of a statement
1 by brian
clean slate
356
   and is reset to 0 once it is closed by the same statement. A non-zero
357
   table->query_id means that a statement is using the table even if it's
358
   not the current statement (table is in use by some outer statement).
359
360
   Non-temporary tables:
361
520.1.22 by Brian Aker
Second pass of thd cleanup
362
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
1 by brian
clean slate
363
   for the duration of a statement and is reset to 0 once it is closed by
364
   the same statement. A non-zero query_id is used to control which tables
365
   in the list of pre-opened and locked tables are actually being used.
366
  */
367
  query_id_t	query_id;
368
369
  /* 
51.1.70 by Jay Pipes
Removed/replaced DBUG symbols and removed sql_test.cc from Makefile
370
    For each key that has quick_keys.is_set(key) == true: estimate of #records
1 by brian
clean slate
371
    and max #key parts that range access would use.
372
  */
373
  ha_rows	quick_rows[MAX_KEY];
374
375
  /* Bitmaps of key parts that =const for the entire join. */
376
  key_part_map  const_key_parts[MAX_KEY];
377
378
  uint		quick_key_parts[MAX_KEY];
379
  uint		quick_n_ranges[MAX_KEY];
380
381
  /* 
382
    Estimate of number of records that satisfy SARGable part of the table
383
    condition, or table->file->records if no SARGable condition could be
384
    constructed.
385
    This value is used by join optimizer as an estimate of number of records
386
    that will pass the table condition (condition that depends on fields of 
387
    this table and constants)
388
  */
389
  ha_rows       quick_condition_rows;
390
391
  /*
392
    If this table has TIMESTAMP field with auto-set property (pointed by
393
    timestamp_field member) then this variable indicates during which
394
    operations (insert only/on update/in both cases) we should set this
395
    field to current timestamp. If there are no such field in this table
396
    or we should not automatically set its value during execution of current
397
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
398
399
    Value of this variable is set for each statement in open_table() and
400
    if needed cleared later in statement processing code (see mysql_update()
401
    as example).
402
  */
403
  timestamp_auto_set_type timestamp_field_type;
404
  table_map	map;                    /* ID bit of table (1,2,4,8,16...) */
405
482 by Brian Aker
Remove uint.
406
  uint32_t          lock_position;          /* Position in DRIZZLE_LOCK.table */
407
  uint32_t          lock_data_start;        /* Start pos. in DRIZZLE_LOCK.locks */
408
  uint32_t          lock_count;             /* Number of locks */
1 by brian
clean slate
409
  uint		tablenr,used_fields;
482 by Brian Aker
Remove uint.
410
  uint32_t          temp_pool_slot;		/* Used by intern temp tables */
1 by brian
clean slate
411
  uint		status;                 /* What's in record[0] */
412
  /* number of select if it is derived table */
482 by Brian Aker
Remove uint.
413
  uint32_t          derived_select_number;
1 by brian
clean slate
414
  int		current_lock;           /* Type of lock on table */
274 by Brian Aker
my_bool conversion in Table
415
  bool copy_blobs;			/* copy_blobs when storing */
1 by brian
clean slate
416
417
  /*
418
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
419
    If maybe_null !=0, this table is inner w.r.t. some outer join operation,
420
    and null_row may be true.
421
  */
327.1.3 by Brian Aker
Cleaned up depend in Proto utils. Modified int to bool. Put TmpTable class
422
  bool maybe_null;
423
1 by brian
clean slate
424
  /*
425
    If true, the current table row is considered to have all columns set to 
426
    NULL, including columns declared as "not null" (see maybe_null).
427
  */
274 by Brian Aker
my_bool conversion in Table
428
  bool null_row;
1 by brian
clean slate
429
274 by Brian Aker
my_bool conversion in Table
430
  bool force_index;
431
  bool distinct,const_table,no_rows;
432
  bool key_read, no_keyread;
1 by brian
clean slate
433
  /*
434
    Placeholder for an open table which prevents other connections
435
    from taking name-locks on this table. Typically used with
436
    TABLE_SHARE::version member to take an exclusive name-lock on
437
    this table name -- a name lock that not only prevents other
438
    threads from opening the table, but also blocks other name
439
    locks. This is achieved by:
440
    - setting open_placeholder to 1 - this will block other name
441
      locks, as wait_for_locked_table_name will be forced to wait,
442
      see table_is_used for details.
443
    - setting version to 0 - this will force other threads to close
444
      the instance of this table and wait (this is the same approach
445
      as used for usual name locks).
446
    An exclusively name-locked table currently can have no handler
447
    object associated with it (db_stat is always 0), but please do
448
    not rely on that.
449
  */
274 by Brian Aker
my_bool conversion in Table
450
  bool open_placeholder;
451
  bool locked_by_logger;
452
  bool no_replicate;
453
  bool locked_by_name;
454
  bool no_cache;
1 by brian
clean slate
455
  /* To signal that the table is associated with a HANDLER statement */
274 by Brian Aker
my_bool conversion in Table
456
  bool open_by_handler;
1 by brian
clean slate
457
  /*
458
    To indicate that a non-null value of the auto_increment field
459
    was provided by the user or retrieved from the current record.
460
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
461
  */
274 by Brian Aker
my_bool conversion in Table
462
  bool auto_increment_field_not_null;
463
  bool insert_or_update;             /* Can be used by the handler */
464
  bool alias_name_used;		/* true if table_name is alias */
465
  bool get_fields_in_item_tree;      /* Signal to fix_field */
1 by brian
clean slate
466
467
  REGINFO reginfo;			/* field connections */
468
  MEM_ROOT mem_root;
327.2.3 by Brian Aker
Refactoring of class Table
469
  filesort_info_st sort;
1 by brian
clean slate
470
471
  bool fill_item_list(List<Item> *item_list) const;
472
  void reset_item_list(List<Item> *item_list) const;
473
  void clear_column_bitmaps(void);
474
  void prepare_for_position(void);
482 by Brian Aker
Remove uint.
475
  void mark_columns_used_by_index_no_reset(uint32_t index, MY_BITMAP *map);
476
  void mark_columns_used_by_index(uint32_t index);
1 by brian
clean slate
477
  void restore_column_maps_after_mark_index();
478
  void mark_auto_increment_column(void);
479
  void mark_columns_needed_for_update(void);
480
  void mark_columns_needed_for_delete(void);
481
  void mark_columns_needed_for_insert(void);
383.7.1 by Andrey Zhakov
Initial submit of code and tests
482
  void mark_virtual_columns(void);
1 by brian
clean slate
483
  inline void column_bitmaps_set(MY_BITMAP *read_set_arg,
484
                                 MY_BITMAP *write_set_arg)
485
  {
486
    read_set= read_set_arg;
487
    write_set= write_set_arg;
488
    if (file)
489
      file->column_bitmaps_signal();
490
  }
491
  inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg,
492
                                           MY_BITMAP *write_set_arg)
493
  {
494
    read_set= read_set_arg;
495
    write_set= write_set_arg;
496
  }
354 by Brian Aker
Refactor of Table methods.
497
498
  void restore_column_map(my_bitmap_map *old);
499
500
  my_bitmap_map *use_all_columns(MY_BITMAP *bitmap);
1 by brian
clean slate
501
  inline void use_all_columns()
502
  {
503
    column_bitmaps_set(&s->all_set, &s->all_set);
504
  }
354 by Brian Aker
Refactor of Table methods.
505
1 by brian
clean slate
506
  inline void default_column_bitmaps()
507
  {
508
    read_set= &def_read_set;
509
    write_set= &def_write_set;
510
  }
354 by Brian Aker
Refactor of Table methods.
511
1 by brian
clean slate
512
  /* Is table open or should be treated as such by name-locking? */
513
  inline bool is_name_opened() { return db_stat || open_placeholder; }
514
  /*
515
    Is this instance of the table should be reopen or represents a name-lock?
516
  */
517
  inline bool needs_reopen_or_name_lock()
518
  { return s->version != refresh_version; }
354 by Brian Aker
Refactor of Table methods.
519
520
  int report_error(int error);
1 by brian
clean slate
521
};
522
575.4.7 by Monty Taylor
More header cleanup.
523
Table *create_virtual_tmp_table(Session *session,
524
                                List<Create_field> &field_list);
525
1 by brian
clean slate
526
typedef struct st_foreign_key_info
527
{
528
  LEX_STRING *forein_id;
529
  LEX_STRING *referenced_db;
530
  LEX_STRING *referenced_table;
531
  LEX_STRING *update_method;
532
  LEX_STRING *delete_method;
533
  LEX_STRING *referenced_key_name;
534
  List<LEX_STRING> foreign_fields;
535
  List<LEX_STRING> referenced_fields;
536
} FOREIGN_KEY_INFO;
537
538
typedef struct st_field_info
539
{
540
  /** 
541
      This is used as column name. 
542
  */
543
  const char* field_name;
544
  /**
545
     For string-type columns, this is the maximum number of
546
     characters. Otherwise, it is the 'display-length' for the column.
547
  */
482 by Brian Aker
Remove uint.
548
  uint32_t field_length;
1 by brian
clean slate
549
  /**
550
     This denotes data type for the column. For the most part, there seems to
551
     be one entry in the enum for each SQL data type, although there seem to
552
     be a number of additional entries in the enum.
553
  */
554
  enum enum_field_types field_type;
555
  int value;
556
  /**
557
     This is used to set column attributes. By default, columns are @c NOT
558
     @c NULL and @c SIGNED, and you can deviate from the default
559
     by setting the appopriate flags. You can use either one of the flags
560
     @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or
561
     combine them using the bitwise or operator @c |. Both flags are
562
     defined in table.h.
563
   */
482 by Brian Aker
Remove uint.
564
  uint32_t field_flags;        // Field atributes(maybe_null, signed, unsigned etc.)
1 by brian
clean slate
565
  const char* old_name;
566
  /**
567
     This should be one of @c SKIP_OPEN_TABLE,
568
     @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
569
  */
482 by Brian Aker
Remove uint.
570
  uint32_t open_method;
1 by brian
clean slate
571
} ST_FIELD_INFO;
572
573
327.2.4 by Brian Aker
Refactoring table.h
574
class TableList;
1 by brian
clean slate
575
typedef class Item COND;
576
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
577
struct ST_SCHEMA_TABLE
1 by brian
clean slate
578
{
579
  const char* table_name;
580
  ST_FIELD_INFO *fields_info;
581
  /* Create information_schema table */
520.1.22 by Brian Aker
Second pass of thd cleanup
582
  Table *(*create_table)  (Session *session, TableList *table_list);
1 by brian
clean slate
583
  /* Fill table with data */
520.1.22 by Brian Aker
Second pass of thd cleanup
584
  int (*fill_table) (Session *session, TableList *tables, COND *cond);
1 by brian
clean slate
585
  /* Handle fileds for old SHOW */
520.1.22 by Brian Aker
Second pass of thd cleanup
586
  int (*old_format) (Session *session, struct ST_SCHEMA_TABLE *schema_table);
587
  int (*process_table) (Session *session, TableList *tables, Table *table,
1 by brian
clean slate
588
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
589
  int idx_field1, idx_field2; 
590
  bool hidden;
482 by Brian Aker
Remove uint.
591
  uint32_t i_s_requested_object;  /* the object we need to open(Table | VIEW) */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
592
};
1 by brian
clean slate
593
594
595
#define JOIN_TYPE_LEFT	1
596
#define JOIN_TYPE_RIGHT	2
597
598
struct st_lex;
599
class select_union;
600
class TMP_TABLE_PARAM;
601
602
struct Field_translator
603
{
604
  Item *item;
605
  const char *name;
606
};
607
608
609
typedef struct st_changed_table_list
610
{
611
  struct	st_changed_table_list *next;
612
  char		*key;
205 by Brian Aker
uint32 -> uin32_t
613
  uint32_t        key_length;
327.2.4 by Brian Aker
Refactoring table.h
614
} CHANGED_TableList;
1 by brian
clean slate
615
616
352 by Brian Aker
Merge of Brian's tree to main tree.
617
typedef struct st_open_table_list
618
{
1 by brian
clean slate
619
  struct st_open_table_list *next;
620
  char	*db,*table;
205 by Brian Aker
uint32 -> uin32_t
621
  uint32_t in_use,locked;
327.2.4 by Brian Aker
Refactoring table.h
622
} OPEN_TableList;
1 by brian
clean slate
623
327.2.3 by Brian Aker
Refactoring of class Table
624
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
625
inline void mark_as_null_row(Table *table)
626
{
627
  table->null_row=1;
628
  table->status|=STATUS_NULL_ROW;
629
  memset(table->null_flags, 255, table->s->null_bytes);
630
}
631
632
/**
633
  clean/setup table fields and map.
634
635
  @param table        Table structure pointer (which should be setup)
636
  @param table_list   TableList structure pointer (owner of Table)
637
  @param tablenr     table number
638
*/
639
void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr);
640
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
641
#endif /* DRIZZLED_TABLE_H */