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