~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.h

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:11:45 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051145-xiputq4lvmtct377
storage engine docs. add bit about some temp table only engines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  instance of table share per one table in the database.
24
24
*/
25
25
 
26
 
#ifndef DRIZZLED_TABLE_INSTANCE_BASE_H
27
 
#define DRIZZLED_TABLE_INSTANCE_BASE_H
 
26
#ifndef DRIZZLED_DEFINITION_TABLE_H
 
27
#define DRIZZLED_DEFINITION_TABLE_H
28
28
 
29
29
#include <string>
30
30
 
32
32
#include <boost/thread/condition_variable.hpp>
33
33
#include <boost/dynamic_bitset.hpp>
34
34
#include <boost/shared_ptr.hpp>
35
 
#include <boost/scoped_ptr.hpp>
36
35
 
37
36
#include "drizzled/typelib.h"
38
37
#include "drizzled/memory/root.h"
39
 
#include "drizzled/message.h"
 
38
#include "drizzled/message/table.pb.h"
40
39
#include "drizzled/util/string.h"
41
40
 
42
 
#include "drizzled/lex_string.h"
43
 
#include "drizzled/key_map.h"
44
 
 
45
41
#include "drizzled/table/cache.h"
46
 
 
47
 
#include <drizzled/field.h>
48
 
 
49
42
 
50
43
namespace drizzled
51
44
{
52
45
 
 
46
extern uint64_t refresh_version;
 
47
 
 
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");
53
52
const static std::string NO_PROTOBUFFER_AVAILABLE("NO PROTOBUFFER AVAILABLE");
54
53
 
55
54
namespace plugin
56
55
{
57
56
class EventObserverList;
58
 
class StorageEngine;
59
57
}
60
58
 
61
59
namespace table {
62
 
class Singular;
 
60
class Instance;
63
61
}
64
62
 
65
63
class Field_blob;
72
70
  typedef boost::shared_ptr<TableShare> shared_ptr;
73
71
  typedef std::vector <shared_ptr> vector;
74
72
 
75
 
  TableShare(const identifier::Table::Type type_arg);
76
 
 
77
 
  TableShare(const identifier::Table &identifier, const identifier::Table::Key &key); // Used by placeholder
78
 
 
79
 
  TableShare(const identifier::Table &identifier); // Just used during createTable()
80
 
 
81
 
  TableShare(const identifier::Table::Type type_arg,
82
 
             const identifier::Table &identifier,
 
73
  TableShare(const TableIdentifier::Type type_arg);
 
74
 
 
75
  TableShare(const TableIdentifier &identifier, const TableIdentifier::Key &key); // Used by placeholder
 
76
 
 
77
  TableShare(const TableIdentifier &identifier); // Just used during createTable()
 
78
 
 
79
  TableShare(const TableIdentifier::Type type_arg,
 
80
             const TableIdentifier &identifier,
83
81
             char *path_arg= NULL, uint32_t path_length_arg= 0); // Shares for cache
84
82
 
85
 
  virtual ~TableShare();
 
83
  ~TableShare();
86
84
 
87
85
private:
88
86
  /** Category of this table. */
89
87
  enum_table_category table_category;
90
88
 
91
89
public:
 
90
 
92
91
  bool isTemporaryCategory() const
93
92
  {
94
93
    return (table_category == TABLE_CATEGORY_TEMPORARY);
101
100
 
102
101
  /* The following is copied to each Table on OPEN */
103
102
  typedef std::vector<Field *> Fields;
104
 
 
105
103
private:
106
104
  Fields _fields;
107
 
 
108
105
public:
109
106
  const Fields getFields() const
110
107
  {
137
134
    _fields.push_back(arg);
138
135
  }
139
136
 
 
137
 
140
138
  Field **found_next_number_field;
141
 
 
142
139
private:
143
140
  Field *timestamp_field;               /* Used only during open */
144
 
 
145
141
public:
146
142
 
147
143
  Field *getTimestampField() const               /* Used only during open */
157
153
 
158
154
private:
159
155
  KeyInfo  *key_info;                   /* data of keys in database */
160
 
 
161
156
public:
162
157
  KeyInfo &getKeyInfo(uint32_t arg) const
163
158
  {
165
160
  }
166
161
  std::vector<uint>     blob_field;                     /* Index to blobs in Field arrray*/
167
162
 
168
 
private:
169
163
  /* hash of field names (contains pointers to elements of field array) */
 
164
private:
170
165
  typedef boost::unordered_map < std::string, Field **, util::insensitive_hash, util::insensitive_equal_to> FieldMap;
171
166
  typedef std::pair< std::string, Field ** > FieldMapPair;
172
167
  FieldMap name_hash; /* hash of field names */
173
 
 
174
168
public:
175
169
  size_t getNamedFieldSize() const
176
170
  {
213
207
                   arg.begin(), ::toupper);
214
208
    _keynames.push_back(arg);
215
209
  }
216
 
 
217
210
public:
218
211
  bool doesKeyNameExist(const char *name_arg, uint32_t name_length, uint32_t &position) const
219
212
  {
241
234
private:
242
235
  std::vector<TYPELIB> intervals;                       /* pointer to interval info */
243
236
 
244
 
public:
245
 
  virtual void lock()
246
 
  { }
247
 
 
248
 
  virtual void unlock()
249
 
  { }
250
 
 
251
 
private:
 
237
  boost::mutex mutex;                /* For locking the share  */
 
238
  boost::condition_variable cond;                       /* To signal that share is ready */
 
239
 
 
240
 
 
241
  void lock()
 
242
  {
 
243
    mutex.lock();
 
244
  }
 
245
 
 
246
  void unlock()
 
247
  {
 
248
    mutex.unlock();
 
249
  }
 
250
 
252
251
  std::vector<unsigned char> default_values;            /* row with default values */
253
 
 
254
252
public:
255
253
  // @note This needs to be made to be const in the future
256
254
  unsigned char *getDefaultValues()
262
260
    default_values.resize(arg);
263
261
  }
264
262
 
265
 
  const charset_info_st *table_charset; /* Default charset of string fields */
 
263
  const CHARSET_INFO *table_charset; /* Default charset of string fields */
266
264
 
267
265
  boost::dynamic_bitset<> all_set;
268
266
 
277
275
    To ensure this one can use set_table_cache() methods.
278
276
  */
279
277
private:
280
 
  identifier::Table::Key private_key_for_cache; // This will not exist in the final design.
 
278
  TableIdentifier::Key private_key_for_cache; // This will not exist in the final design.
281
279
  std::vector<char> private_normalized_path; // This will not exist in the final design.
282
280
  LEX_STRING db;                        /* Pointer to db */
283
281
  LEX_STRING table_name;                /* Table name (for open) */
284
282
  LEX_STRING path;      /* Path to table (from datadir) */
285
283
  LEX_STRING normalized_path;           /* unpack_filename(path) */
286
 
 
287
284
public:
288
285
 
289
286
  const char *getNormalizedPath() const
296
293
    return path.str;
297
294
  }
298
295
 
299
 
  const identifier::Table::Key& getCacheKey() const // This should never be called when we aren't looking at a cache.
 
296
  const TableIdentifier::Key& getCacheKey() const // This should never be called when we aren't looking at a cache.
300
297
  {
301
298
    assert(private_key_for_cache.size());
302
299
    return private_key_for_cache;
319
316
    normalized_path.str= str_arg;
320
317
    normalized_path.length= size_arg;
321
318
  }
322
 
 
323
319
public:
324
320
 
325
321
  const char *getTableName() const
357
353
 
358
354
private:
359
355
  uint64_t   version;
360
 
 
361
356
public:
362
357
  uint64_t getVersion() const
363
358
  {
364
359
    return version;
365
360
  }
366
361
 
367
 
  void refreshVersion();
 
362
  void refreshVersion()
 
363
  {
 
364
   version= refresh_version;
 
365
  }
368
366
 
369
367
  void resetVersion()
370
368
  {
371
369
    version= 0;
372
370
  }
373
371
 
374
 
private:
375
372
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
376
 
 
377
 
  uint32_t reclength;                   /* Recordlength */
378
 
  uint32_t stored_rec_length;         /* Stored record length*/
379
 
 
 
373
private:
 
374
  uint32_t   reclength;                 /* Recordlength */
380
375
public:
381
 
  uint32_t sizeStoredRecord() const
382
 
  {
383
 
    return stored_rec_length;
384
 
  }
 
376
  uint32_t   stored_rec_length;         /* Stored record length*/
385
377
 
386
378
  uint32_t getRecordLength() const
387
379
  {
405
397
  /* Max rows is a hint to HEAP during a create tmp table */
406
398
  uint64_t max_rows;
407
399
 
408
 
  boost::scoped_ptr<message::Table> _table_message;
409
 
 
 
400
  message::Table *table_proto;
410
401
public:
 
402
 
411
403
  /*
412
 
    @note Without a _table_message, we assume we are building a STANDARD table.
 
404
    @note Without a table_proto, we assume we are building a STANDARD table.
413
405
    This will be modified once we use Identifiers in the Share itself.
414
406
  */
415
407
  message::Table::TableType getTableType() const
416
408
  {
417
 
    return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
 
409
    return table_proto ? table_proto->type() : message::Table::STANDARD;
418
410
  }
419
411
 
420
412
  const std::string &getTableTypeAsString() const
421
413
  {
422
 
    if (getTableMessage())
423
 
      return message::type(getTableMessage()->type());
424
 
 
425
 
    return NO_PROTOBUFFER_AVAILABLE;
 
414
    if (table_proto)
 
415
    {
 
416
      switch (table_proto->type())
 
417
      {
 
418
      default:
 
419
      case message::Table::STANDARD:
 
420
        return STANDARD_STRING;
 
421
      case message::Table::TEMPORARY:
 
422
        return TEMPORARY_STRING;
 
423
      case message::Table::INTERNAL:
 
424
        return INTERNAL_STRING;
 
425
      case message::Table::FUNCTION:
 
426
        return FUNCTION_STRING;
 
427
      }
 
428
    }
 
429
    else
 
430
    {
 
431
      return NO_PROTOBUFFER_AVAILABLE;
 
432
    }
426
433
  }
427
434
 
428
435
  /* This is only used in one location currently */
429
 
  inline message::Table *getTableMessage() const
430
 
  {
431
 
    return _table_message.get();
432
 
  }
433
 
 
434
 
  void setTableMessage(const message::Table &arg)
435
 
  {
436
 
    assert(not getTableMessage());
437
 
    _table_message.reset(new(std::nothrow) message::Table(arg));
 
436
  inline message::Table *getTableProto() const
 
437
  {
 
438
    return table_proto;
438
439
  }
439
440
 
440
441
  const message::Table::Field &field(int32_t field_position) const
441
442
  {
442
 
    assert(getTableMessage());
443
 
    return getTableMessage()->field(field_position);
 
443
    assert(table_proto);
 
444
    return table_proto->field(field_position);
 
445
  }
 
446
 
 
447
  inline void setTableProto(message::Table *arg)
 
448
  {
 
449
    assert(table_proto == NULL);
 
450
    table_proto= arg;
444
451
  }
445
452
 
446
453
  inline bool hasComment() const
447
454
  {
448
 
    return (getTableMessage()) ?  getTableMessage()->options().has_comment() : false; 
 
455
    return (table_proto) ?  table_proto->options().has_comment() : false; 
449
456
  }
450
457
 
451
458
  inline const char *getComment()
452
459
  {
453
 
    return (getTableMessage() && getTableMessage()->has_options()) ?  getTableMessage()->options().comment().c_str() : NULL; 
 
460
    return (table_proto && table_proto->has_options()) ?  table_proto->options().comment().c_str() : NULL; 
454
461
  }
455
462
 
456
463
  inline uint32_t getCommentLength() const
457
464
  {
458
 
    return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0; 
 
465
    return (table_proto) ? table_proto->options().comment().length() : 0; 
459
466
  }
460
467
 
461
468
  inline uint64_t getMaxRows() const
485
492
  }
486
493
 
487
494
private:
488
 
  identifier::Table::Type tmp_table;
 
495
  TableIdentifier::Type tmp_table;
489
496
public:
490
497
 
491
 
  identifier::Table::Type getType() const
 
498
  TableIdentifier::Type getType() const
492
499
  {
493
500
    return tmp_table;
494
501
  }
495
502
 
496
503
private:
497
 
  uint32_t _ref_count;       /* How many Table objects uses this */
 
504
  uint32_t ref_count;       /* How many Table objects uses this */
498
505
 
499
506
public:
500
507
  uint32_t getTableCount() const
501
508
  {
502
 
    return _ref_count;
 
509
    return ref_count;
503
510
  }
504
511
 
505
512
  void incrementTableCount()
506
513
  {
507
514
    lock();
508
 
    _ref_count++;
 
515
    ref_count++;
509
516
    unlock();
510
517
  }
511
518
 
512
 
  uint32_t decrementTableCount()
513
 
  {
514
 
    return --_ref_count;
515
 
  }
516
 
 
517
519
  uint32_t null_bytes;
518
520
  uint32_t last_null_bit_pos;
519
521
private:
544
546
  uint32_t blob_fields;                 /* number of blob fields */
545
547
private:
546
548
  bool has_variable_width;                  /* number of varchar fields */
547
 
 
548
549
public:
549
550
  bool hasVariableWidth() const
550
551
  {
587
588
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
588
589
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
589
590
 
590
 
private:
591
591
  uint8_t blob_ptr_size;                        /* 4 or 8 */
592
 
 
593
 
public:
594
 
  uint8_t sizeBlobPtr() const
595
 
  {
596
 
    return blob_ptr_size;
597
 
  }
598
 
 
599
592
  bool db_low_byte_first;               /* Portable row format */
600
593
 
601
594
  /*
609
602
    event_observers is a class containing all the event plugins that have 
610
603
    registered an interest in this table.
611
604
  */
612
 
  virtual plugin::EventObserverList *getTableObservers() 
 
605
  private:
 
606
  plugin::EventObserverList *event_observers;
 
607
  public:
 
608
  plugin::EventObserverList *getTableObservers() 
613
609
  { 
614
 
    return NULL;
 
610
    return event_observers;
615
611
  }
616
612
  
617
 
  virtual void setTableObservers(plugin::EventObserverList *) 
618
 
  { }
 
613
  void setTableObservers(plugin::EventObserverList *observers) 
 
614
  { 
 
615
    event_observers= observers;
 
616
  }
619
617
  
620
618
  /*
621
619
    Set share's identifier information.
626
624
    NOTES
627
625
  */
628
626
 
629
 
  void setIdentifier(const identifier::Table &identifier_arg);
 
627
  void setIdentifier(const TableIdentifier &identifier_arg);
630
628
 
631
629
  /*
632
630
    Initialize share for temporary tables
647
645
private:
648
646
  void init(const char *new_table_name,
649
647
            const char *new_path);
 
648
public:
650
649
 
651
 
protected:
652
650
  void open_table_error(int pass_error, int db_errno, int pass_errarg);
653
651
 
654
 
public:
655
 
 
 
652
  static void release(TableShare *share);
 
653
  static void release(TableShare::shared_ptr &share);
 
654
  static void release(const TableIdentifier &identifier);
656
655
  static TableShare::shared_ptr getShareCreate(Session *session, 
657
 
                                               const identifier::Table &identifier,
 
656
                                               const TableIdentifier &identifier,
658
657
                                               int &error);
659
658
 
660
659
  friend std::ostream& operator<<(std::ostream& output, const TableShare &share)
673
672
  }
674
673
 
675
674
protected:
676
 
  friend class drizzled::table::Singular;
 
675
  friend class drizzled::table::Instance;
677
676
 
678
677
  Field *make_field(const message::Table::Field &pfield,
679
678
                    unsigned char *ptr,
683
682
                    unsigned char null_bit,
684
683
                    uint8_t decimals,
685
684
                    enum_field_types field_type,
686
 
                    const charset_info_st * field_charset,
 
685
                    const CHARSET_INFO * field_charset,
687
686
                    Field::utype unireg_check,
688
687
                    TYPELIB *interval,
689
688
                    const char *field_name);
696
695
                    unsigned char null_bit,
697
696
                    uint8_t decimals,
698
697
                    enum_field_types field_type,
699
 
                    const charset_info_st * field_charset,
 
698
                    const CHARSET_INFO * field_charset,
700
699
                    Field::utype unireg_check,
701
700
                    TYPELIB *interval,
702
701
                    const char *field_name, 
703
702
                    bool is_unsigned);
704
703
 
705
704
public:
706
 
  int open_table_def(Session& session, const identifier::Table &identifier);
 
705
  int open_table_def(Session& session, const TableIdentifier &identifier);
707
706
 
708
707
  int open_table_from_share(Session *session,
709
 
                            const identifier::Table &identifier,
 
708
                            const TableIdentifier &identifier,
710
709
                            const char *alias,
711
710
                            uint32_t db_stat, uint32_t ha_open_flags,
712
711
                            Table &outparam);
715
714
                                  const char *alias,
716
715
                                  uint32_t db_stat,
717
716
                                  Table &outparam);
718
 
  int open_table_cursor_inner(const identifier::Table &identifier,
 
717
  int open_table_cursor_inner(const TableIdentifier &identifier,
719
718
                              uint32_t db_stat, uint32_t ha_open_flags,
720
719
                              Table &outparam,
721
720
                              bool &error_reported);
722
721
public:
723
 
  bool parse_table_proto(Session& session, message::Table &table);
 
722
  int parse_table_proto(Session& session, message::Table &table);
 
723
private:
 
724
  int inner_parse_table_proto(Session& session, message::Table &table);
724
725
};
725
726
 
726
727
} /* namespace drizzled */
727
728
 
728
 
#endif /* DRIZZLED_TABLE_INSTANCE_BASE_H */
 
729
#endif /* DRIZZLED_DEFINITION_TABLE_H */