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