~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
 *
4
 *  Copyright (C) 2009 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
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
1122.2.10 by Monty Taylor
Fixed all of the include guards.
26
#ifndef DRIZZLED_TABLE_SHARE_H
27
#define DRIZZLED_TABLE_SHARE_H
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>
1429.3.1 by Monty Taylor
Use unordered_map from the upcoming c++0x standard instead of a homemade
35
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
36
#include "drizzled/typelib.h"
37
#include "drizzled/memory/root.h"
1122.2.13 by Monty Taylor
Header cleanup.
38
#include "drizzled/message/table.pb.h"
1669.3.2 by Brian Aker
This fixes the issue with case and unordered map.
39
#include "drizzled/util/string.h"
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
40
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
41
namespace drizzled
42
{
43
1835.1.1 by Brian Aker
Convert the internal of our definition cache to be shared_ptr.
44
typedef boost::shared_ptr<TableShare> TableSharePtr;
45
46
typedef boost::unordered_map< TableIdentifier::Key, TableSharePtr> TableDefinitionCache;
1340.1.2 by Brian Aker
Merge of table cache/def DD.
47
1347 by Brian Aker
Update/fix for leak.
48
const static std::string STANDARD_STRING("STANDARD");
49
const static std::string TEMPORARY_STRING("TEMPORARY");
50
const static std::string INTERNAL_STRING("INTERNAL");
51
const static std::string FUNCTION_STRING("FUNCTION");
52
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
53
namespace plugin
54
{
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
55
class EventObserverList;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
56
}
57
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.
58
class Field_blob;
59
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
60
class TableShare
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
61
{
1530.1.1 by Brian Aker
Removes typelib usage from fieldname
62
  typedef std::vector<std::string> StringVector;
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
63
public:
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
64
  TableShare(TableIdentifier::Type type_arg);
65
66
  TableShare(TableIdentifier &identifier, const TableIdentifier::Key &key); // Used by placeholder
67
1618.1.1 by Brian Aker
Modify TableIdentifier to be const
68
  TableShare(const TableIdentifier &identifier); // Just used during createTable()
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
69
1608.2.4 by Brian Aker
Update for having share declared type.
70
  TableShare(TableIdentifier::Type type_arg,
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
71
             TableIdentifier &identifier,
72
             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()
73
1619.1.1 by Brian Aker
Update for TableShare usage of key (remove a case where we had to build it).
74
  ~TableShare();
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
75
1502.1.23 by Brian Aker
Some encapsulation.
76
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
77
  /** Category of this table. */
78
  enum_table_category table_category;
79
1030.1.3 by Brian Aker
Final bits to structure alignment
80
  uint32_t open_count;			/* Number of tables in open list */
1502.1.23 by Brian Aker
Some encapsulation.
81
public:
82
83
  bool isTemporaryCategory() const
84
  {
85
    return (table_category == TABLE_CATEGORY_TEMPORARY);
86
  }
87
88
  void setTableCategory(enum_table_category arg)
89
  {
90
    table_category= arg;
91
  }
1030.1.3 by Brian Aker
Final bits to structure alignment
92
93
  /* The following is copied to each Table on OPEN */
1578.2.14 by Brian Aker
Additional pass through to remove raw field access.
94
  typedef std::vector<Field *> Fields;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
95
private:
1578.2.14 by Brian Aker
Additional pass through to remove raw field access.
96
  Fields field;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
97
public:
1591 by Brian Aker
Small bits of field abstraction.
98
  const Fields getFields() const
1578.2.14 by Brian Aker
Additional pass through to remove raw field access.
99
  {
100
    return field;
101
  }
102
103
  Field ** getFields(bool)
1502.1.23 by Brian Aker
Some encapsulation.
104
  {
1578.2.7 by Brian Aker
Move Field to being a vector.
105
    return &field[0];
1502.1.23 by Brian Aker
Some encapsulation.
106
  }
107
1578.2.11 by Brian Aker
Use the Fields generated from share for Table.
108
  void setFields(uint32_t arg)
109
  {
110
    field.resize(arg);
111
  }
112
1578.2.15 by Brian Aker
Merge of additions to Field abstraction.
113
  uint32_t positionFields(Field **arg) const
114
  {
115
    return (arg - (Field **)&field[0]);
116
  }
117
118
  void pushField(Field *arg)
119
  {
120
    fields++;
121
    field.push_back(arg);
122
  }
123
1530.1.3 by Brian Aker
Style cleanup for table_share
124
1030.1.3 by Brian Aker
Final bits to structure alignment
125
  Field **found_next_number_field;
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
126
private:
1030.1.3 by Brian Aker
Final bits to structure alignment
127
  Field *timestamp_field;               /* Used only during open */
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
128
public:
129
130
  Field *getTimestampField() const               /* Used only during open */
131
  {
132
    return timestamp_field;
133
  }
134
135
  void setTimestampField(Field *arg) /* Used only during open */
136
  {
137
    timestamp_field= arg;
138
  }
139
140
1574.1.3 by Brian Aker
Encapsulate Key info in share.
141
private:
1535 by Brian Aker
Rename of KEY to KeyInfo
142
  KeyInfo  *key_info;			/* data of keys in database */
1574.1.3 by Brian Aker
Encapsulate Key info in share.
143
public:
1574.1.4 by Brian Aker
Furthere encapsulation for TableShare.
144
  KeyInfo &getKeyInfo(uint32_t arg) const
1574.1.3 by Brian Aker
Encapsulate Key info in share.
145
  {
146
    return key_info[arg];
147
  }
1574.1.8 by Brian Aker
Blob now allocated via vector
148
  std::vector<uint>	blob_field;			/* Index to blobs in Field arrray*/
1030.1.3 by Brian Aker
Final bits to structure alignment
149
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
150
  /* hash of field names (contains pointers to elements of field array) */
1669.3.1 by Brian Aker
Remove usage of my_hash in table_share.
151
private:
1669.3.4 by Brian Aker
Fix up a few additional cases around case insensitive usage for
152
  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.
153
  typedef std::pair< std::string, Field ** > FieldMapPair;
154
  FieldMap name_hash; /* hash of field names */
155
public:
156
  size_t getNamedFieldSize() const
157
  {
158
    return name_hash.size();
159
  }
160
161
  Field **getNamedField(const std::string &arg)
162
  {
163
    FieldMap::iterator iter= name_hash.find(arg);
164
165
    if (iter == name_hash.end())
166
        return 0;
167
168
    return (*iter).second;
169
  }
170
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
171
private:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
172
  memory::Root mem_root;
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
173
public:
174
  void *alloc_root(size_t arg)
175
  {
176
    return mem_root.alloc_root(arg);
177
  }
178
179
  char *strmake_root(const char *str_arg, size_t len_arg)
180
  {
181
    return mem_root.strmake_root(str_arg, len_arg);
182
  }
183
1532.1.1 by Brian Aker
Merge of change to flip table instance to be share instance
184
  memory::Root *getMemRoot()
185
  {
186
    return &mem_root;
187
  }
188
1527.1.3 by Brian Aker
This is:
189
private:
190
  std::vector<std::string> _keynames;
191
192
  void addKeyName(std::string arg)
193
  {
194
    std::transform(arg.begin(), arg.end(),
195
                   arg.begin(), ::toupper);
196
    _keynames.push_back(arg);
197
  }
198
public:
1574 by Brian Aker
Rollup patch for hiding tableshare.
199
  bool doesKeyNameExist(const char *name_arg, uint32_t name_length, uint32_t &position) const
1527.1.3 by Brian Aker
This is:
200
  {
201
    std::string arg(name_arg, name_length);
202
    std::transform(arg.begin(), arg.end(),
203
                   arg.begin(), ::toupper);
204
1574 by Brian Aker
Rollup patch for hiding tableshare.
205
    std::vector<std::string>::const_iterator iter= std::find(_keynames.begin(), _keynames.end(), arg);
1527.1.3 by Brian Aker
This is:
206
207
    if (iter == _keynames.end())
208
      return false;
209
210
    position= iter -  _keynames.begin();
211
212
    return true;
213
  }
214
1574 by Brian Aker
Rollup patch for hiding tableshare.
215
  bool doesKeyNameExist(std::string arg, uint32_t &position) const
1527.1.4 by Brian Aker
Second pass to remove keynames typelib.
216
  {
217
    std::transform(arg.begin(), arg.end(),
218
                   arg.begin(), ::toupper);
219
1574 by Brian Aker
Rollup patch for hiding tableshare.
220
    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.
221
222
    if (iter == _keynames.end())
223
    {
1816.2.3 by Monty Taylor
Fixed some more ICC warnings. How did I get started on this this morning?
224
      position= UINT32_MAX; //historical, required for finding primary key from unique
1527.1.4 by Brian Aker
Second pass to remove keynames typelib.
225
      return false;
226
    }
227
228
    position= iter -  _keynames.begin();
229
230
    return true;
231
  }
232
1530.1.1 by Brian Aker
Removes typelib usage from fieldname
233
private:
1574.1.7 by Brian Aker
Remove interval allocation via memroot.
234
  std::vector<TYPELIB> intervals;			/* pointer to interval info */
1530.1.1 by Brian Aker
Removes typelib usage from fieldname
235
1755.2.5 by Brian Aker
Move over to use boost for the locks in table_share.
236
  boost::mutex mutex;                /* For locking the share  */
237
  boost::condition_variable cond;			/* To signal that share is ready */
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
238
1685.2.2 by Brian Aker
Remove wait condition.
239
240
  void lock()
241
  {
1755.2.5 by Brian Aker
Move over to use boost for the locks in table_share.
242
    mutex.lock();
1685.2.2 by Brian Aker
Remove wait condition.
243
  }
244
245
  void unlock()
246
  {
1755.2.5 by Brian Aker
Move over to use boost for the locks in table_share.
247
    mutex.unlock();
1685.2.2 by Brian Aker
Remove wait condition.
248
  }
1685.2.16 by Brian Aker
Merge in change such that the lock for share is now private (including methods).
249
public:
1685.2.2 by Brian Aker
Remove wait condition.
250
1574 by Brian Aker
Rollup patch for hiding tableshare.
251
private:
252
  std::vector<unsigned char> default_values;		/* row with default values */
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
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
264
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
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:
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
279
  TableIdentifier::Key private_key_for_cache; // This will not exist in the final design.
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) */
1502.1.9 by Brian Aker
More encapsulation.
285
public:
286
1578.2.2 by Brian Aker
Const'ize TableShare methods (first pass, not completed)
287
  const char *getNormalizedPath() const
1502.1.9 by Brian Aker
More encapsulation.
288
  {
289
    return normalized_path.str;
290
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
291
1578.2.2 by Brian Aker
Const'ize TableShare methods (first pass, not completed)
292
  const char *getPath() const
1502.1.7 by Brian Aker
Partial encapsulation of table_share
293
  {
294
    return path.str;
295
  }
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
296
1619.1.1 by Brian Aker
Update for TableShare usage of key (remove a case where we had to build it).
297
  const TableIdentifier::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.
298
  {
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
299
    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).
300
    return private_key_for_cache;
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
301
  }
302
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
303
  size_t getCacheKeySize() const
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
304
  {
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
305
    return private_key_for_cache.size();
1502.1.8 by Brian Aker
Fixed table_share_key from being public.
306
  }
307
1502.1.7 by Brian Aker
Partial encapsulation of table_share
308
  void setPath(char *str_arg, uint32_t size_arg)
309
  {
310
    path.str= str_arg;
311
    path.length= size_arg;
312
  }
313
1502.1.9 by Brian Aker
More encapsulation.
314
  void setNormalizedPath(char *str_arg, uint32_t size_arg)
315
  {
316
    normalized_path.str= str_arg;
317
    normalized_path.length= size_arg;
318
  }
319
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
320
  const char *getTableName() const
321
  {
322
    return table_name.str;
323
  }
324
1502.1.10 by Brian Aker
Encapsulate table name in TableShare.
325
  uint32_t getTableNameSize() const
326
  {
327
    return table_name.length;
328
  }
329
1347 by Brian Aker
Update/fix for leak.
330
  const std::string &getTableName(std::string &name_arg) const
331
  {
332
    name_arg.clear();
333
    name_arg.append(table_name.str, table_name.length);
334
335
    return name_arg;
336
  }
337
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
338
  const char *getSchemaName() const
339
  {
340
    return db.str;
341
  }
342
1346 by Brian Aker
Solve non-null termination issue.
343
  const std::string &getSchemaName(std::string &schema_name_arg) const
344
  {
345
    schema_name_arg.clear();
346
    schema_name_arg.append(db.str, db.length);
347
348
    return schema_name_arg;
349
  }
350
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
351
  uint32_t   block_size;                   /* create information */
1340.1.2 by Brian Aker
Merge of table cache/def DD.
352
1578.2.3 by Brian Aker
Take version and encapsulate it in TableShare
353
private:
1223.2.1 by Trond Norbye
Bug #485658: Compile failure on 32 bit system due to mixing ulong, uint64_t and uint32_t
354
  uint64_t   version;
1578.2.3 by Brian Aker
Take version and encapsulate it in TableShare
355
public:
1578.2.2 by Brian Aker
Const'ize TableShare methods (first pass, not completed)
356
  uint64_t getVersion() const
1340.1.2 by Brian Aker
Merge of table cache/def DD.
357
  {
358
    return version;
359
  }
360
1578.2.3 by Brian Aker
Take version and encapsulate it in TableShare
361
  void refreshVersion()
362
  {
363
   version= refresh_version;
364
  }
365
366
  void resetVersion()
367
  {
368
    version= 0;
369
  }
370
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
371
  uint32_t   timestamp_offset;		/* Set to offset+1 of record */
1578.2.8 by Brian Aker
Encapsulate record length.
372
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
373
  uint32_t   reclength;			/* Recordlength */
1578.2.8 by Brian Aker
Encapsulate record length.
374
public:
1030.1.3 by Brian Aker
Final bits to structure alignment
375
  uint32_t   stored_rec_length;         /* Stored record length*/
376
1578.2.8 by Brian Aker
Encapsulate record length.
377
  uint32_t getRecordLength() const
1320.1.17 by Brian Aker
New code for a show temporary tables;
378
  {
379
    return reclength;
380
  }
381
1578.2.8 by Brian Aker
Encapsulate record length.
382
  void setRecordLength(uint32_t arg)
383
  {
384
    reclength= arg;
385
  }
386
1593 by Brian Aker
Merge in Barry.
387
  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.
388
  {
1593 by Brian Aker
Merge in Barry.
389
    if (arg < blob_fields)
390
      return (Field_blob*) field[blob_field[arg]];
391
392
    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.
393
  }
1589.1.1 by Barry.Leslie at PrimeBase
Changed the table event observers to pass the 'Table' not the TableShare' to the observers.
394
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
395
private:
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
396
  /* Max rows is a hint to HEAP during a create tmp table */
397
  uint64_t max_rows;
398
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
399
  message::Table *table_proto;
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
400
public:
401
1608.2.1 by Brian Aker
Modified to table identifier to fix temporary table creation loss of file.
402
  /*
403
    @note Without a table_proto, we assume we are building a STANDARD table.
404
    This will be modified once we use Identifiers in the Share itself.
405
  */
406
  message::Table::TableType getTableType() const
407
  {
408
    return table_proto ? table_proto->type() : message::Table::STANDARD;
409
  }
410
1347 by Brian Aker
Update/fix for leak.
411
  const std::string &getTableTypeAsString() const
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
412
  {
413
    switch (table_proto->type())
414
    {
415
    default:
416
    case message::Table::STANDARD:
1347 by Brian Aker
Update/fix for leak.
417
      return STANDARD_STRING;
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
418
    case message::Table::TEMPORARY:
1347 by Brian Aker
Update/fix for leak.
419
      return TEMPORARY_STRING;
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
420
    case message::Table::INTERNAL:
1347 by Brian Aker
Update/fix for leak.
421
      return INTERNAL_STRING;
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
422
    case message::Table::FUNCTION:
1347 by Brian Aker
Update/fix for leak.
423
      return FUNCTION_STRING;
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
424
    }
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 */
1320.1.18 by Brian Aker
Overhaul of SHOW TABLE STATUS.
428
  inline message::Table *getTableProto() const
1273.19.10 by Brian Aker
Add support for listing temporay tables from show commands.
429
  {
430
    return table_proto;
431
  }
432
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
433
  inline void setTableProto(message::Table *arg)
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
434
  {
435
    assert(table_proto == NULL);
436
    table_proto= arg;
437
  }
438
1574 by Brian Aker
Rollup patch for hiding tableshare.
439
  inline bool hasComment() const
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
440
  {
441
    return (table_proto) ?  table_proto->options().has_comment() : false; 
442
  }
443
444
  inline const char *getComment()
445
  {
1183.1.18 by Brian Aker
Fixed references to doCreateTable()
446
    return (table_proto && table_proto->has_options()) ?  table_proto->options().comment().c_str() : NULL; 
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
447
  }
448
1574 by Brian Aker
Rollup patch for hiding tableshare.
449
  inline uint32_t getCommentLength() const
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
450
  {
451
    return (table_proto) ? table_proto->options().comment().length() : 0; 
452
  }
453
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
454
  inline uint64_t getMaxRows() const
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
455
  {
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
456
    return max_rows;
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
457
  }
458
459
  inline void setMaxRows(uint64_t arg)
460
  {
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
461
    max_rows= arg;
1116.1.1 by Brian Aker
Fix for Stewart's patch (includes hack to solve MAX rows problem).
462
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
463
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.
464
  /**
465
   * Returns true if the supplied Field object
466
   * is part of the table's primary key.
1530.1.3 by Brian Aker
Style cleanup for table_share
467
 */
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.
468
  bool fieldInPrimaryKey(Field *field) const;
469
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
470
  plugin::StorageEngine *storage_engine;			/* storage engine plugin */
471
  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).
472
  {
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
473
    return storage_engine;
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
474
  }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
475
  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.
476
  {
477
    return storage_engine;
478
  }
1395.1.9 by Brian Aker
Small cleanup around how we do types internally.
479
1608.2.3 by Brian Aker
Encapsulate type for TableShare.
480
private:
1395.1.9 by Brian Aker
Small cleanup around how we do types internally.
481
  TableIdentifier::Type tmp_table;
1608.2.3 by Brian Aker
Encapsulate type for TableShare.
482
public:
483
484
  TableIdentifier::Type getType() const
485
  {
486
    return tmp_table;
487
  }
488
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
489
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
490
  uint32_t ref_count;       /* How many Table objects uses this */
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
491
public:
492
  uint32_t getTableCount() const
1340.1.2 by Brian Aker
Merge of table cache/def DD.
493
  {
494
    return ref_count;
495
  }
496
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
497
  void incrementTableCount()
498
  {
1685.2.16 by Brian Aker
Merge in change such that the lock for share is now private (including methods).
499
    lock();
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
500
    ref_count++;
1685.2.16 by Brian Aker
Merge in change such that the lock for share is now private (including methods).
501
    unlock();
1578.2.4 by Brian Aker
More encapsulation of table Share, this time table count.
502
  }
503
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
504
  uint32_t null_bytes;
505
  uint32_t last_null_bit_pos;
506
  uint32_t fields;				/* Number of fields */
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
507
508
  uint32_t sizeFields() const
509
  {
510
    return fields;
511
  }
512
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
513
  uint32_t rec_buff_length;                 /* Size of table->record[] buffer */
1578.2.10 by Brian Aker
keys and fields partial encapsulation.
514
  uint32_t keys;
515
516
  uint32_t sizeKeys() const
517
  {
518
    return keys;
519
  }
520
  uint32_t key_parts;
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
521
  uint32_t max_key_length, max_unique_length, total_key_length;
522
  uint32_t uniques;                         /* Number of UNIQUE index */
523
  uint32_t null_fields;			/* number of null fields */
524
  uint32_t blob_fields;			/* number of blob fields */
525
  uint32_t timestamp_field_offset;		/* Field number for timestamp field */
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
526
private:
527
  bool has_variable_width;                  /* number of varchar fields */
528
public:
529
  bool hasVariableWidth() const
530
  {
531
    return has_variable_width; // We should calculate this.
532
  }
533
  void setVariableWidth()
534
  {
535
    has_variable_width= true;
536
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
537
  uint32_t db_create_options;		/* Create options from database */
538
  uint32_t db_options_in_use;		/* Options in use */
539
  uint32_t db_record_offset;		/* if HA_REC_IN_SEQ */
540
  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.
541
  /**
542
   * @TODO 
543
   *
544
   * Currently the replication services component uses
545
   * the primary_key member to determine which field is the table's
546
   * primary key.  However, as it exists, because this member is scalar, it
547
   * only supports a single-column primary key. Is there a better way
548
   * to ask for the fields which are in a primary key?
1530.1.3 by Brian Aker
Style cleanup for table_share
549
 */
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
550
private:
1143.2.21 by Jay Pipes
Fixes Bug 440141 - Replication stream contains incorrect key field information for UPDATE statements.
551
  uint32_t primary_key;
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
552
public:
553
554
  uint32_t getPrimaryKey() const
555
  {
556
    return primary_key;
557
  }
558
559
  bool hasPrimaryKey() const
560
  {
561
    return primary_key != MAX_KEY;
562
  }
563
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
564
  /* Index of auto-updated TIMESTAMP field in field array */
565
  uint32_t next_number_index;               /* autoincrement key number */
566
  uint32_t next_number_key_offset;          /* autoinc keypart offset in a key */
567
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
568
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
569
1039.1.9 by Brian Aker
Partial Refactor of TableShare
570
  uint8_t blob_ptr_size;			/* 4 or 8 */
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
571
  bool db_low_byte_first;		/* Portable row format */
1340.1.2 by Brian Aker
Merge of table cache/def DD.
572
1578.2.5 by Brian Aker
Encapsulate name lock.
573
private:
1039.1.9 by Brian Aker
Partial Refactor of TableShare
574
  bool name_lock;
1578.2.5 by Brian Aker
Encapsulate name lock.
575
public:
1340.1.2 by Brian Aker
Merge of table cache/def DD.
576
  bool isNameLock() const
577
  {
578
    return name_lock;
579
  }
580
1039.1.9 by Brian Aker
Partial Refactor of TableShare
581
  bool replace_with_name_lock;
1340.1.2 by Brian Aker
Merge of table cache/def DD.
582
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
583
private:
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
584
  bool waiting_on_cond;                 /* Protection against free */
1578.2.6 by Brian Aker
Encapsulate timestamp field in table share.
585
public:
1340.1.2 by Brian Aker
Merge of table cache/def DD.
586
  bool isWaitingOnCondition()
587
  {
588
    return waiting_on_cond;
589
  }
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
590
591
  /*
1089.1.4 by Brian Aker
Optimization for createKey(). Removes the need to initialize some
592
    Set of keys in use, implemented as a Bitmap.
593
    Excludes keys disabled by ALTER Table ... DISABLE KEYS.
1030.1.3 by Brian Aker
Final bits to structure alignment
594
  */
595
  key_map keys_in_use;
596
  key_map keys_for_keyread;
597
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
598
  /* 
599
    event_observers is a class containing all the event plugins that have 
600
    registered an interest in this table.
601
  */
602
  private:
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
603
  plugin::EventObserverList *event_observers;
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
604
  public:
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
605
  plugin::EventObserverList *getTableObservers() 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
606
  { 
607
    return event_observers;
608
  }
609
  
1502.5.8 by Barry.Leslie at PrimeBase
- Changed names to match the drizzle naming convention.
610
  void setTableObservers(plugin::EventObserverList *observers) 
1502.5.2 by Barry.Leslie at PrimeBase
Changes made to drizzle source when building in the events plugin.
611
  { 
612
    event_observers= observers;
613
  }
614
  
1030.1.3 by Brian Aker
Final bits to structure alignment
615
  /*
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
616
    Set share's identifier information.
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
617
618
    SYNOPSIS
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
619
    setIdentifier()
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
620
621
    NOTES
622
  */
623
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
624
  void setIdentifier(TableIdentifier &identifier_arg);
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
625
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
626
  /*
627
    Initialize share for temporary tables
628
629
    SYNOPSIS
1000.1.5 by Brian Aker
More refactoring back to TableShare object.
630
    init()
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
631
    share	Share to fill
632
    key		Table_cache_key, as generated from create_table_def_key.
633
    must start with db name.
634
    key_length	Length of key
635
    table_name	Table name
1259.5.7 by Stewart Smith
remove references to FRM in comments around tableshare
636
    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).
637
638
    NOTES
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
639
    
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
640
  */
641
1578.2.1 by Brian Aker
Make init() methods private in TableShare.
642
private:
1000.1.5 by Brian Aker
More refactoring back to TableShare object.
643
  void init(const char *new_table_name,
1608.2.2 by Brian Aker
Move constructors to .cc file.
644
            const char *new_path);
1578.2.1 by Brian Aker
Make init() methods private in TableShare.
645
public:
1000.1.4 by Brian Aker
Turn init_tmp_table_share into a method (the memset of the object... cute).
646
1039.1.9 by Brian Aker
Partial Refactor of TableShare
647
  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
648
1223.3.1 by Monty Taylor
Replace HASH in table_share with drizzled::hash_map
649
  static void cacheStart(void);
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
650
  static void release(TableShare *share);
1835.1.2 by Brian Aker
Further push down the logic for shared_ptr.
651
  static void release(TableSharePtr &share);
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
652
  static void release(TableIdentifier &identifier);
653
  static const TableDefinitionCache &getCache();
1835.1.2 by Brian Aker
Further push down the logic for shared_ptr.
654
  static TableSharePtr getShare(TableIdentifier &identifier);
655
  static TableSharePtr getShareCreate(Session *session, 
656
                                      TableIdentifier &identifier,
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
1502.1.18 by Brian Aker
Encapsulate mem_root in TableShare
674
  Field *make_field(unsigned char *ptr,
675
                    uint32_t field_length,
676
                    bool is_nullable,
677
                    unsigned char *null_pos,
678
                    unsigned char null_bit,
679
                    uint8_t decimals,
680
                    enum_field_types field_type,
681
                    const CHARSET_INFO * field_charset,
682
                    Field::utype unireg_check,
683
                    TYPELIB *interval,
684
                    const char *field_name);
1502.1.24 by Brian Aker
Absorb TableShare proto to share methods.
685
686
  int open_table_def(Session& session, TableIdentifier &identifier);
687
1626.3.2 by Brian Aker
Cleanup table_share to pass in identifier.
688
  int open_table_from_share(Session *session,
689
                            const TableIdentifier &identifier,
690
                            const char *alias,
1502.1.24 by Brian Aker
Absorb TableShare proto to share methods.
691
                            uint32_t db_stat, uint32_t ha_open_flags,
692
                            Table &outparam);
1502.1.25 by Brian Aker
Function -> method for TableShare.
693
  int parse_table_proto(Session& session, message::Table &table);
694
private:
695
  int inner_parse_table_proto(Session& session, message::Table &table);
798 by Brian Aker
Updated table_share tto its own file (yess, it will eventually go away).
696
};
1122.2.10 by Monty Taylor
Fixed all of the include guards.
697
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
698
} /* namespace drizzled */
699
1122.2.10 by Monty Taylor
Fixed all of the include guards.
700
#endif /* DRIZZLED_TABLE_SHARE_H */