~drizzle-trunk/drizzle/development

798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
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) 2009 Sun Microsystems, Inc.
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
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
 */
20
21
/*
22
  This class is shared between different table objects. There is one
23
  instance of table share per one table in the database.
24
*/
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
25
2069.4.3 by Brian Aker
Merge in move for share to be instance.
26
#ifndef DRIZZLED_TABLE_INSTANCE_BASE_H
27
#define DRIZZLED_TABLE_INSTANCE_BASE_H
1122.2.10 by Monty Taylor
Fixed all of the include guards.
28
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
29
#include <string>
30
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
31
#include <boost/unordered_map.hpp>
1755.2.5 by Brian Aker
Move over to use boost for the locks in table_share.
32
#include <boost/thread/condition_variable.hpp>
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
33
#include <boost/dynamic_bitset.hpp>
1835.1.1 by Brian Aker
Convert the internal of our definition cache to be shared_ptr.
34
#include <boost/shared_ptr.hpp>
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
35
#include <boost/scoped_ptr.hpp>
1429.3.1 by Monty Taylor
Use unordered_map from the upcoming c++0x standard instead of a homemade
36
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
37
#include <drizzled/memory/root.h>
38
#include <drizzled/message.h>
39
#include <drizzled/util/string.h>
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
40
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
41
#include <drizzled/lex_string.h>
42
#include <drizzled/key_map.h>
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
43
 
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
44
#include <drizzled/table/cache.h>
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
45
 
46
#include <drizzled/field.h>
47
1877.2.4 by Brian Aker
Shift over to cache definition in table/cache
48
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
49
namespace drizzled
50
{
51
1903.1.1 by Brian Aker
Merge of partial set of patches for locks.
52
const static std::string NO_PROTOBUFFER_AVAILABLE("NO PROTOBUFFER AVAILABLE");
1347 by Brian Aker
Update/fix for leak.
53
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
54
namespace plugin
55
{
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
56
class EventObserverList;
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
57
class StorageEngine;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
58
}
59
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
60
namespace table {
2069.4.2 by Brian Aker
Clear up naming convention for table type.
61
class Singular;
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
62
}
63
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
64
class Field_blob;
65
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
66
class TableShare
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
67
{
1530.1.1 by Brian Aker
Removes typelib usage from fieldname
68
  typedef std::vector<std::string> StringVector;
1938.4.3 by Brian Aker
Added generator for table_definition cache. Now no one can touch the guts :)
69
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
70
public:
1938.4.1 by Brian Aker
Fix style on naming of shared_ptr for tableshare.
71
  typedef boost::shared_ptr<TableShare> shared_ptr;
1938.4.3 by Brian Aker
Added generator for table_definition cache. Now no one can touch the guts :)
72
  typedef std::vector <shared_ptr> vector;
1938.4.1 by Brian Aker
Fix style on naming of shared_ptr for tableshare.
73
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
74
  TableShare(const identifier::Table::Type type_arg);
75
76
  TableShare(const identifier::Table &identifier, const identifier::Table::Key &key); // Used by placeholder
77
78
  TableShare(const identifier::Table &identifier); // Just used during createTable()
79
80
  TableShare(const identifier::Table::Type type_arg,
81
             const identifier::Table &identifier,
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
82
             char *path_arg= NULL, uint32_t path_length_arg= 0); // Shares for cache
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
83
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
84
  virtual ~TableShare();
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
85
1502.1.23 by Brian Aker
Some encapsulation.
86
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
87
  /** Category of this table. */
88
  enum_table_category table_category;
89
1502.1.23 by Brian Aker
Some encapsulation.
90
public:
91
  bool isTemporaryCategory() const
92
  {
93
    return (table_category == TABLE_CATEGORY_TEMPORARY);
94
  }
95
96
  void setTableCategory(enum_table_category arg)
97
  {
98
    table_category= arg;
99
  }
1030.1.3 by Brian Aker
Final bits to structure alignment
100
101
  /* The following is copied to each Table on OPEN */
1578.2.14 by Brian Aker
Additional pass through to remove raw field access.
102
  typedef std::vector<Field *> Fields;
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
103
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
104
private:
2040.4.1 by Brian Aker
Update to time and field.
105
  Fields _fields;
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
106
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
107
public:
1591 by Brian Aker
Small bits of field abstraction.
108
  const Fields getFields() const
1578.2.14 by Brian Aker
Additional pass through to remove raw field access.
109
  {
2040.4.1 by Brian Aker
Update to time and field.
110
    return _fields;
111
  }
112
113
  Fields getFields()
114
  {
115
    return _fields;
1578.2.14 by Brian Aker
Additional pass through to remove raw field access.
116
  }
117
118
  Field ** getFields(bool)
1502.1.23 by Brian Aker
Some encapsulation.
119
  {
2040.4.1 by Brian Aker
Update to time and field.
120
    return &_fields[0];
1502.1.23 by Brian Aker
Some encapsulation.
121
  }
122
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
123
  void setFields(uint32_t arg)
124
  {
2040.4.1 by Brian Aker
Update to time and field.
125
    _fields.resize(arg);
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
126
  }
127
1578.2.15 by Brian Aker
Merge of additions to Field abstraction.
128
  uint32_t positionFields(Field **arg) const
129
  {
2040.4.1 by Brian Aker
Update to time and field.
130
    return (arg - (Field **)&_fields[0]);
1578.2.15 by Brian Aker
Merge of additions to Field abstraction.
131
  }
132
133
  void pushField(Field *arg)
134
  {
2040.4.1 by Brian Aker
Update to time and field.
135
    _field_size++;
136
    _fields.push_back(arg);
1578.2.15 by Brian Aker
Merge of additions to Field abstraction.
137
  }
138
1030.1.3 by Brian Aker
Final bits to structure alignment
139
  Field **found_next_number_field;
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
140
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
141
private:
1030.1.3 by Brian Aker
Final bits to structure alignment
142
  Field *timestamp_field;               /* Used only during open */
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
143
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
144
public:
145
146
  Field *getTimestampField() const               /* Used only during open */
147
  {
148
    return timestamp_field;
149
  }
150
151
  void setTimestampField(Field *arg) /* Used only during open */
152
  {
153
    timestamp_field= arg;
154
  }
155
156
1574.1.3 by Brian Aker
Encapsulate Key info in share.
157
private:
1535 by Brian Aker
Rename of KEY to KeyInfo
158
  KeyInfo  *key_info;			/* data of keys in database */
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
159
1574.1.3 by Brian Aker
Encapsulate Key info in share.
160
public:
1574.1.4 by Brian Aker
Furthere encapsulation for TableShare.
161
  KeyInfo &getKeyInfo(uint32_t arg) const
1574.1.3 by Brian Aker
Encapsulate Key info in share.
162
  {
163
    return key_info[arg];
164
  }
1574.1.8 by Brian Aker
Blob now allocated via vector
165
  std::vector<uint>	blob_field;			/* Index to blobs in Field arrray*/
1030.1.3 by Brian Aker
Final bits to structure alignment
166
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
167
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
168
  /* hash of field names (contains pointers to elements of field array) */
1669.3.4 by Brian Aker
Fix up a few additional cases around case insensitive usage for
169
  typedef boost::unordered_map < std::string, Field **, util::insensitive_hash, util::insensitive_equal_to> FieldMap;
1669.3.1 by Brian Aker
Remove usage of my_hash in table_share.
170
  typedef std::pair< std::string, Field ** > FieldMapPair;
171
  FieldMap name_hash; /* hash of field names */
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
172
1669.3.1 by Brian Aker
Remove usage of my_hash in table_share.
173
public:
174
  size_t getNamedFieldSize() const
175
  {
176
    return name_hash.size();
177
  }
178
179
  Field **getNamedField(const std::string &arg)
180
  {
181
    FieldMap::iterator iter= name_hash.find(arg);
182
183
    if (iter == name_hash.end())
184
        return 0;
185
186
    return (*iter).second;
187
  }
188
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
189
private:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
190
  memory::Root mem_root;
1904.1.3 by Brian Aker
Additional private bits in tableshare.
191
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
192
  void *alloc_root(size_t arg)
193
  {
194
    return mem_root.alloc_root(arg);
195
  }
196
197
  char *strmake_root(const char *str_arg, size_t len_arg)
198
  {
199
    return mem_root.strmake_root(str_arg, len_arg);
200
  }
201
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
202
  memory::Root *getMemRoot()
203
  {
204
    return &mem_root;
205
  }
206
1527.1.3 by Brian Aker
This is:
207
  std::vector<std::string> _keynames;
208
209
  void addKeyName(std::string arg)
210
  {
211
    std::transform(arg.begin(), arg.end(),
212
                   arg.begin(), ::toupper);
213
    _keynames.push_back(arg);
214
  }
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
215
1527.1.3 by Brian Aker
This is:
216
public:
1574 by Brian Aker
Rollup patch for hiding tableshare.
217
  bool doesKeyNameExist(const char *name_arg, uint32_t name_length, uint32_t &position) const
1527.1.3 by Brian Aker
This is:
218
  {
1861.4.1 by Brian Aker
Cut down logic on finding if the key is valid.
219
    return doesKeyNameExist(std::string(name_arg, name_length), position);
1527.1.3 by Brian Aker
This is:
220
  }
221
1574 by Brian Aker
Rollup patch for hiding tableshare.
222
  bool doesKeyNameExist(std::string arg, uint32_t &position) const
1527.1.4 by Brian Aker
Second pass to remove keynames typelib.
223
  {
224
    std::transform(arg.begin(), arg.end(),
225
                   arg.begin(), ::toupper);
226
1574 by Brian Aker
Rollup patch for hiding tableshare.
227
    std::vector<std::string>::const_iterator iter= std::find(_keynames.begin(), _keynames.end(), arg);
1527.1.4 by Brian Aker
Second pass to remove keynames typelib.
228
229
    if (iter == _keynames.end())
230
    {
1816.2.3 by Monty Taylor
Fixed some more ICC warnings. How did I get started on this this morning?
231
      position= UINT32_MAX; //historical, required for finding primary key from unique
1527.1.4 by Brian Aker
Second pass to remove keynames typelib.
232
      return false;
233
    }
234
235
    position= iter -  _keynames.begin();
236
237
    return true;
238
  }
239
1530.1.1 by Brian Aker
Removes typelib usage from fieldname
240
private:
1574.1.7 by Brian Aker
Remove interval allocation via memroot.
241
  std::vector<TYPELIB> intervals;			/* pointer to interval info */
1530.1.1 by Brian Aker
Removes typelib usage from fieldname
242
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
243
public:
244
  virtual void lock()
245
  { }
246
247
  virtual void unlock()
248
  { }
249
250
private:
1574 by Brian Aker
Rollup patch for hiding tableshare.
251
  std::vector<unsigned char> default_values;		/* row with default values */
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
252
1574 by Brian Aker
Rollup patch for hiding tableshare.
253
public:
1835.1.5 by Brian Aker
Cleans up some spots where we were using mutable but did not need too.
254
  // @note This needs to be made to be const in the future
255
  unsigned char *getDefaultValues()
1574 by Brian Aker
Rollup patch for hiding tableshare.
256
  {
257
    return &default_values[0];
258
  }
259
  void resizeDefaultValues(size_t arg)
260
  {
261
    default_values.resize(arg);
262
  }
263
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
264
  const charset_info_st *table_charset; /* Default charset of string fields */
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
265
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
266
  boost::dynamic_bitset<> all_set;
1574.1.5 by Brian Aker
Additional removal of mybitmap to being more C++
267
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
268
  /*
269
    Key which is used for looking-up table in table cache and in the list
270
    of thread's temporary tables. Has the form of:
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
271
    "database_name\0table_name\0" + optional part for temporary tables.
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
272
273
    Note that all three 'table_cache_key', 'db' and 'table_name' members
274
    must be set (and be non-zero) for tables in table cache. They also
275
    should correspond to each other.
276
    To ensure this one can use set_table_cache() methods.
277
  */
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
278
private:
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
279
  identifier::Table::Key private_key_for_cache; // This will not exist in the final design.
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
280
  std::vector<char> private_normalized_path; // This will not exist in the final design.
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
281
  LEX_STRING db;                        /* Pointer to db */
282
  LEX_STRING table_name;                /* Table name (for open) */
1259.5.7 by Stewart Smith
remove references to FRM in comments around tableshare
283
  LEX_STRING path;	/* Path to table (from datadir) */
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
284
  LEX_STRING normalized_path;		/* unpack_filename(path) */
2134.1.3 by Brian Aker
Fix init/warnings for Table
285
1502.1.9 by Brian Aker
More encapsulation.
286
public:
287
1578.2.2 by Brian Aker
Const'ize TableShare methods (first pass, not completed)
288
  const char *getNormalizedPath() const
1502.1.9 by Brian Aker
More encapsulation.
289
  {
290
    return normalized_path.str;
291
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
292
1578.2.2 by Brian Aker
Const'ize TableShare methods (first pass, not completed)
293
  const char *getPath() const
1502.1.7 by Brian Aker
Partial encapsulation of table_share
294
  {
295
    return path.str;
296
  }
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
297
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
298
  const identifier::Table::Key& getCacheKey() const // This should never be called when we aren't looking at a cache.
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
299
  {
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
300
    assert(private_key_for_cache.size());
1619.1.1 by Brian Aker
Update for TableShare usage of key (remove a case where we had to build it).
301
    return private_key_for_cache;
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
302
  }
303
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
304
  size_t getCacheKeySize() const
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
305
  {
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
306
    return private_key_for_cache.size();
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
307
  }
308
1904.1.2 by Brian Aker
Make private portions of TableShare
309
private:
1502.1.7 by Brian Aker
Partial encapsulation of table_share
310
  void setPath(char *str_arg, uint32_t size_arg)
311
  {
312
    path.str= str_arg;
313
    path.length= size_arg;
314
  }
315
1502.1.9 by Brian Aker
More encapsulation.
316
  void setNormalizedPath(char *str_arg, uint32_t size_arg)
317
  {
318
    normalized_path.str= str_arg;
319
    normalized_path.length= size_arg;
320
  }
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
321
1904.1.2 by Brian Aker
Make private portions of TableShare
322
public:
1502.1.9 by Brian Aker
More encapsulation.
323
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
324
  const char *getTableName() const
325
  {
326
    return table_name.str;
327
  }
328
1502.1.10 by Brian Aker
Encapsulate table name in TableShare.
329
  uint32_t getTableNameSize() const
330
  {
331
    return table_name.length;
332
  }
333
1347 by Brian Aker
Update/fix for leak.
334
  const std::string &getTableName(std::string &name_arg) const
335
  {
336
    name_arg.clear();
337
    name_arg.append(table_name.str, table_name.length);
338
339
    return name_arg;
340
  }
341
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
342
  const char *getSchemaName() const
343
  {
344
    return db.str;
345
  }
346
1346 by Brian Aker
Solve non-null termination issue.
347
  const std::string &getSchemaName(std::string &schema_name_arg) const
348
  {
349
    schema_name_arg.clear();
350
    schema_name_arg.append(db.str, db.length);
351
352
    return schema_name_arg;
353
  }
354
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
355
  uint32_t   block_size;                   /* create information */
1340.1.2 by Brian Aker
Merge of table cache/def DD.
356
1578.2.3 by Brian Aker
Take version and encapsulate it in TableShare
357
private:
1223.2.1 by Trond Norbye
Bug #485658: Compile failure on 32 bit system due to mixing ulong, uint64_t and uint32_t
358
  uint64_t   version;
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
359
1578.2.3 by Brian Aker
Take version and encapsulate it in TableShare
360
public:
1578.2.2 by Brian Aker
Const'ize TableShare methods (first pass, not completed)
361
  uint64_t getVersion() const
1340.1.2 by Brian Aker
Merge of table cache/def DD.
362
  {
363
    return version;
364
  }
365
2148.7.11 by Brian Aker
Remove some of the dependencies from session.h so that we make the include
366
  void refreshVersion();
1578.2.3 by Brian Aker
Take version and encapsulate it in TableShare
367
368
  void resetVersion()
369
  {
370
    version= 0;
371
  }
372
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
373
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
374
  uint32_t   timestamp_offset;		/* Set to offset+1 of record */
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
375
2134.1.4 by Brian Aker
Simple encapsulation for table.
376
  uint32_t reclength;			/* Recordlength */
377
  uint32_t stored_rec_length;         /* Stored record length*/
378
1578.2.8 by Brian Aker
Encapsulate record length.
379
public:
2134.1.4 by Brian Aker
Simple encapsulation for table.
380
  uint32_t sizeStoredRecord() const
381
  {
382
    return stored_rec_length;
383
  }
1030.1.3 by Brian Aker
Final bits to structure alignment
384
1578.2.8 by Brian Aker
Encapsulate record length.
385
  uint32_t getRecordLength() const
1320.1.17 by Brian Aker
New code for a show temporary tables;
386
  {
387
    return reclength;
388
  }
389
1578.2.8 by Brian Aker
Encapsulate record length.
390
  void setRecordLength(uint32_t arg)
391
  {
392
    reclength= arg;
393
  }
394
1593 by Brian Aker
Merge in Barry.
395
  const Field_blob *getBlobFieldAt(uint32_t arg) const
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
396
  {
1593 by Brian Aker
Merge in Barry.
397
    if (arg < blob_fields)
2040.4.1 by Brian Aker
Update to time and field.
398
      return (Field_blob*) _fields[blob_field[arg]];
1593 by Brian Aker
Merge in Barry.
399
400
    return NULL;
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
401
  }
1589.1.1 by Barry.Leslie at PrimeBase
Changed the table event observers to pass the 'Table' not the TableShare' to the observers.
402
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
403
private:
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
404
  /* Max rows is a hint to HEAP during a create tmp table */
405
  uint64_t max_rows;
406
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
407
  boost::scoped_ptr<message::Table> _table_message;
2134.1.4 by Brian Aker
Simple encapsulation for table.
408
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
409
public:
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
410
  /*
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
411
    @note Without a _table_message, we assume we are building a STANDARD table.
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
412
    This will be modified once we use Identifiers in the Share itself.
413
  */
414
  message::Table::TableType getTableType() const
415
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
416
    return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
417
  }
418
1347 by Brian Aker
Update/fix for leak.
419
  const std::string &getTableTypeAsString() const
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
420
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
421
    if (getTableMessage())
2134.1.7 by Brian Aker
Collapse strings used for table.
422
      return message::type(getTableMessage()->type());
423
424
    return NO_PROTOBUFFER_AVAILABLE;
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
425
  }
426
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
427
  /* This is only used in one location currently */
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
428
  inline message::Table *getTableMessage() const
1273.19.10 by Brian Aker
Add support for listing temporay tables from show commands.
429
  {
2134.1.8 by Brian Aker
Switch to scoped_ptr for the table message.
430
    return _table_message.get();
1273.19.10 by Brian Aker
Add support for listing temporay tables from show commands.
431
  }
432
2134.1.9 by Brian Aker
Merge in singular (to be be used with temp tables).
433
  void setTableMessage(const message::Table &arg)
434
  {
435
    assert(not getTableMessage());
436
    _table_message.reset(new(std::nothrow) message::Table(arg));
437
  }
438
2040.4.1 by Brian Aker
Update to time and field.
439
  const message::Table::Field &field(int32_t field_position) const
440
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
441
    assert(getTableMessage());
442
    return getTableMessage()->field(field_position);
2040.4.1 by Brian Aker
Update to time and field.
443
  }
444
1574 by Brian Aker
Rollup patch for hiding tableshare.
445
  inline bool hasComment() const
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
446
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
447
    return (getTableMessage()) ?  getTableMessage()->options().has_comment() : false; 
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
448
  }
449
450
  inline const char *getComment()
451
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
452
    return (getTableMessage() && getTableMessage()->has_options()) ?  getTableMessage()->options().comment().c_str() : NULL; 
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
453
  }
454
1574 by Brian Aker
Rollup patch for hiding tableshare.
455
  inline uint32_t getCommentLength() const
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
456
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
457
    return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0; 
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
458
  }
459
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
460
  inline uint64_t getMaxRows() const
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
461
  {
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
462
    return max_rows;
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
463
  }
464
465
  inline void setMaxRows(uint64_t arg)
466
  {
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
467
    max_rows= arg;
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
468
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
469
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
470
  /**
471
   * Returns true if the supplied Field object
472
   * is part of the table's primary key.
1530.1.3 by Brian Aker
Style cleanup for table_share
473
 */
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
474
  bool fieldInPrimaryKey(Field *field) const;
475
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
476
  plugin::StorageEngine *storage_engine;			/* storage engine plugin */
477
  inline plugin::StorageEngine *db_type() const	/* table_type for handler */
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
478
  {
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
479
    return storage_engine;
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
480
  }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
481
  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.
482
  {
483
    return storage_engine;
484
  }
1395.1.9 by Brian Aker
Small cleanup around how we do types internally.
485
1608.2.3 by Brian Aker
Encapsulate type for TableShare.
486
private:
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
487
  identifier::Table::Type tmp_table;
1608.2.3 by Brian Aker
Encapsulate type for TableShare.
488
public:
489
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
490
  identifier::Table::Type getType() const
1608.2.3 by Brian Aker
Encapsulate type for TableShare.
491
  {
492
    return tmp_table;
493
  }
494
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
495
private:
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
496
  uint32_t _ref_count;       /* How many Table objects uses this */
1877.2.9 by Brian Aker
Adding cache.h for definition.
497
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
498
public:
499
  uint32_t getTableCount() const
1340.1.2 by Brian Aker
Merge of table cache/def DD.
500
  {
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
501
    return _ref_count;
1340.1.2 by Brian Aker
Merge of table cache/def DD.
502
  }
503
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
504
  void incrementTableCount()
505
  {
1685.2.16 by Brian Aker
Merge in change such that the lock for share is now private (including methods).
506
    lock();
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
507
    _ref_count++;
1685.2.16 by Brian Aker
Merge in change such that the lock for share is now private (including methods).
508
    unlock();
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
509
  }
510
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
511
  uint32_t decrementTableCount()
512
  {
513
    return --_ref_count;
514
  }
515
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
516
  uint32_t null_bytes;
517
  uint32_t last_null_bit_pos;
2040.4.1 by Brian Aker
Update to time and field.
518
private:
519
  uint32_t _field_size;				/* Number of fields */
520
521
public:
522
  void setFieldSize(uint32_t arg)
523
  {
524
    _field_size= arg;
525
  }
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
526
527
  uint32_t sizeFields() const
528
  {
2040.4.1 by Brian Aker
Update to time and field.
529
    return _field_size;
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
530
  }
531
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
532
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
533
  uint32_t keys;
534
535
  uint32_t sizeKeys() const
536
  {
537
    return keys;
538
  }
539
  uint32_t key_parts;
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
540
  uint32_t max_key_length, max_unique_length, total_key_length;
541
  uint32_t uniques;                         /* Number of UNIQUE index */
542
  uint32_t null_fields;			/* number of null fields */
543
  uint32_t blob_fields;			/* number of blob fields */
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
544
private:
545
  bool has_variable_width;                  /* number of varchar fields */
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
546
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
547
public:
548
  bool hasVariableWidth() const
549
  {
550
    return has_variable_width; // We should calculate this.
551
  }
552
  void setVariableWidth()
553
  {
554
    has_variable_width= true;
555
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
556
  uint32_t db_create_options;		/* Create options from database */
557
  uint32_t db_options_in_use;		/* Options in use */
558
  uint32_t db_record_offset;		/* if HA_REC_IN_SEQ */
559
  uint32_t rowid_field_offset;		/* Field_nr +1 to rowid field */
1143.2.21 by Jay Pipes
Fixes Bug 440141 - Replication stream contains incorrect key field information for UPDATE statements.
560
  /**
561
   * @TODO 
562
   *
563
   * Currently the replication services component uses
564
   * the primary_key member to determine which field is the table's
565
   * primary key.  However, as it exists, because this member is scalar, it
566
   * only supports a single-column primary key. Is there a better way
567
   * to ask for the fields which are in a primary key?
1530.1.3 by Brian Aker
Style cleanup for table_share
568
 */
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
569
private:
1143.2.21 by Jay Pipes
Fixes Bug 440141 - Replication stream contains incorrect key field information for UPDATE statements.
570
  uint32_t primary_key;
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
571
public:
572
573
  uint32_t getPrimaryKey() const
574
  {
575
    return primary_key;
576
  }
577
578
  bool hasPrimaryKey() const
579
  {
580
    return primary_key != MAX_KEY;
581
  }
582
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
583
  /* Index of auto-updated TIMESTAMP field in field array */
584
  uint32_t next_number_index;               /* autoincrement key number */
585
  uint32_t next_number_key_offset;          /* autoinc keypart offset in a key */
586
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
587
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
588
2134.1.4 by Brian Aker
Simple encapsulation for table.
589
private:
1039.1.9 by Brian Aker
Partial Refactor of TableShare
590
  uint8_t blob_ptr_size;			/* 4 or 8 */
2134.1.4 by Brian Aker
Simple encapsulation for table.
591
592
public:
593
  uint8_t sizeBlobPtr() const
594
  {
595
    return blob_ptr_size;
596
  }
597
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
598
  bool db_low_byte_first;		/* Portable row format */
1340.1.2 by Brian Aker
Merge of table cache/def DD.
599
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
600
  /*
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
601
    Set of keys in use, implemented as a Bitmap.
602
    Excludes keys disabled by ALTER Table ... DISABLE KEYS.
1030.1.3 by Brian Aker
Final bits to structure alignment
603
  */
604
  key_map keys_in_use;
605
  key_map keys_for_keyread;
606
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
607
  /* 
608
    event_observers is a class containing all the event plugins that have 
609
    registered an interest in this table.
610
  */
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
611
  virtual plugin::EventObserverList *getTableObservers() 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
612
  { 
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
613
    return NULL;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
614
  }
615
  
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
616
  virtual void setTableObservers(plugin::EventObserverList *) 
617
  { }
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
618
  
1030.1.3 by Brian Aker
Final bits to structure alignment
619
  /*
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
620
    Set share's identifier information.
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
621
622
    SYNOPSIS
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
623
    setIdentifier()
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
624
625
    NOTES
626
  */
627
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
628
  void setIdentifier(const identifier::Table &identifier_arg);
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
629
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
630
  /*
631
    Initialize share for temporary tables
632
633
    SYNOPSIS
1000.1.5 by Brian Aker
More refactoring back to TableShare object.
634
    init()
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
635
    share	Share to fill
636
    key		Table_cache_key, as generated from create_table_def_key.
637
    must start with db name.
638
    key_length	Length of key
639
    table_name	Table name
1259.5.7 by Stewart Smith
remove references to FRM in comments around tableshare
640
    path	Path to table (possible in lower case)
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
641
642
    NOTES
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
643
    
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
644
  */
645
1578.2.1 by Brian Aker
Make init() methods private in TableShare.
646
private:
1000.1.5 by Brian Aker
More refactoring back to TableShare object.
647
  void init(const char *new_table_name,
1608.2.2 by Brian Aker
Move constructors to .cc file.
648
            const char *new_path);
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
649
2140.1.7 by Brian Aker
Hide open_table_error() from interface.
650
protected:
1039.1.9 by Brian Aker
Partial Refactor of TableShare
651
  void open_table_error(int pass_error, int db_errno, int pass_errarg);
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
652
2140.1.7 by Brian Aker
Hide open_table_error() from interface.
653
public:
654
1938.4.1 by Brian Aker
Fix style on naming of shared_ptr for tableshare.
655
  static TableShare::shared_ptr getShareCreate(Session *session, 
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
656
                                               const identifier::Table &identifier,
1938.4.4 by Brian Aker
Remove dead getShare() call which should have been a call on the cache
657
                                               int &error);
1395.1.14 by Brian Aker
Fix for Innodb dfe files.
658
659
  friend std::ostream& operator<<(std::ostream& output, const TableShare &share)
660
  {
661
    output << "TableShare:(";
662
    output <<  share.getSchemaName();
663
    output << ", ";
664
    output << share.getTableName();
665
    output << ", ";
666
    output << share.getTableTypeAsString();
667
    output << ", ";
668
    output << share.getPath();
669
    output << ")";
670
671
    return output;  // for multiple << operators.
672
  }
1502.1.12 by Brian Aker
Second pass through TableShare to new(). Partial hack in using bool for the
673
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
674
protected:
2069.4.2 by Brian Aker
Clear up naming convention for table type.
675
  friend class drizzled::table::Singular;
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
676
2040.4.1 by Brian Aker
Update to time and field.
677
  Field *make_field(const message::Table::Field &pfield,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
678
                    unsigned char *ptr,
679
                    uint32_t field_length,
680
                    bool is_nullable,
681
                    unsigned char *null_pos,
682
                    unsigned char null_bit,
683
                    uint8_t decimals,
684
                    enum_field_types field_type,
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
685
                    const charset_info_st * field_charset,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
686
                    Field::utype unireg_check,
687
                    TYPELIB *interval,
688
                    const char *field_name);
689
2040.4.1 by Brian Aker
Update to time and field.
690
  Field *make_field(const message::Table::Field &pfield,
691
                    unsigned char *ptr,
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
692
                    uint32_t field_length,
693
                    bool is_nullable,
694
                    unsigned char *null_pos,
695
                    unsigned char null_bit,
696
                    uint8_t decimals,
697
                    enum_field_types field_type,
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
698
                    const charset_info_st * field_charset,
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
699
                    Field::utype unireg_check,
700
                    TYPELIB *interval,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
701
                    const char *field_name, 
702
                    bool is_unsigned);
1502.1.24 by Brian Aker
Absorb TableShare proto to share methods.
703
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
704
public:
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
705
  int open_table_def(Session& session, const identifier::Table &identifier);
1502.1.24 by Brian Aker
Absorb TableShare proto to share methods.
706
1626.3.2 by Brian Aker
Cleanup table_share to pass in identifier.
707
  int open_table_from_share(Session *session,
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
708
                            const identifier::Table &identifier,
1626.3.2 by Brian Aker
Cleanup table_share to pass in identifier.
709
                            const char *alias,
1502.1.24 by Brian Aker
Absorb TableShare proto to share methods.
710
                            uint32_t db_stat, uint32_t ha_open_flags,
711
                            Table &outparam);
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
712
private:
713
  int open_table_from_share_inner(Session *session,
714
                                  const char *alias,
1864.4.1 by Brian Aker
Move share creation into temporary table (there still exists and issue with
715
                                  uint32_t db_stat,
716
                                  Table &outparam);
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
717
  int open_table_cursor_inner(const identifier::Table &identifier,
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
718
                              uint32_t db_stat, uint32_t ha_open_flags,
719
                              Table &outparam,
720
                              bool &error_reported);
721
public:
2140.1.6 by Brian Aker
Simplify parse_table_proto
722
  bool parse_table_proto(Session& session, message::Table &table);
2168.3.2 by Brian Aker
CREATE TABLE/SCHEMA now allow you to add REPLICATION to the list of items
723
2187.7.5 by Brian Aker
Merge in modifications such that we check both schema and table for
724
  virtual bool is_replicated() const
2168.3.2 by Brian Aker
CREATE TABLE/SCHEMA now allow you to add REPLICATION to the list of items
725
  {
726
    return false;
727
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
728
};
1122.2.10 by Monty Taylor
Fixed all of the include guards.
729
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
730
} /* namespace drizzled */
731
2069.4.3 by Brian Aker
Merge in move for share to be instance.
732
#endif /* DRIZZLED_TABLE_INSTANCE_BASE_H */