~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>
1802.16.1 by Padraig O'Sullivan
Replaced one instance of MyBitmap with dynamic_bitset from boost. Added some utility functions to MyBitmap temporarily in order to accomplish this.
27
#include <boost/dynamic_bitset.hpp>
1122.2.13 by Monty Taylor
Header cleanup.
28
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
29
#include "drizzled/order.h"
30
#include "drizzled/filesort_info.h"
31
#include "drizzled/natural_join_column.h"
32
#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
33
#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.
34
#include "drizzled/lex_string.h"
35
#include "drizzled/table_list.h"
1877.2.15 by Brian Aker
Move table_share over into definition and fix header.
36
#include "drizzled/definition/table.h"
1130.3.4 by Monty Taylor
Merged in tree-wide include guard fixes and some header cleanup.
37
#include "drizzled/atomics.h"
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
38
#include "drizzled/query_id.h"
1100 by Brian Aker
Merge
39
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
40
namespace drizzled
41
{
42
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
43
class Item;
1 by brian
clean slate
44
class Item_subselect;
848 by Brian Aker
typdef class removal (just... use the name of the class).
45
class Select_Lex_Unit;
846 by Brian Aker
Removing on typedeffed class.
46
class Select_Lex;
1 by brian
clean slate
47
class COND_EQUAL;
1273.11.1 by Dennis Schoen
rename class
48
class SecurityContext;
327.2.4 by Brian Aker
Refactoring table.h
49
class TableList;
1 by brian
clean slate
50
class Field_timestamp;
51
class Field_blob;
52
1220.1.3 by Brian Aker
Remove atomic on refresh (go back to do it via lazy method).
53
extern uint64_t refresh_version;
1122.2.13 by Monty Taylor
Header cleanup.
54
1 by brian
clean slate
55
typedef enum enum_table_category TABLE_CATEGORY;
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
56
typedef struct st_columndef MI_COLUMNDEF;
1 by brian
clean slate
57
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
58
/**
59
 * Class representing a set of records, either in a temporary, 
60
 * normal, or derived table.
61
 */
62
class Table 
63
{
64
  Field **field; /**< Pointer to fields collection */
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
65
public:
66
67
  Field **getFields() const
68
  {
69
    return field;
70
  }
71
72
  Field *getField(uint32_t arg) const
73
  {
74
    return field[arg];
75
  }
76
77
  void setFields(Field **arg)
78
  {
79
    field= arg;
80
  }
81
82
  void setFieldAt(Field *arg, uint32_t arg_pos)
83
  {
84
    field[arg_pos]= arg;
85
  }
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
86
1208.3.2 by brian
Update for Cursor renaming.
87
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
1608 by Brian Aker
This encapsulates prev/next.
88
private:
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
89
  Table *next;
1608 by Brian Aker
This encapsulates prev/next.
90
public:
91
  Table *getNext() const
92
  {
93
    return next;
94
  }
95
96
  Table **getNextPtr()
97
  {
98
    return &next;
99
  }
100
101
  void setNext(Table *arg)
102
  {
103
    next= arg;
104
  }
105
1637.4.1 by Brian Aker
Wrap unused access with a class.
106
  void unlink()
107
  {
108
    getNext()->setPrev(getPrev());		/* remove from used chain */
109
    getPrev()->setNext(getNext());
110
  }
111
1608 by Brian Aker
This encapsulates prev/next.
112
private:
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
113
  Table *prev;
1608 by Brian Aker
This encapsulates prev/next.
114
public:
115
  Table *getPrev() const
116
  {
117
    return prev;
118
  }
119
120
  Table **getPrevPtr()
121
  {
122
    return &prev;
123
  }
124
125
  void setPrev(Table *arg)
126
  {
127
    prev= arg;
128
  }
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
129
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
130
  boost::dynamic_bitset<> *read_set; /* Active column sets */
131
  boost::dynamic_bitset<> *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.
132
133
  uint32_t tablenr;
1208.3.2 by brian
Update for Cursor renaming.
134
  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.
135
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
136
  boost::dynamic_bitset<> def_read_set; /**< Default read set of columns */
137
  boost::dynamic_bitset<> def_write_set; /**< Default write set of columns */
138
  boost::dynamic_bitset<> 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.
139
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.
140
  Session *in_use; /**< Pointer to the current session using this object */
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
141
  Session *getSession()
142
  {
143
    return in_use;
144
  }
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
145
1672.3.6 by Brian Aker
First pass in encapsulating row
146
  unsigned char *getInsertRecord()
147
  {
148
    return record[0];
149
  }
150
151
  unsigned char *getUpdateRecord()
152
  {
153
    return record[1];
154
  }
155
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
156
  unsigned char *record[2]; /**< Pointer to "records" */
1672.3.5 by Brian Aker
This replaces the allocation we do for insert/update.
157
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
1535 by Brian Aker
Rename of KEY to KeyInfo
158
  KeyInfo  *key_info; /**< data of keys in database */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
159
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
160
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
161
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
162
163
  TableList *pos_in_table_list; /* Element referring to this table */
1892.3.3 by tdavies
struct order_st changed and renamed to c++ class named:Order
164
  Order *group;
1669.2.6 by Brian Aker
First pass through encapsulating getAlias() from table.
165
  
166
  const char *getAlias() const
167
  {
1864.4.4 by Brian Aker
We now handle the free of the alias inside of table.
168
    return _alias.c_str();
169
  }
170
171
  void clearAlias()
172
  {
173
    _alias.clear();
174
  }
175
176
  void setAlias(const char *arg)
177
  {
178
    _alias= arg;
179
  }
180
181
private:
182
  std::string _alias; /**< alias or table name if no alias */
183
public:
1669.2.6 by Brian Aker
First pass through encapsulating getAlias() from table.
184
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
185
  unsigned char *null_flags;
1 by brian
clean slate
186
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
187
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
188
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
189
  uint32_t lock_count; /**< Number of locks */
1030.1.2 by Brian Aker
More alignment for structures
190
  uint32_t used_fields;
1672.3.6 by Brian Aker
First pass in encapsulating row
191
  uint32_t status; /* What's in getInsertRecord() */
1 by brian
clean slate
192
  /* 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.
193
  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.
194
  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.
195
  bool copy_blobs; /**< Should blobs by copied when storing? */
1 by brian
clean slate
196
197
  /*
198
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
199
    If maybe_null !=0, this table is inner w.r.t. some outer join operation,
200
    and null_row may be true.
201
  */
327.1.3 by Brian Aker
Cleaned up depend in Proto utils. Modified int to bool. Put TmpTable class
202
  bool maybe_null;
203
1 by brian
clean slate
204
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
205
    If true, the current table row is considered to have all columns set to
1 by brian
clean slate
206
    NULL, including columns declared as "not null" (see maybe_null).
207
  */
274 by Brian Aker
my_bool conversion in Table
208
  bool null_row;
1 by brian
clean slate
209
274 by Brian Aker
my_bool conversion in Table
210
  bool force_index;
1672.3.2 by Brian Aker
Tiny little cleanup around Table.
211
  bool distinct;
212
  bool const_table;
213
  bool no_rows;
1030.1.2 by Brian Aker
More alignment for structures
214
  bool key_read;
215
  bool no_keyread;
1 by brian
clean slate
216
  /*
217
    Placeholder for an open table which prevents other connections
218
    from taking name-locks on this table. Typically used with
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
219
    TableShare::version member to take an exclusive name-lock on
1 by brian
clean slate
220
    this table name -- a name lock that not only prevents other
221
    threads from opening the table, but also blocks other name
222
    locks. This is achieved by:
223
    - setting open_placeholder to 1 - this will block other name
224
      locks, as wait_for_locked_table_name will be forced to wait,
225
      see table_is_used for details.
226
    - setting version to 0 - this will force other threads to close
227
      the instance of this table and wait (this is the same approach
228
      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
229
    An exclusively name-locked table currently can have no Cursor
1 by brian
clean slate
230
    object associated with it (db_stat is always 0), but please do
231
    not rely on that.
232
  */
274 by Brian Aker
my_bool conversion in Table
233
  bool open_placeholder;
234
  bool locked_by_name;
235
  bool no_cache;
1 by brian
clean slate
236
  /*
237
    To indicate that a non-null value of the auto_increment field
238
    was provided by the user or retrieved from the current record.
239
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
240
  */
274 by Brian Aker
my_bool conversion in Table
241
  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.
242
  bool alias_name_used; /* true if table_name is alias */
1030.1.2 by Brian Aker
More alignment for structures
243
244
  /*
245
   The ID of the query that opened and is using this table. Has different
246
   meanings depending on the table type.
247
248
   Temporary tables:
249
250
   table->query_id is set to session->query_id for the duration of a statement
251
   and is reset to 0 once it is closed by the same statement. A non-zero
252
   table->query_id means that a statement is using the table even if it's
253
   not the current statement (table is in use by some outer statement).
254
255
   Non-temporary tables:
256
257
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
258
   for the duration of a statement and is reset to 0 once it is closed by
259
   the same statement. A non-zero query_id is used to control which tables
260
   in the list of pre-opened and locked tables are actually being used.
261
  */
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.
262
  query_id_t query_id;
1030.1.2 by Brian Aker
More alignment for structures
263
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.
264
  /**
265
   * Estimate of number of records that satisfy SARGable part of the table
1208.3.2 by brian
Update for Cursor renaming.
266
   * 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.
267
   * constructed.
268
   * This value is used by join optimizer as an estimate of number of records
269
   * that will pass the table condition (condition that depends on fields of
270
   * this table and constants)
271
   */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
272
  ha_rows quick_condition_rows;
1030.1.2 by Brian Aker
More alignment for structures
273
274
  /*
275
    If this table has TIMESTAMP field with auto-set property (pointed by
276
    timestamp_field member) then this variable indicates during which
277
    operations (insert only/on update/in both cases) we should set this
278
    field to current timestamp. If there are no such field in this table
279
    or we should not automatically set its value during execution of current
280
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
281
282
    Value of this variable is set for each statement in open_table() and
283
    if needed cleared later in statement processing code (see mysql_update()
284
    as example).
285
  */
286
  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.
287
  table_map map; ///< ID bit of table (1,2,4,8,16...)
1 by brian
clean slate
288
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
289
  RegInfo reginfo; /* field connections */
1030.1.2 by Brian Aker
More alignment for structures
290
291
  /*
292
    Map of keys that can be used to retrieve all data from this table
293
    needed by the query without reading the row.
294
  */
295
  key_map covering_keys;
296
  key_map quick_keys;
297
  key_map merge_keys;
298
299
  /*
300
    A set of keys that can be used in the query that references this
301
    table.
302
303
    All indexes disabled on the table's TableShare (see Table::s) will be
304
    subtracted from this set upon instantiation. Thus for any Table t it holds
305
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
306
    must not introduce any new keys here (see setup_tables).
307
308
    The set is implemented as a bitmap.
309
  */
310
  key_map keys_in_use_for_query;
311
  /* Map of keys that can be used to calculate GROUP BY without sorting */
312
  key_map keys_in_use_for_group_by;
313
  /* Map of keys that can be used to calculate ORDER BY without sorting */
314
  key_map keys_in_use_for_order_by;
315
316
  /*
317
    For each key that has quick_keys.test(key) == true: estimate of #records
318
    and max #key parts that range access would use.
319
  */
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.
320
  ha_rows quick_rows[MAX_KEY];
1030.1.2 by Brian Aker
More alignment for structures
321
322
  /* Bitmaps of key parts that =const for the entire join. */
323
  key_part_map  const_key_parts[MAX_KEY];
324
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
325
  uint32_t quick_key_parts[MAX_KEY];
326
  uint32_t quick_n_ranges[MAX_KEY];
1030.1.2 by Brian Aker
More alignment for structures
327
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
328
private:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
329
  memory::Root mem_root;
1532.1.4 by Brian Aker
Remove memset() on table, also add methods to table for allocation
330
331
  void init_mem_root()
332
  {
333
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
334
  }
335
public:
336
  memory::Root *getMemRoot()
337
  {
338
    if (not mem_root.alloc_root_inited())
339
    {
340
      init_mem_root();
341
    }
342
343
    return &mem_root;
344
  }
345
346
  void *alloc_root(size_t arg)
347
  {
348
    if (not mem_root.alloc_root_inited())
349
    {
350
      init_mem_root();
351
    }
352
353
    return mem_root.alloc_root(arg);
354
  }
355
356
  char *strmake_root(const char *str_arg, size_t len_arg)
357
  {
358
    if (not mem_root.alloc_root_inited())
359
    {
360
      init_mem_root();
361
    }
362
363
    return mem_root.strmake_root(str_arg, len_arg);
364
  }
365
1826.1.1 by tdavies
Bug:621861 Changed C structs to C++ class in the following files: filesort.cc, filesort_info.h, sql_sort.h, table.h. removed the '_st' from the name of some of the classes. For more detail of changes made read the merge proposal notes.
366
  filesort_info sort;
1 by brian
clean slate
367
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
368
  Table();
1864.4.3 by Brian Aker
Move mem_root to the destructor.
369
  virtual ~Table();
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
370
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
371
  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.
372
  /**
373
   * Free information allocated by openfrm
374
   *
375
   * @param If true if we also want to free table_share
1502.1.3 by Brian Aker
Cleanup to use references.
376
   * @note this should all be the destructor
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.
377
   */
1672.3.2 by Brian Aker
Tiny little cleanup around Table.
378
  int delete_table(bool free_share= false);
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
379
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
380
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
1030.1.2 by Brian Aker
More alignment for structures
381
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
382
  /* SHARE methods */
1859.2.10 by Brian Aker
Move all of the table bits out so that Table is an abstract class.
383
  virtual const TableShare *getShare() const= 0; /* Get rid of this long term */
384
  virtual TableShare *getMutableShare()= 0; /* Get rid of this long term */
385
  virtual bool hasShare() const= 0; /* Get rid of this long term */
386
  virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
387
1903.1.1 by Brian Aker
Merge of partial set of patches for locks.
388
  virtual void release(void)= 0;
389
1859.2.10 by Brian Aker
Move all of the table bits out so that Table is an abstract class.
390
  uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
391
  uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
392
  uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
393
  uint32_t sizeBlobFields() { return getMutableShare()->blob_fields; }
394
  uint32_t *getBlobField() { return &getMutableShare()->blob_field[0]; }
1593 by Brian Aker
Merge in Barry.
395
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
396
public:
397
  virtual bool hasVariableWidth() const
398
  {
399
    return getShare()->hasVariableWidth(); // We should calculate this.
400
  }
401
402
  virtual void setVariableWidth(void);
403
1593 by Brian Aker
Merge in Barry.
404
  Field_blob *getBlobFieldAt(uint32_t arg) const
1548.2.4 by Barry.Leslie at PrimeBase
Changed the table event observers to pass the 'Table' not the TableShare' to the observers.
405
  {
1827.2.2 by Brian Aker
Encapsulate the share in Table.
406
    if (arg < getShare()->blob_fields)
407
      return (Field_blob*) field[getShare()->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
1593 by Brian Aker
Merge in Barry.
408
409
    return NULL;
1548.2.4 by Barry.Leslie at PrimeBase
Changed the table event observers to pass the 'Table' not the TableShare' to the observers.
410
  }
1827.2.2 by Brian Aker
Encapsulate the share in Table.
411
  inline uint8_t getBlobPtrSize() { return getShare()->blob_ptr_size; }
412
  inline uint32_t getNullBytes() { return getShare()->null_bytes; }
413
  inline uint32_t getNullFields() { return getShare()->null_fields; }
414
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
415
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
416
  inline const char *getTableName()  const { return getShare()->getTableName(); }
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
417
1827.2.2 by Brian Aker
Encapsulate the share in Table.
418
  inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
419
  inline bool isNameLock() const { return getShare()->isNameLock(); }
420
  inline bool isReplaceWithNameLock() { return getShare()->replace_with_name_lock; }
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
421
1235.1.14 by Brian Aker
Final move of index flags up to Engine (new interface still needed).
422
  uint32_t index_flags(uint32_t idx) const
423
  {
1827.2.2 by Brian Aker
Encapsulate the share in Table.
424
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
1235.1.14 by Brian Aker
Final move of index flags up to Engine (new interface still needed).
425
  }
426
1455.6.1 by Yanbo Wu
convert st_foreign_key_info to class ForeignKeyInfo
427
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
1235.1.2 by Brian Aker
Added engine flag so that an engine can skip store_lock.
428
  {
1827.2.2 by Brian Aker
Encapsulate the share in Table.
429
    return getShare()->storage_engine;
1235.1.2 by Brian Aker
Added engine flag so that an engine can skip store_lock.
430
  }
431
1455.6.1 by Yanbo Wu
convert st_foreign_key_info to class ForeignKeyInfo
432
  Cursor &getCursor() const /* table_type for handler */
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
433
  {
434
    assert(cursor);
435
    return *cursor;
436
  }
437
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
438
  size_t max_row_length(const unsigned char *data);
439
  uint32_t find_shortest_key(const key_map *usable_keys);
440
  bool compare_record(Field **ptr);
441
  bool compare_record();
442
  /* TODO: the (re)storeRecord's may be able to be further condensed */
443
  void storeRecord();
444
  void storeRecordAsInsert();
445
  void storeRecordAsDefault();
446
  void restoreRecord();
447
  void restoreRecordAsDefault();
448
  void emptyRecord();
449
1908.1.1 by Brian Aker
Merge in encapsulations in filesort.
450
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
451
  /* See if this can be blown away */
452
  inline uint32_t getDBStat () { return db_stat; }
453
  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.
454
  /**
455
   * Create Item_field for each column in the table.
456
   *
457
   * @param[out] a pointer to an empty list used to store items
458
   *
459
   * @details
460
   *
461
   * Create Item_field object for each column in the table and
462
   * initialize it with the corresponding Field. New items are
463
   * created in the current Session memory root.
464
   *
465
   * @retval
466
   *  false on success
467
   * @retval
468
   *  true when out of memory
469
   */
1 by brian
clean slate
470
  bool fill_item_list(List<Item> *item_list) const;
471
  void clear_column_bitmaps(void);
472
  void prepare_for_position(void);
1802.16.1 by Padraig O'Sullivan
Replaced one instance of MyBitmap with dynamic_bitset from boost. Added some utility functions to MyBitmap temporarily in order to accomplish this.
473
  void mark_columns_used_by_index_no_reset(uint32_t index, boost::dynamic_bitset<>& bitmap);
1003.1.7 by Brian Aker
Add mark_columns_used_by_index_no_reset() with just index (assumes read_set
474
  void mark_columns_used_by_index_no_reset(uint32_t index);
482 by Brian Aker
Remove uint.
475
  void mark_columns_used_by_index(uint32_t index);
1 by brian
clean slate
476
  void restore_column_maps_after_mark_index();
477
  void mark_auto_increment_column(void);
478
  void mark_columns_needed_for_update(void);
479
  void mark_columns_needed_for_delete(void);
480
  void mark_columns_needed_for_insert(void);
1802.16.9 by Padraig O'Sullivan
Resolved bitset handling during temporary table creation. All tests pass again.
481
  void column_bitmaps_set(boost::dynamic_bitset<>& read_set_arg,
482
                          boost::dynamic_bitset<>& write_set_arg);
354 by Brian Aker
Refactor of Table methods.
483
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
484
  void restore_column_map(const boost::dynamic_bitset<>& old);
354 by Brian Aker
Refactor of Table methods.
485
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
486
  const boost::dynamic_bitset<> use_all_columns(boost::dynamic_bitset<>& map);
1 by brian
clean slate
487
  inline void use_all_columns()
488
  {
1827.2.2 by Brian Aker
Encapsulate the share in Table.
489
    column_bitmaps_set(getMutableShare()->all_set, getMutableShare()->all_set);
1 by brian
clean slate
490
  }
354 by Brian Aker
Refactor of Table methods.
491
1 by brian
clean slate
492
  inline void default_column_bitmaps()
493
  {
494
    read_set= &def_read_set;
495
    write_set= &def_write_set;
496
  }
354 by Brian Aker
Refactor of Table methods.
497
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
498
  /* Both of the below should go away once we can move this bit to the field objects */
499
  inline bool isReadSet(uint32_t index)
500
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
501
    return read_set->test(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
502
  }
503
504
  inline void setReadSet(uint32_t index)
505
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
506
    read_set->set(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
507
  }
508
1005.2.12 by Monty Taylor
Moved some things to the API.
509
  inline void setReadSet()
510
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
511
    read_set->set();
1005.2.12 by Monty Taylor
Moved some things to the API.
512
  }
513
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
514
  inline void clearReadSet(uint32_t index)
515
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
516
    read_set->reset(index);
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
517
  }
518
519
  inline void clearReadSet()
520
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
521
    read_set->reset();
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
522
  }
523
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
524
  inline bool isWriteSet(uint32_t index)
525
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
526
    return write_set->test(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
527
  }
528
529
  inline void setWriteSet(uint32_t index)
530
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
531
    write_set->set(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
532
  }
533
1005.2.12 by Monty Taylor
Moved some things to the API.
534
  inline void setWriteSet()
535
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
536
    write_set->set();
1005.2.12 by Monty Taylor
Moved some things to the API.
537
  }
538
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
539
  inline void clearWriteSet(uint32_t index)
540
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
541
    write_set->reset(index);
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
542
  }
543
544
  inline void clearWriteSet()
545
  {
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
546
    write_set->reset();
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
547
  }
548
1 by brian
clean slate
549
  /* 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.
550
  inline bool is_name_opened()
551
  {
552
    return db_stat || open_placeholder;
553
  }
1 by brian
clean slate
554
  /*
555
    Is this instance of the table should be reopen or represents a name-lock?
556
  */
557
  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.
558
  { 
1827.2.2 by Brian Aker
Encapsulate the share in Table.
559
    return getShare()->getVersion() != refresh_version;
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
560
  }
354 by Brian Aker
Refactor of Table methods.
561
934.1.1 by Brian Aker
Moved two functions in classes.
562
  /**
563
    clean/setup table fields and map.
564
565
    @param table        Table structure pointer (which should be setup)
566
    @param table_list   TableList structure pointer (owner of Table)
567
    @param tablenr     table number
568
  */
569
  void setup_table_map(TableList *table_list, uint32_t tablenr);
570
  inline void mark_as_null_row()
571
  {
1055.2.3 by Jay Pipes
Removed dead Table::table_check_intact() method.
572
    null_row= 1;
573
    status|= STATUS_NULL_ROW;
1827.2.2 by Brian Aker
Encapsulate the share in Table.
574
    memset(null_flags, 255, getShare()->null_bytes);
934.1.1 by Brian Aker
Moved two functions in classes.
575
  }
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
576
1109.1.4 by Brian Aker
More Table refactor
577
  void free_io_cache();
578
  void filesort_free_buffers(bool full= false);
579
  void intern_close_table();
1216.1.1 by Brian Aker
Move print_error up to Engine.
580
581
  void print_error(int error, myf errflag)
582
  {
1827.2.2 by Brian Aker
Encapsulate the share in Table.
583
    getShare()->storage_engine->print_error(error, errflag, *this);
1216.1.1 by Brian Aker
Move print_error up to Engine.
584
  }
585
586
  /**
587
    @return
588
    key if error because of duplicated keys
589
  */
590
  uint32_t get_dup_key(int error)
591
  {
592
    cursor->errkey  = (uint32_t) -1;
593
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
594
        error == HA_ERR_FOUND_DUPP_UNIQUE ||
595
        error == HA_ERR_DROP_INDEX_FK)
596
      cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
597
598
    return(cursor->errkey);
599
  }
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
600
601
  /*
602
    This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
603
  */
604
  bool operator<(const Table &right) const
605
  {
1415 by Brian Aker
Mass overhaul to use schema_identifier.
606
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
607
608
    if (result <  0)
609
      return true;
610
611
    if (result >  0)
612
      return false;
613
614
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
615
616
    if (result <  0)
617
      return true;
618
619
    if (result >  0)
620
      return false;
621
622
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
623
      return true;
624
625
    return false;
626
  }
627
628
  static bool compare(const Table *a, const Table *b)
629
  {
630
    return *a < *b;
631
  }
632
633
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
634
  {
1903.1.1 by Brian Aker
Merge of partial set of patches for locks.
635
    if (table.getShare())
636
    {
637
      output << "Table:(";
638
      output << table.getShare()->getSchemaName();
639
      output << ", ";
640
      output <<  table.getShare()->getTableName();
641
      output << ", ";
642
      output <<  table.getShare()->getTableTypeAsString();
643
      output << ")";
644
    }
645
    else
646
    {
647
      output << "Table:(has no share)";
648
    }
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
649
650
    return output;  // for multiple << operators.
651
  }
652
1532.1.14 by Brian Aker
We no longer use alloc for placeholders (due to HASH I didn't use a
653
public:
1843.7.2 by Brian Aker
Fix placeholder to actuall be a placeholder via methods.
654
  virtual bool isPlaceHolder(void) const
1502.1.19 by Brian Aker
Adds concept of table owned TableShare.
655
  {
1843.7.2 by Brian Aker
Fix placeholder to actuall be a placeholder via methods.
656
    return false;
1502.1.19 by Brian Aker
Adds concept of table owned TableShare.
657
  }
1 by brian
clean slate
658
};
659
1455.6.1 by Yanbo Wu
convert st_foreign_key_info to class ForeignKeyInfo
660
/**
661
 * @class
662
 *  ForeignKeyInfo
663
 *
664
 * @brief
665
 *  This class defines the information for foreign keys.
666
 */
667
class ForeignKeyInfo
1 by brian
clean slate
668
{
1455.6.1 by Yanbo Wu
convert st_foreign_key_info to class ForeignKeyInfo
669
public:
670
    /**
671
     * @brief
672
     *  This is the constructor with all properties set.
673
     *
674
     * @param[in] in_foreign_id The id of the foreign key
675
     * @param[in] in_referenced_db The referenced database name of the foreign key
676
     * @param[in] in_referenced_table The referenced table name of the foreign key
677
     * @param[in] in_update_method The update method of the foreign key.
678
     * @param[in] in_delete_method The delete method of the foreign key.
679
     * @param[in] in_referenced_key_name The name of referenced key
680
     * @param[in] in_foreign_fields The foreign fields
681
     * @param[in] in_referenced_fields The referenced fields
682
     */
683
    ForeignKeyInfo(LEX_STRING *in_foreign_id,
684
                   LEX_STRING *in_referenced_db,
685
                   LEX_STRING *in_referenced_table,
686
                   LEX_STRING *in_update_method,
687
                   LEX_STRING *in_delete_method,
688
                   LEX_STRING *in_referenced_key_name,
689
                   List<LEX_STRING> in_foreign_fields,
690
                   List<LEX_STRING> in_referenced_fields)
691
    :
692
      foreign_id(in_foreign_id),
693
      referenced_db(in_referenced_db),
694
      referenced_table(in_referenced_table),
695
      update_method(in_update_method),
696
      delete_method(in_delete_method),
697
      referenced_key_name(in_referenced_key_name),
698
      foreign_fields(in_foreign_fields),
699
      referenced_fields(in_referenced_fields)
700
    {}
701
702
    /**
703
     * @brief
704
     *  This is the default constructor. All properties are set to default values for their types.
705
     */
706
    ForeignKeyInfo()
707
    : foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
708
      update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
709
    {}
710
711
    /**
712
     * @brief
713
     *  Gets the foreign id.
714
     *
715
     * @ retval  the foreign id
716
     */
717
    const LEX_STRING *getForeignId() const
718
    {
719
        return foreign_id;
720
    }
721
722
    /**
723
     * @brief
724
     *  Gets the name of the referenced database.
725
     *
726
     * @ retval  the name of the referenced database
727
     */
728
    const LEX_STRING *getReferencedDb() const
729
    {
730
        return referenced_db;
731
    }
732
733
    /**
734
     * @brief
735
     *  Gets the name of the referenced table.
736
     *
737
     * @ retval  the name of the referenced table
738
     */
739
    const LEX_STRING *getReferencedTable() const
740
    {
741
        return referenced_table;
742
    }
743
744
    /**
745
     * @brief
746
     *  Gets the update method.
747
     *
748
     * @ retval  the update method
749
     */
750
    const LEX_STRING *getUpdateMethod() const
751
    {
752
        return update_method;
753
    }
754
755
    /**
756
     * @brief
757
     *  Gets the delete method.
758
     *
759
     * @ retval  the delete method
760
     */
761
    const LEX_STRING *getDeleteMethod() const
762
    {
763
        return delete_method;
764
    }
765
766
    /**
767
     * @brief
768
     *  Gets the name of the referenced key.
769
     *
770
     * @ retval  the name of the referenced key
771
     */
772
    const LEX_STRING *getReferencedKeyName() const
773
    {
774
        return referenced_key_name;
775
    }
776
777
    /**
778
     * @brief
779
     *  Gets the foreign fields.
780
     *
781
     * @ retval  the foreign fields
782
     */
783
    const List<LEX_STRING> &getForeignFields() const
784
    {
785
        return foreign_fields;
786
    }
787
788
    /**
789
     * @brief
790
     *  Gets the referenced fields.
791
     *
792
     * @ retval  the referenced fields
793
     */
794
    const List<LEX_STRING> &getReferencedFields() const
795
    {
796
        return referenced_fields;
797
    }
798
private:
799
    /**
800
     * The foreign id.
801
     */
802
    LEX_STRING *foreign_id;
803
    /**
804
     * The name of the reference database.
805
     */
806
    LEX_STRING *referenced_db;
807
    /**
808
     * The name of the reference table.
809
     */
810
    LEX_STRING *referenced_table;
811
    /**
812
     * The update method.
813
     */
814
    LEX_STRING *update_method;
815
    /**
816
     * The delete method.
817
     */
818
    LEX_STRING *delete_method;
819
    /**
820
     * The name of the referenced key.
821
     */
822
    LEX_STRING *referenced_key_name;
823
    /**
824
     * The foreign fields.
825
     */
826
    List<LEX_STRING> foreign_fields;
827
    /**
828
     * The referenced fields.
829
     */
830
    List<LEX_STRING> referenced_fields;
831
};
1 by brian
clean slate
832
327.2.4 by Brian Aker
Refactoring table.h
833
class TableList;
1 by brian
clean slate
834
1455.6.1 by Yanbo Wu
convert st_foreign_key_info to class ForeignKeyInfo
835
#define JOIN_TYPE_LEFT  1
836
#define JOIN_TYPE_RIGHT 2
1 by brian
clean slate
837
838
struct st_lex;
839
class select_union;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
840
class Tmp_Table_Param;
1 by brian
clean slate
841
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
842
void free_blobs(Table *table);
843
int set_zone(int nr,int min_zone,int max_zone);
844
uint32_t convert_period_to_month(uint32_t period);
845
uint32_t convert_month_to_period(uint32_t month);
846
847
int test_if_number(char *str,int *res,bool allow_wildcards);
848
void change_byte(unsigned char *,uint,char,char);
849
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
850
namespace optimizer { class SqlSelect; }
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
851
852
void change_double_for_sort(double nr,unsigned char *to);
853
double my_double_round(double value, int64_t dec, bool dec_unsigned,
854
                       bool truncate);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
855
int get_quick_record(optimizer::SqlSelect *select);
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
856
857
void find_date(char *pos,uint32_t *vek,uint32_t flag);
858
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
859
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
860
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
861
void append_unescaped(String *res, const char *pos, uint32_t length);
1241.9.15 by Monty Taylor
Moved last of the global function decls out of server_includes.h.
862
863
int rename_file_ext(const char * from,const char * to,const char * ext);
864
bool check_column_name(const char *name);
1578.4.11 by Brian Aker
PAss through the code removing current_session
865
bool check_db_name(Session *session, SchemaIdentifier &schema);
1241.9.15 by Monty Taylor
Moved last of the global function decls out of server_includes.h.
866
bool check_table_name(const char *name, uint32_t length);
867
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
868
} /* namespace drizzled */
869
1843.8.4 by Brian Aker
Committing refactor of table out (this is part of the concurrency work).
870
#include "drizzled/table/instance.h"
1843.8.5 by Brian Aker
Added concurrent type.
871
#include "drizzled/table/concurrent.h"
1843.8.3 by Brian Aker
Break out table types (first pass).
872
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
873
#endif /* DRIZZLED_TABLE_H */