~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
520.1.22 by Brian Aker
Second pass of thd cleanup
57
bool create_myisam_from_heap(Session *session, Table *table,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
58
                             MI_COLUMNDEF *start_recinfo,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
59
                             MI_COLUMNDEF **recinfo,
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
60
                             int error, bool ignore_last_dupp_key_error);
61
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
62
/**
63
 * Class representing a set of records, either in a temporary, 
64
 * normal, or derived table.
65
 */
66
class Table 
67
{
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
68
public:
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
69
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
70
  TableShare *s; /**< Pointer to the shared metadata about the table */
71
  Field **field; /**< Pointer to fields collection */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
72
1208.3.2 by brian
Update for Cursor renaming.
73
  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).
74
  Table *next;
75
  Table *prev;
76
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
77
  MyBitmap *read_set; /* Active column sets */
78
  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.
79
80
  uint32_t tablenr;
1208.3.2 by brian
Update for Cursor renaming.
81
  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.
82
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
83
  MyBitmap def_read_set; /**< Default read set of columns */
84
  MyBitmap def_write_set; /**< Default write set of columns */
85
  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.
86
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.
87
  Session *in_use; /**< Pointer to the current session using this object */
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
88
  Session *getSession()
89
  {
90
    return in_use;
91
  }
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
93
  unsigned char *record[2]; /**< Pointer to "records" */
94
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
95
  KEY  *key_info; /**< data of keys in database */
96
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
97
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
98
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
99
100
  TableList *pos_in_table_list; /* Element referring to this table */
327.2.3 by Brian Aker
Refactoring of class Table
101
  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.
102
  const char *alias; /**< alias or table name if no alias */
103
  unsigned char *null_flags;
1 by brian
clean slate
104
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 lock_position; /**< Position in DRIZZLE_LOCK.table */
106
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
107
  uint32_t lock_count; /**< Number of locks */
1030.1.2 by Brian Aker
More alignment for structures
108
  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.
109
  uint32_t status; /* What's in record[0] */
1 by brian
clean slate
110
  /* 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.
111
  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.
112
  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.
113
  bool copy_blobs; /**< Should blobs by copied when storing? */
1 by brian
clean slate
114
115
  /*
116
    0 or JOIN_TYPE_{LEFT|RIGHT}. Currently this is only compared to 0.
117
    If maybe_null !=0, this table is inner w.r.t. some outer join operation,
118
    and null_row may be true.
119
  */
327.1.3 by Brian Aker
Cleaned up depend in Proto utils. Modified int to bool. Put TmpTable class
120
  bool maybe_null;
121
1 by brian
clean slate
122
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
123
    If true, the current table row is considered to have all columns set to
1 by brian
clean slate
124
    NULL, including columns declared as "not null" (see maybe_null).
125
  */
274 by Brian Aker
my_bool conversion in Table
126
  bool null_row;
1 by brian
clean slate
127
274 by Brian Aker
my_bool conversion in Table
128
  bool force_index;
129
  bool distinct,const_table,no_rows;
1030.1.2 by Brian Aker
More alignment for structures
130
  bool key_read;
131
  bool no_keyread;
1 by brian
clean slate
132
  /*
133
    Placeholder for an open table which prevents other connections
134
    from taking name-locks on this table. Typically used with
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
135
    TableShare::version member to take an exclusive name-lock on
1 by brian
clean slate
136
    this table name -- a name lock that not only prevents other
137
    threads from opening the table, but also blocks other name
138
    locks. This is achieved by:
139
    - setting open_placeholder to 1 - this will block other name
140
      locks, as wait_for_locked_table_name will be forced to wait,
141
      see table_is_used for details.
142
    - setting version to 0 - this will force other threads to close
143
      the instance of this table and wait (this is the same approach
144
      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
145
    An exclusively name-locked table currently can have no Cursor
1 by brian
clean slate
146
    object associated with it (db_stat is always 0), but please do
147
    not rely on that.
148
  */
274 by Brian Aker
my_bool conversion in Table
149
  bool open_placeholder;
150
  bool locked_by_name;
151
  bool no_cache;
1 by brian
clean slate
152
  /*
153
    To indicate that a non-null value of the auto_increment field
154
    was provided by the user or retrieved from the current record.
155
    Used only in the MODE_NO_AUTO_VALUE_ON_ZERO mode.
156
  */
274 by Brian Aker
my_bool conversion in Table
157
  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.
158
  bool alias_name_used; /* true if table_name is alias */
1030.1.2 by Brian Aker
More alignment for structures
159
160
  /*
161
   The ID of the query that opened and is using this table. Has different
162
   meanings depending on the table type.
163
164
   Temporary tables:
165
166
   table->query_id is set to session->query_id for the duration of a statement
167
   and is reset to 0 once it is closed by the same statement. A non-zero
168
   table->query_id means that a statement is using the table even if it's
169
   not the current statement (table is in use by some outer statement).
170
171
   Non-temporary tables:
172
173
   Under pre-locked or LOCK TABLES mode: query_id is set to session->query_id
174
   for the duration of a statement and is reset to 0 once it is closed by
175
   the same statement. A non-zero query_id is used to control which tables
176
   in the list of pre-opened and locked tables are actually being used.
177
  */
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.
178
  query_id_t query_id;
1030.1.2 by Brian Aker
More alignment for structures
179
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.
180
  /**
181
   * Estimate of number of records that satisfy SARGable part of the table
1208.3.2 by brian
Update for Cursor renaming.
182
   * 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.
183
   * constructed.
184
   * This value is used by join optimizer as an estimate of number of records
185
   * that will pass the table condition (condition that depends on fields of
186
   * this table and constants)
187
   */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
188
  ha_rows quick_condition_rows;
1030.1.2 by Brian Aker
More alignment for structures
189
190
  /*
191
    If this table has TIMESTAMP field with auto-set property (pointed by
192
    timestamp_field member) then this variable indicates during which
193
    operations (insert only/on update/in both cases) we should set this
194
    field to current timestamp. If there are no such field in this table
195
    or we should not automatically set its value during execution of current
196
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
197
198
    Value of this variable is set for each statement in open_table() and
199
    if needed cleared later in statement processing code (see mysql_update()
200
    as example).
201
  */
202
  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.
203
  table_map map; ///< ID bit of table (1,2,4,8,16...)
1 by brian
clean slate
204
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
205
  RegInfo reginfo; /* field connections */
1030.1.2 by Brian Aker
More alignment for structures
206
207
  /*
208
    Map of keys that can be used to retrieve all data from this table
209
    needed by the query without reading the row.
210
  */
211
  key_map covering_keys;
212
  key_map quick_keys;
213
  key_map merge_keys;
214
215
  /*
216
    A set of keys that can be used in the query that references this
217
    table.
218
219
    All indexes disabled on the table's TableShare (see Table::s) will be
220
    subtracted from this set upon instantiation. Thus for any Table t it holds
221
    that t.keys_in_use_for_query is a subset of t.s.keys_in_use. Generally we
222
    must not introduce any new keys here (see setup_tables).
223
224
    The set is implemented as a bitmap.
225
  */
226
  key_map keys_in_use_for_query;
227
  /* Map of keys that can be used to calculate GROUP BY without sorting */
228
  key_map keys_in_use_for_group_by;
229
  /* Map of keys that can be used to calculate ORDER BY without sorting */
230
  key_map keys_in_use_for_order_by;
231
232
  /*
233
    For each key that has quick_keys.test(key) == true: estimate of #records
234
    and max #key parts that range access would use.
235
  */
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.
236
  ha_rows quick_rows[MAX_KEY];
1030.1.2 by Brian Aker
More alignment for structures
237
238
  /* Bitmaps of key parts that =const for the entire join. */
239
  key_part_map  const_key_parts[MAX_KEY];
240
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
241
  uint32_t quick_key_parts[MAX_KEY];
242
  uint32_t quick_n_ranges[MAX_KEY];
1030.1.2 by Brian Aker
More alignment for structures
243
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
244
  memory::Root mem_root;
327.2.3 by Brian Aker
Refactoring of class Table
245
  filesort_info_st sort;
1 by brian
clean slate
246
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
247
  Table();
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
248
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
249
  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.
250
  /**
251
   * Free information allocated by openfrm
252
   *
253
   * @param If true if we also want to free table_share
254
   */
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
255
  int closefrm(bool free_share);
256
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
257
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
1030.1.2 by Brian Aker
More alignment for structures
258
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
259
  /* SHARE methods */
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
260
  inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
261
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
262
  inline uint32_t sizeKeys() { return s->keys; }
263
  inline uint32_t sizeFields() { return s->fields; }
264
  inline uint32_t getRecordLength() { return s->reclength; }
265
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
266
  inline uint32_t *getBlobField() { return s->blob_field; }
267
  inline uint32_t getNullBytes() { return s->null_bytes; }
268
  inline uint32_t getNullFields() { return s->null_fields; }
269
  inline unsigned char *getDefaultValues() { return s->default_values; }
270
1055.2.2 by Jay Pipes
Cleanup of style, indentation, and documentation of Table class members. Removed 5 or 6 dead Table member variables.
271
  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).
272
  inline bool isNameLock() { return s->name_lock; }
273
  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.
274
  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).
275
1235.1.14 by Brian Aker
Final move of index flags up to Engine (new interface still needed).
276
  uint32_t index_flags(uint32_t idx) const
277
  {
278
    return s->storage_engine->index_flags(s->key_info[idx].algorithm);
279
  }
280
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
281
  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.
282
  {
283
    return s->storage_engine;
284
  }
285
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
286
  Cursor &getCursor() const	/* table_type for handler */
287
  {
288
    assert(cursor);
289
    return *cursor;
290
  }
291
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
292
  /* For TMP tables, should be pulled out as a class */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
293
  void updateCreateInfo(message::Table *table_proto);
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
294
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
295
  bool create_myisam_tmp_table(KEY *keyinfo,
296
                               MI_COLUMNDEF *start_recinfo,
297
                               MI_COLUMNDEF **recinfo,
298
                               uint64_t options);
299
  void free_tmp_table(Session *session);
300
  bool open_tmp_table();
301
  size_t max_row_length(const unsigned char *data);
302
  uint32_t find_shortest_key(const key_map *usable_keys);
303
  bool compare_record(Field **ptr);
304
  bool compare_record();
305
  /* TODO: the (re)storeRecord's may be able to be further condensed */
306
  void storeRecord();
307
  void storeRecordAsInsert();
308
  void storeRecordAsDefault();
309
  void restoreRecord();
310
  void restoreRecordAsDefault();
311
  void emptyRecord();
312
313
  /* See if this can be blown away */
314
  inline uint32_t getDBStat () { return db_stat; }
315
  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.
316
  /**
317
   * Create Item_field for each column in the table.
318
   *
319
   * @param[out] a pointer to an empty list used to store items
320
   *
321
   * @details
322
   *
323
   * Create Item_field object for each column in the table and
324
   * initialize it with the corresponding Field. New items are
325
   * created in the current Session memory root.
326
   *
327
   * @retval
328
   *  false on success
329
   * @retval
330
   *  true when out of memory
331
   */
1 by brian
clean slate
332
  bool fill_item_list(List<Item> *item_list) const;
333
  void clear_column_bitmaps(void);
334
  void prepare_for_position(void);
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
335
  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
336
  void mark_columns_used_by_index_no_reset(uint32_t index);
482 by Brian Aker
Remove uint.
337
  void mark_columns_used_by_index(uint32_t index);
1 by brian
clean slate
338
  void restore_column_maps_after_mark_index();
339
  void mark_auto_increment_column(void);
340
  void mark_columns_needed_for_update(void);
341
  void mark_columns_needed_for_delete(void);
342
  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
343
  inline void column_bitmaps_set(MyBitmap *read_set_arg,
344
                                 MyBitmap *write_set_arg)
1 by brian
clean slate
345
  {
346
    read_set= read_set_arg;
347
    write_set= write_set_arg;
348
  }
354 by Brian Aker
Refactor of Table methods.
349
1005.2.3 by Monty Taylor
Further reversion of P.
350
  void restore_column_map(my_bitmap_map *old);
354 by Brian Aker
Refactor of Table methods.
351
1103.6.2 by Padraig O'Sullivan
Removing references to MY_BITMAP throughout the code base and updating calls
352
  my_bitmap_map *use_all_columns(MyBitmap *bitmap);
1 by brian
clean slate
353
  inline void use_all_columns()
354
  {
355
    column_bitmaps_set(&s->all_set, &s->all_set);
356
  }
354 by Brian Aker
Refactor of Table methods.
357
1 by brian
clean slate
358
  inline void default_column_bitmaps()
359
  {
360
    read_set= &def_read_set;
361
    write_set= &def_write_set;
362
  }
354 by Brian Aker
Refactor of Table methods.
363
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
364
  /* Both of the below should go away once we can move this bit to the field objects */
365
  inline bool isReadSet(uint32_t index)
366
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
367
    return read_set->isBitSet(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
368
  }
369
370
  inline void setReadSet(uint32_t index)
371
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
372
    read_set->setBit(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
373
  }
374
1005.2.12 by Monty Taylor
Moved some things to the API.
375
  inline void setReadSet()
376
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
377
    read_set->setAll();
1005.2.12 by Monty Taylor
Moved some things to the API.
378
  }
379
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
380
  inline void clearReadSet(uint32_t index)
381
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
382
    read_set->clearBit(index);
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
383
  }
384
385
  inline void clearReadSet()
386
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
387
    read_set->clearAll();
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
388
  }
389
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
390
  inline bool isWriteSet(uint32_t index)
391
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
392
    return write_set->isBitSet(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
393
  }
394
395
  inline void setWriteSet(uint32_t index)
396
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
397
    write_set->setBit(index);
1003.1.12 by Brian Aker
Begin of abstract out the bitmap from direct reference.
398
  }
399
1005.2.12 by Monty Taylor
Moved some things to the API.
400
  inline void setWriteSet()
401
  {
1103.6.3 by Padraig O'Sullivan
Fixing up more calls to the old bitmap API.
402
    write_set->setAll();
1005.2.12 by Monty Taylor
Moved some things to the API.
403
  }
404
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
405
  inline void clearWriteSet(uint32_t index)
406
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
407
    write_set->clearBit(index);
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
408
  }
409
410
  inline void clearWriteSet()
411
  {
1039.5.60 by Jay Pipes
Fixes compile errors mostly due to change from plugin_registry.h to plugin/registry.h
412
    write_set->clearAll();
1039.5.42 by Jay Pipes
Splits out the previously aggregated all.test case into separate test
413
  }
414
1 by brian
clean slate
415
  /* 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.
416
  inline bool is_name_opened()
417
  {
418
    return db_stat || open_placeholder;
419
  }
1 by brian
clean slate
420
  /*
421
    Is this instance of the table should be reopen or represents a name-lock?
422
  */
423
  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.
424
  { 
425
    return s->version != refresh_version;
426
  }
354 by Brian Aker
Refactor of Table methods.
427
934.1.1 by Brian Aker
Moved two functions in classes.
428
  /**
429
    clean/setup table fields and map.
430
431
    @param table        Table structure pointer (which should be setup)
432
    @param table_list   TableList structure pointer (owner of Table)
433
    @param tablenr     table number
434
  */
435
  void setup_table_map(TableList *table_list, uint32_t tablenr);
436
  inline void mark_as_null_row()
437
  {
1055.2.3 by Jay Pipes
Removed dead Table::table_check_intact() method.
438
    null_row= 1;
439
    status|= STATUS_NULL_ROW;
934.1.1 by Brian Aker
Moved two functions in classes.
440
    memset(null_flags, 255, s->null_bytes);
441
  }
1109.1.1 by Brian Aker
Applying refactor of tmp table bits back to session. (this all needs to be
442
1371 by Brian Aker
Small corrections.
443
  bool renameAlterTemporaryTable(TableIdentifier &identifier);
1109.1.4 by Brian Aker
More Table refactor
444
  void free_io_cache();
445
  void filesort_free_buffers(bool full= false);
446
  void intern_close_table();
1216.1.1 by Brian Aker
Move print_error up to Engine.
447
448
  void print_error(int error, myf errflag)
449
  {
450
    s->storage_engine->print_error(error, errflag, *this);
451
  }
452
453
  /**
454
    @return
455
    key if error because of duplicated keys
456
  */
457
  uint32_t get_dup_key(int error)
458
  {
459
    cursor->errkey  = (uint32_t) -1;
460
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
461
        error == HA_ERR_FOUND_DUPP_UNIQUE ||
462
        error == HA_ERR_DROP_INDEX_FK)
463
      cursor->info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
464
465
    return(cursor->errkey);
466
  }
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
467
468
  /*
469
    This is a short term fix. Long term we will used the TableIdentifier to do the actual comparison.
470
  */
471
  bool operator<(const Table &right) const
472
  {
1415 by Brian Aker
Mass overhaul to use schema_identifier.
473
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
474
475
    if (result <  0)
476
      return true;
477
478
    if (result >  0)
479
      return false;
480
481
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
482
483
    if (result <  0)
484
      return true;
485
486
    if (result >  0)
487
      return false;
488
489
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
490
      return true;
491
492
    return false;
493
  }
494
495
  static bool compare(const Table *a, const Table *b)
496
  {
497
    return *a < *b;
498
  }
499
500
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
501
  {
502
    output << "Table:(";
503
    output << table.getShare()->getSchemaName();
504
    output << ", ";
505
    output <<  table.getShare()->getTableName();
506
    output << ", ";
507
    output <<  table.getShare()->getTableTypeAsString();
508
    output << ")";
509
510
    return output;  // for multiple << operators.
511
  }
512
1 by brian
clean slate
513
};
514
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
515
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
575.4.7 by Monty Taylor
More header cleanup.
516
1 by brian
clean slate
517
typedef struct st_foreign_key_info
518
{
519
  LEX_STRING *forein_id;
520
  LEX_STRING *referenced_db;
521
  LEX_STRING *referenced_table;
522
  LEX_STRING *update_method;
523
  LEX_STRING *delete_method;
524
  LEX_STRING *referenced_key_name;
525
  List<LEX_STRING> foreign_fields;
526
  List<LEX_STRING> referenced_fields;
527
} FOREIGN_KEY_INFO;
528
529
530
327.2.4 by Brian Aker
Refactoring table.h
531
class TableList;
1 by brian
clean slate
532
533
#define JOIN_TYPE_LEFT	1
534
#define JOIN_TYPE_RIGHT	2
535
536
struct st_lex;
537
class select_union;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
538
class Tmp_Table_Param;
1 by brian
clean slate
539
1093.6.2 by Brian Aker
Small optimization to make table listing simpler
540
struct open_table_list_st
352 by Brian Aker
Merge of Brian's tree to main tree.
541
{
1130.3.6 by Monty Taylor
Removed use of using namespace std; from a header.
542
  std::string	db;
543
  std::string	table;
1093.6.2 by Brian Aker
Small optimization to make table listing simpler
544
  uint32_t in_use;
545
  uint32_t locked;
546
547
  open_table_list_st() :
548
    in_use(0),
549
    locked(0)
550
  { }
551
552
};
1 by brian
clean slate
553
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
554
TableShare *alloc_table_share(TableList *table_list, char *key,
555
                               uint32_t key_length);
1372 by Brian Aker
Save on an identifier creation.
556
int open_table_def(Session& session, TableIdentifier &identifier, TableShare *share);
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
557
void open_table_error(TableShare *share, int error, int db_errno, int errarg);
558
int open_table_from_share(Session *session, TableShare *share, const char *alias,
1259.5.15 by Stewart Smith
remove the effectively dead READ_ALL and EXTRA_RECORD defines that were part of the rotting FRM corspe. This means we can remove prgflag from open_table_from_share()
559
                          uint32_t db_stat, uint32_t ha_open_flags,
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
560
                          Table *outparam);
561
void free_blobs(Table *table);
562
int set_zone(int nr,int min_zone,int max_zone);
563
uint32_t convert_period_to_month(uint32_t period);
564
uint32_t convert_month_to_period(uint32_t month);
565
566
int test_if_number(char *str,int *res,bool allow_wildcards);
567
void change_byte(unsigned char *,uint,char,char);
568
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
569
namespace optimizer { class SqlSelect; }
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
570
571
ha_rows filesort(Session *session,
572
                 Table *form,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
573
                 st_sort_field *sortorder,
574
                 uint32_t s_length,
575
                 optimizer::SqlSelect *select,
576
                 ha_rows max_rows,
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
577
                 bool sort_positions,
578
                 ha_rows *examined_rows);
579
580
void filesort_free_buffers(Table *table, bool full);
581
void change_double_for_sort(double nr,unsigned char *to);
582
double my_double_round(double value, int64_t dec, bool dec_unsigned,
583
                       bool truncate);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
584
int get_quick_record(optimizer::SqlSelect *select);
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
585
586
void find_date(char *pos,uint32_t *vek,uint32_t flag);
587
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
588
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
589
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
590
ulong next_io_size(ulong pos);
591
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.
592
593
int rename_file_ext(const char * from,const char * to,const char * ext);
594
bool check_column_name(const char *name);
1415 by Brian Aker
Mass overhaul to use schema_identifier.
595
bool check_db_name(SchemaIdentifier &schema);
1241.9.15 by Monty Taylor
Moved last of the global function decls out of server_includes.h.
596
bool check_table_name(const char *name, uint32_t length);
597
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
598
} /* namespace drizzled */
599
327.1.2 by Brian Aker
Commiting next pass of Table class cleanup.
600
#endif /* DRIZZLED_TABLE_H */