~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
1122.2.13 by Monty Taylor
Header cleanup.
26
#include <string>
27
28
#include "plugin/myisam/myisam.h"
29
#include "mysys/hash.h"
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
30
#include "drizzled/order.h"
31
#include "drizzled/filesort_info.h"
32
#include "drizzled/natural_join_column.h"
33
#include "drizzled/field_iterator.h"
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
34
#include "drizzled/cursor.h"
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
35
#include "drizzled/lex_string.h"
36
#include "drizzled/table_list.h"
37
#include "drizzled/table_share.h"
1130.3.4 by Monty Taylor
Merged in tree-wide include guard fixes and some header cleanup.
38
#include "drizzled/atomics.h"
1100 by Brian Aker
Merge
39
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
40
class Item;
1 by brian
clean slate
41
class Item_subselect;
848 by Brian Aker
typdef class removal (just... use the name of the class).
42
class Select_Lex_Unit;
846 by Brian Aker
Removing on typedeffed class.
43
class Select_Lex;
1 by brian
clean slate
44
class COND_EQUAL;
45
class Security_context;
327.2.4 by Brian Aker
Refactoring table.h
46
class TableList;
1 by brian
clean slate
47
class Field_timestamp;
48
class Field_blob;
49
1220.1.3 by Brian Aker
Remove atomic on refresh (go back to do it via lazy method).
50
extern uint64_t refresh_version;
1122.2.13 by Monty Taylor
Header cleanup.
51
1 by brian
clean slate
52
typedef enum enum_table_category TABLE_CATEGORY;
53
520.1.22 by Brian Aker
Second pass of thd cleanup
54
bool create_myisam_from_heap(Session *session, Table *table,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
55
                             MI_COLUMNDEF *start_recinfo,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
56
                             MI_COLUMNDEF **recinfo,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
57
                             int error, bool ignore_last_dupp_key_error);
58
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
59
/**
60
 * Class representing a set of records, either in a temporary, 
61
 * normal, or derived table.
62
 */
63
class Table 
64
{
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
65
public:
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
66
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
67
  TableShare *s; /**< Pointer to the shared metadata about the table */
68
  Field **field; /**< Pointer to fields collection */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
69
1208.3.2 by brian
Update for Cursor renaming.
70
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
71
  Table *next;
72
  Table *prev;
73
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
74
  MyBitmap *read_set; /* Active column sets */
75
  MyBitmap *write_set; /* Active column sets */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
76
77
  uint32_t tablenr;
1208.3.2 by brian
Update for Cursor renaming.
78
  uint32_t db_stat; /**< information about the cursor as in Cursor.h */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
79
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
80
  MyBitmap def_read_set; /**< Default read set of columns */
81
  MyBitmap def_write_set; /**< Default write set of columns */
82
  MyBitmap tmp_set; /* Not sure about this... */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
83
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
84
  Session *in_use; /**< Pointer to the current session using this object */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
85
86
  unsigned char *record[2]; /**< Pointer to "records" */
87
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
88
  KEY  *key_info; /**< data of keys in database */
89
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
90
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
91
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
92
93
  TableList *pos_in_table_list; /* Element referring to this table */
327.2.3 by Brian Aker
Refactoring of class Table
94
  order_st *group;
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
95
  const char *alias; /**< alias or table name if no alias */
96
  unsigned char *null_flags;
1 by brian
clean slate
97
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
98
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
99
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
100
  uint32_t lock_count; /**< Number of locks */
1030.1.2 by Brian Aker
More alignment for structures
101
  uint32_t used_fields;
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
102
  uint32_t status; /* What's in record[0] */
1 by brian
clean slate
103
  /* number of select if it is derived table */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
104
  uint32_t derived_select_number;
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
105
  int current_lock; /**< Type of lock on table */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
106
  bool copy_blobs; /**< Should blobs by copied when storing? */
1 by brian
clean slate
107
108
  /*
109
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
110
    If maybe_null !=0, this table is inner w.r.t. some outer join operation,
111
    and null_row may be true.
112
  */
327.1.3 by Brian Aker
Cleaned up depend in Proto utils. Modified int to bool. Put TmpTable class
113
  bool maybe_null;
114
1 by brian
clean slate
115
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
116
    If true, the current table row is considered to have all columns set to
1 by brian
clean slate
117
    NULL, including columns declared as "not null" (see maybe_null).
118
  */
274 by Brian Aker
my_bool conversion in Table
119
  bool null_row;
1 by brian
clean slate
120
274 by Brian Aker
my_bool conversion in Table
121
  bool force_index;
122
  bool distinct,const_table,no_rows;
1030.1.2 by Brian Aker
More alignment for structures
123
  bool key_read;
124
  bool no_keyread;
1 by brian
clean slate
125
  /*
126
    Placeholder for an open table which prevents other connections
127
    from taking name-locks on this table. Typically used with
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
128
    TableShare::version member to take an exclusive name-lock on
1 by brian
clean slate
129
    this table name -- a name lock that not only prevents other
130
    threads from opening the table, but also blocks other name
131
    locks. This is achieved by:
132
    - setting open_placeholder to 1 - this will block other name
133
      locks, as wait_for_locked_table_name will be forced to wait,
134
      see table_is_used for details.
135
    - setting version to 0 - this will force other threads to close
136
      the instance of this table and wait (this is the same approach
137
      as used for usual name locks).
1183.1.2 by Brian Aker
Rename of handler to Cursor. You would not believe how long I have wanted
138
    An exclusively name-locked table currently can have no Cursor
1 by brian
clean slate
139
    object associated with it (db_stat is always 0), but please do
140
    not rely on that.
141
  */
274 by Brian Aker
my_bool conversion in Table
142
  bool open_placeholder;
143
  bool locked_by_name;
144
  bool no_cache;
1 by brian
clean slate
145
  /*
146
    To indicate that a non-null value of the auto_increment field
147
    was provided by the user or retrieved from the current record.
148
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
149
  */
274 by Brian Aker
my_bool conversion in Table
150
  bool auto_increment_field_not_null;
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
151
  bool alias_name_used; /* true if table_name is alias */
1030.1.2 by Brian Aker
More alignment for structures
152
153
  /*
154
   The ID of the query that opened and is using this table. Has different
155
   meanings depending on the table type.
156
157
   Temporary tables:
158
159
   table->query_id is set to session->query_id for the duration of a statement
160
   and is reset to 0 once it is closed by the same statement. A non-zero
161
   table->query_id means that a statement is using the table even if it's
162
   not the current statement (table is in use by some outer statement).
163
164
   Non-temporary tables:
165
166
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
167
   for the duration of a statement and is reset to 0 once it is closed by
168
   the same statement. A non-zero query_id is used to control which tables
169
   in the list of pre-opened and locked tables are actually being used.
170
  */
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
171
  query_id_t query_id;
1030.1.2 by Brian Aker
More alignment for structures
172
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
173
  /**
174
   * Estimate of number of records that satisfy SARGable part of the table
1208.3.2 by brian
Update for Cursor renaming.
175
   * condition, or table->cursor->records if no SARGable condition could be
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
176
   * constructed.
177
   * This value is used by join optimizer as an estimate of number of records
178
   * that will pass the table condition (condition that depends on fields of
179
   * this table and constants)
180
   */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
181
  ha_rows quick_condition_rows;
1030.1.2 by Brian Aker
More alignment for structures
182
183
  /*
184
    If this table has TIMESTAMP field with auto-set property (pointed by
185
    timestamp_field member) then this variable indicates during which
186
    operations (insert only/on update/in both cases) we should set this
187
    field to current timestamp. If there are no such field in this table
188
    or we should not automatically set its value during execution of current
189
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
190
191
    Value of this variable is set for each statement in open_table() and
192
    if needed cleared later in statement processing code (see mysql_update()
193
    as example).
194
  */
195
  timestamp_auto_set_type timestamp_field_type;
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
196
  table_map map; ///< ID bit of table (1,2,4,8,16...)
1 by brian
clean slate
197
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
198
  RegInfo reginfo; /* field connections */
1030.1.2 by Brian Aker
More alignment for structures
199
200
  /*
201
    Map of keys that can be used to retrieve all data from this table
202
    needed by the query without reading the row.
203
  */
204
  key_map covering_keys;
205
  key_map quick_keys;
206
  key_map merge_keys;
207
208
  /*
209
    A set of keys that can be used in the query that references this
210
    table.
211
212
    All indexes disabled on the table's TableShare (see Table::s) will be
213
    subtracted from this set upon instantiation. Thus for any Table t it holds
214
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
215
    must not introduce any new keys here (see setup_tables).
216
217
    The set is implemented as a bitmap.
218
  */
219
  key_map keys_in_use_for_query;
220
  /* Map of keys that can be used to calculate GROUP BY without sorting */
221
  key_map keys_in_use_for_group_by;
222
  /* Map of keys that can be used to calculate ORDER BY without sorting */
223
  key_map keys_in_use_for_order_by;
224
225
  /*
226
    For each key that has quick_keys.test(key) == true: estimate of #records
227
    and max #key parts that range access would use.
228
  */
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
229
  ha_rows quick_rows[MAX_KEY];
1030.1.2 by Brian Aker
More alignment for structures
230
231
  /* Bitmaps of key parts that =const for the entire join. */
232
  key_part_map  const_key_parts[MAX_KEY];
233
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
234
  uint32_t quick_key_parts[MAX_KEY];
235
  uint32_t quick_n_ranges[MAX_KEY];
1030.1.2 by Brian Aker
More alignment for structures
236
1 by brian
clean slate
237
  MEM_ROOT mem_root;
327.2.3 by Brian Aker
Refactoring of class Table
238
  filesort_info_st sort;
1 by brian
clean slate
239
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
240
  Table() : 
241
    s(NULL), 
242
    field(NULL),
1208.3.2 by brian
Update for Cursor renaming.
243
    cursor(NULL),
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
244
    next(NULL),
245
    prev(NULL),
246
    read_set(NULL),
247
    write_set(NULL),
248
    tablenr(0),
249
    db_stat(0),
250
    in_use(NULL),
251
    insert_values(NULL),
252
    key_info(NULL),
253
    next_number_field(NULL),
254
    found_next_number_field(NULL),
255
    timestamp_field(NULL),
256
    pos_in_table_list(NULL),
257
    group(NULL),
258
    alias(NULL),
259
    null_flags(NULL),
260
    lock_position(0),
261
    lock_data_start(0),
262
    lock_count(0),
263
    used_fields(0),
264
    status(0),
265
    derived_select_number(0),
266
    current_lock(F_UNLCK),
267
    copy_blobs(false),
268
    maybe_null(false),
269
    null_row(false),
270
    force_index(false),
271
    distinct(false),
272
    const_table(false),
273
    no_rows(false),
274
    key_read(false),
275
    no_keyread(false),
276
    open_placeholder(false),
277
    locked_by_name(false),
278
    no_cache(false),
279
    auto_increment_field_not_null(false),
280
    alias_name_used(false),
281
    query_id(0), 
282
    quick_condition_rows(0),
283
    timestamp_field_type(TIMESTAMP_NO_AUTO_SET),
284
    map(0)
1039.1.10 by Brian Aker
Minor formating, change of one name to make grep easier :)
285
  {
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
286
    record[0]= (unsigned char *) 0;
287
    record[1]= (unsigned char *) 0;
1014.2.9 by Monty Taylor
Merged trunk.
288
289
    covering_keys.reset();
290
291
    quick_keys.reset();
292
    merge_keys.reset();
293
294
    keys_in_use_for_query.reset();
295
    keys_in_use_for_group_by.reset();
296
    keys_in_use_for_order_by.reset();
297
1014.2.8 by Monty Taylor
Less fail.
298
    memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
299
    memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1014.2.9 by Monty Taylor
Merged trunk.
300
1014.2.8 by Monty Taylor
Less fail.
301
    memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
302
    memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1014.2.9 by Monty Taylor
Merged trunk.
303
304
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
1014.2.8 by Monty Taylor
Less fail.
305
    memset(&sort, 0, sizeof(filesort_info_st));
306
  }
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
307
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
308
  int report_error(int error);
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
309
  /**
310
   * Free information allocated by openfrm
311
   *
312
   * @param If true if we also want to free table_share
313
   */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
314
  int closefrm(bool free_share);
315
1039.1.10 by Brian Aker
Minor formating, change of one name to make grep easier :)
316
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg)
1014.2.7 by Monty Taylor
First malloc(Table) stab (doesn't work)
317
  {
1014.2.9 by Monty Taylor
Merged trunk.
318
    s= share;
319
    field= NULL;
320
1208.3.2 by brian
Update for Cursor renaming.
321
    cursor= NULL;
1014.2.8 by Monty Taylor
Less fail.
322
    next= NULL;
323
    prev= NULL;
1014.2.9 by Monty Taylor
Merged trunk.
324
325
    read_set= NULL;
326
    write_set= NULL;
327
328
    tablenr= 0;
329
    db_stat= db_stat_arg;
330
331
    in_use= session;
1055.2.3 by Jay Pipes
Removed dead Table::table_check_intact() method.
332
    record[0]= (unsigned char *) 0;
333
    record[1]= (unsigned char *) 0;
1014.2.9 by Monty Taylor
Merged trunk.
334
1014.2.8 by Monty Taylor
Less fail.
335
    insert_values= NULL;
336
    key_info= NULL;
337
    next_number_field= NULL;
338
    found_next_number_field= NULL;
339
    timestamp_field= NULL;
1014.2.9 by Monty Taylor
Merged trunk.
340
1014.2.8 by Monty Taylor
Less fail.
341
    pos_in_table_list= NULL;
342
    group= NULL;
343
    alias= NULL;
344
    null_flags= NULL;
345
     
346
    lock_position= 0;
347
    lock_data_start= 0;
348
    lock_count= 0;
349
    used_fields= 0;
350
    status= 0;
351
    derived_select_number= 0;
352
    current_lock= F_UNLCK;
353
    copy_blobs= false;
1014.2.9 by Monty Taylor
Merged trunk.
354
1014.2.8 by Monty Taylor
Less fail.
355
    maybe_null= false;
1014.2.9 by Monty Taylor
Merged trunk.
356
1014.2.8 by Monty Taylor
Less fail.
357
    null_row= false;
1014.2.9 by Monty Taylor
Merged trunk.
358
1014.2.8 by Monty Taylor
Less fail.
359
    force_index= false;
360
    distinct= false;
361
    const_table= false;
362
    no_rows= false;
363
    key_read= false;
364
    no_keyread= false;
1014.2.9 by Monty Taylor
Merged trunk.
365
1014.2.8 by Monty Taylor
Less fail.
366
    open_placeholder= false;
367
    locked_by_name= false;
368
    no_cache= false;
1014.2.9 by Monty Taylor
Merged trunk.
369
1014.2.8 by Monty Taylor
Less fail.
370
    auto_increment_field_not_null= false;
371
    alias_name_used= false;
372
    
1014.2.9 by Monty Taylor
Merged trunk.
373
    query_id= 0;
374
    quick_condition_rows= 0;
375
     
376
    timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
377
    map= 0;
378
1014.2.10 by Monty Taylor
Made REGINFO into RegInfo and responsible for initializing itself.
379
    reginfo.reset();
1014.2.8 by Monty Taylor
Less fail.
380
1014.2.9 by Monty Taylor
Merged trunk.
381
    covering_keys.reset();
1014.2.8 by Monty Taylor
Less fail.
382
1014.2.7 by Monty Taylor
First malloc(Table) stab (doesn't work)
383
    quick_keys.reset();
1014.2.9 by Monty Taylor
Merged trunk.
384
    merge_keys.reset();
385
1014.2.7 by Monty Taylor
First malloc(Table) stab (doesn't work)
386
    keys_in_use_for_query.reset();
1014.2.9 by Monty Taylor
Merged trunk.
387
    keys_in_use_for_group_by.reset();
388
    keys_in_use_for_order_by.reset();
1014.2.7 by Monty Taylor
First malloc(Table) stab (doesn't work)
389
1014.2.8 by Monty Taylor
Less fail.
390
    memset(quick_rows, 0, sizeof(query_id_t) * MAX_KEY);
391
    memset(const_key_parts, 0, sizeof(ha_rows) * MAX_KEY);
1014.2.9 by Monty Taylor
Merged trunk.
392
1014.2.8 by Monty Taylor
Less fail.
393
    memset(quick_key_parts, 0, sizeof(unsigned int) * MAX_KEY);
394
    memset(quick_n_ranges, 0, sizeof(unsigned int) * MAX_KEY);
1014.2.9 by Monty Taylor
Merged trunk.
395
396
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
1014.2.8 by Monty Taylor
Less fail.
397
    memset(&sort, 0, sizeof(filesort_info_st));
1014.2.7 by Monty Taylor
First malloc(Table) stab (doesn't work)
398
  }
1030.1.2 by Brian Aker
More alignment for structures
399
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
400
  /* SHARE methods */
401
  inline TableShare *getShare() { return s; } /* Get rid of this long term */
402
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
403
  inline uint32_t sizeKeys() { return s->keys; }
404
  inline uint32_t sizeFields() { return s->fields; }
405
  inline uint32_t getRecordLength() { return s->reclength; }
406
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
407
  inline uint32_t *getBlobField() { return s->blob_field; }
408
  inline uint32_t getNullBytes() { return s->null_bytes; }
409
  inline uint32_t getNullFields() { return s->null_fields; }
410
  inline unsigned char *getDefaultValues() { return s->default_values; }
411
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
412
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
413
  inline bool isNameLock() { return s->name_lock; }
414
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
415
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
416
1235.1.2 by Brian Aker
Added engine flag so that an engine can skip store_lock.
417
  inline drizzled::plugin::StorageEngine *getEngine() const	/* table_type for handler */
418
  {
419
    return s->storage_engine;
420
  }
421
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
422
  /* For TMP tables, should be pulled out as a class */
1222.1.7 by Brian Aker
Remove HA_CREATE_INFO from createTable()
423
  void updateCreateInfo(drizzled::message::Table *table_proto);
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
424
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
425
  bool create_myisam_tmp_table(KEY *keyinfo,
426
                               MI_COLUMNDEF *start_recinfo,
427
                               MI_COLUMNDEF **recinfo,
428
                               uint64_t options);
429
  void free_tmp_table(Session *session);
430
  bool open_tmp_table();
431
  size_t max_row_length(const unsigned char *data);
432
  uint32_t find_shortest_key(const key_map *usable_keys);
433
  bool compare_record(Field **ptr);
434
  bool compare_record();
435
  /* TODO: the (re)storeRecord's may be able to be further condensed */
436
  void storeRecord();
437
  void storeRecordAsInsert();
438
  void storeRecordAsDefault();
439
  void restoreRecord();
440
  void restoreRecordAsDefault();
441
  void emptyRecord();
442
443
  /* See if this can be blown away */
444
  inline uint32_t getDBStat () { return db_stat; }
445
  inline uint32_t setDBStat () { return db_stat; }
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
446
  /**
447
   * Create Item_field for each column in the table.
448
   *
449
   * @param[out] a pointer to an empty list used to store items
450
   *
451
   * @details
452
   *
453
   * Create Item_field object for each column in the table and
454
   * initialize it with the corresponding Field. New items are
455
   * created in the current Session memory root.
456
   *
457
   * @retval
458
   *  false on success
459
   * @retval
460
   *  true when out of memory
461
   */
1 by brian
clean slate
462
  bool fill_item_list(List<Item> *item_list) const;
463
  void clear_column_bitmaps(void);
464
  void prepare_for_position(void);
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
465
  void mark_columns_used_by_index_no_reset(uint32_t index, MyBitmap *map);
1003.1.7 by Brian Aker
Add mark_columns_used_by_index_no_reset() with just index (assumes read_set
466
  void mark_columns_used_by_index_no_reset(uint32_t index);
482 by Brian Aker
Remove uint.
467
  void mark_columns_used_by_index(uint32_t index);
1 by brian
clean slate
468
  void restore_column_maps_after_mark_index();
469
  void mark_auto_increment_column(void);
470
  void mark_columns_needed_for_update(void);
471
  void mark_columns_needed_for_delete(void);
472
  void mark_columns_needed_for_insert(void);
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
473
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
474
                                 MyBitmap *write_set_arg)
1 by brian
clean slate
475
  {
476
    read_set= read_set_arg;
477
    write_set= write_set_arg;
478
  }
1055.2.24 by Jay Pipes
Merge with trunk and resolve conflicts.
479
  /**
480
   * Find field in table, no side effects, only purpose is to check for field
481
   * in table object and get reference to the field if found.
482
   *
483
   * @param Name of field searched for
484
   *
485
   * @retval
486
   *  0 field is not found
487
   * @retval
488
   *  non-0 pointer to field
489
   */
490
  Field *find_field_in_table_sef(const char *name);
354 by Brian Aker
Refactor of Table methods.
491
1005.2.3 by Monty Taylor
Further reversion of P.
492
  void restore_column_map(my_bitmap_map *old);
354 by Brian Aker
Refactor of Table methods.
493
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
494
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
1 by brian
clean slate
495
  inline void use_all_columns()
496
  {
497
    column_bitmaps_set(&s->all_set, &s->all_set);
498
  }
354 by Brian Aker
Refactor of Table methods.
499
1 by brian
clean slate
500
  inline void default_column_bitmaps()
501
  {
502
    read_set= &def_read_set;
503
    write_set= &def_write_set;
504
  }
354 by Brian Aker
Refactor of Table methods.
505
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
506
  /* Both of the below should go away once we can move this bit to the field objects */
507
  inline bool isReadSet(uint32_t index)
508
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
509
    return read_set->isBitSet(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
510
  }
511
512
  inline void setReadSet(uint32_t index)
513
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
514
    read_set->setBit(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
515
  }
516
1005.2.12 by Monty Taylor
Moved some things to the API.
517
  inline void setReadSet()
518
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
519
    read_set->setAll();
1005.2.12 by Monty Taylor
Moved some things to the API.
520
  }
521
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
522
  inline void clearReadSet(uint32_t index)
523
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
524
    read_set->clearBit(index);
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
525
  }
526
527
  inline void clearReadSet()
528
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
529
    read_set->clearAll();
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
530
  }
531
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
532
  inline bool isWriteSet(uint32_t index)
533
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
534
    return write_set->isBitSet(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
535
  }
536
537
  inline void setWriteSet(uint32_t index)
538
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
539
    write_set->setBit(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
540
  }
541
1005.2.12 by Monty Taylor
Moved some things to the API.
542
  inline void setWriteSet()
543
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
544
    write_set->setAll();
1005.2.12 by Monty Taylor
Moved some things to the API.
545
  }
546
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
547
  inline void clearWriteSet(uint32_t index)
548
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
549
    write_set->clearBit(index);
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
550
  }
551
552
  inline void clearWriteSet()
553
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
554
    write_set->clearAll();
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
555
  }
556
1 by brian
clean slate
557
  /* Is table open or should be treated as such by name-locking? */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
558
  inline bool is_name_opened()
559
  {
560
    return db_stat || open_placeholder;
561
  }
1 by brian
clean slate
562
  /*
563
    Is this instance of the table should be reopen or represents a name-lock?
564
  */
565
  inline bool needs_reopen_or_name_lock()
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
566
  { 
567
    return s->version != refresh_version;
568
  }
354 by Brian Aker
Refactor of Table methods.
569
934.1.1 by Brian Aker
Moved two functions in classes.
570
  /**
571
    clean/setup table fields and map.
572
573
    @param table        Table structure pointer (which should be setup)
574
    @param table_list   TableList structure pointer (owner of Table)
575
    @param tablenr     table number
576
  */
577
  void setup_table_map(TableList *table_list, uint32_t tablenr);
578
  inline void mark_as_null_row()
579
  {
1055.2.3 by Jay Pipes
Removed dead Table::table_check_intact() method.
580
    null_row= 1;
581
    status|= STATUS_NULL_ROW;
934.1.1 by Brian Aker
Moved two functions in classes.
582
    memset(null_flags, 255, s->null_bytes);
583
  }
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
584
585
  bool rename_temporary_table(const char *db, const char *table_name);
1109.1.4 by Brian Aker
More Table refactor
586
  void free_io_cache();
587
  void filesort_free_buffers(bool full= false);
588
  void intern_close_table();
1216.1.1 by Brian Aker
Move print_error up to Engine.
589
590
  void print_error(int error, myf errflag)
591
  {
592
    s->storage_engine->print_error(error, errflag, *this);
593
  }
594
595
  /**
596
    @return
597
    key if error because of duplicated keys
598
  */
599
  uint32_t get_dup_key(int error)
600
  {
601
    cursor->errkey  = (uint32_t) -1;
602
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
603
        error == HA_ERR_FOUND_DUPP_UNIQUE ||
604
        error == HA_ERR_DROP_INDEX_FK)
605
      cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
606
607
    return(cursor->errkey);
608
  }
1 by brian
clean slate
609
};
610
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
611
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
575.4.7 by Monty Taylor
More header cleanup.
612
1 by brian
clean slate
613
typedef struct st_foreign_key_info
614
{
615
  LEX_STRING *forein_id;
616
  LEX_STRING *referenced_db;
617
  LEX_STRING *referenced_table;
618
  LEX_STRING *update_method;
619
  LEX_STRING *delete_method;
620
  LEX_STRING *referenced_key_name;
621
  List<LEX_STRING> foreign_fields;
622
  List<LEX_STRING> referenced_fields;
623
} FOREIGN_KEY_INFO;
624
625
626
327.2.4 by Brian Aker
Refactoring table.h
627
class TableList;
1 by brian
clean slate
628
629
#define JOIN_TYPE_LEFT	1
630
#define JOIN_TYPE_RIGHT	2
631
632
struct st_lex;
633
class select_union;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
634
class Tmp_Table_Param;
1 by brian
clean slate
635
636
typedef struct st_changed_table_list
637
{
638
  struct	st_changed_table_list *next;
639
  char		*key;
1046.1.6 by Brian Aker
Formatting/style cleanup.
640
  uint32_t key_length;
327.2.4 by Brian Aker
Refactoring table.h
641
} CHANGED_TableList;
1 by brian
clean slate
642
1093.6.2 by Brian Aker
Small optimization to make table listing simpler
643
struct open_table_list_st
352 by Brian Aker
Merge of Brian's tree to main tree.
644
{
1130.3.6 by Monty Taylor
Removed use of using namespace std; from a header.
645
  std::string	db;
646
  std::string	table;
1093.6.2 by Brian Aker
Small optimization to make table listing simpler
647
  uint32_t in_use;
648
  uint32_t locked;
649
650
  open_table_list_st() :
651
    in_use(0),
652
    locked(0)
653
  { }
654
655
};
1 by brian
clean slate
656
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
657
#endif /* DRIZZLED_TABLE_H */