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