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