~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
typedef enum enum_table_category TABLE_CATEGORY;
55
55
typedef struct st_columndef MI_COLUMNDEF;
56
56
 
57
 
bool create_myisam_from_heap(Session *session, Table *table,
58
 
                             MI_COLUMNDEF *start_recinfo,
59
 
                             MI_COLUMNDEF **recinfo,
60
 
                             int error, bool ignore_last_dupp_key_error);
61
 
 
62
57
/**
63
58
 * Class representing a set of records, either in a temporary, 
64
59
 * normal, or derived table.
66
61
class Table 
67
62
{
68
63
public:
69
 
 
70
64
  TableShare *s; /**< Pointer to the shared metadata about the table */
 
65
 
 
66
private:
71
67
  Field **field; /**< Pointer to fields collection */
 
68
public:
 
69
 
 
70
  Field **getFields() const
 
71
  {
 
72
    return field;
 
73
  }
 
74
 
 
75
  Field *getField(uint32_t arg) const
 
76
  {
 
77
    return field[arg];
 
78
  }
 
79
 
 
80
  void setFields(Field **arg)
 
81
  {
 
82
    field= arg;
 
83
  }
 
84
 
 
85
  void setFieldAt(Field *arg, uint32_t arg_pos)
 
86
  {
 
87
    field[arg_pos]= arg;
 
88
  }
72
89
 
73
90
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
 
91
private:
74
92
  Table *next;
 
93
public:
 
94
  Table *getNext() const
 
95
  {
 
96
    return next;
 
97
  }
 
98
 
 
99
  Table **getNextPtr()
 
100
  {
 
101
    return &next;
 
102
  }
 
103
 
 
104
  void setNext(Table *arg)
 
105
  {
 
106
    next= arg;
 
107
  }
 
108
 
 
109
  void unlink()
 
110
  {
 
111
    getNext()->setPrev(getPrev());              /* remove from used chain */
 
112
    getPrev()->setNext(getNext());
 
113
  }
 
114
 
 
115
private:
75
116
  Table *prev;
 
117
public:
 
118
  Table *getPrev() const
 
119
  {
 
120
    return prev;
 
121
  }
 
122
 
 
123
  Table **getPrevPtr()
 
124
  {
 
125
    return &prev;
 
126
  }
 
127
 
 
128
  void setPrev(Table *arg)
 
129
  {
 
130
    prev= arg;
 
131
  }
76
132
 
77
133
  MyBitmap *read_set; /* Active column sets */
78
134
  MyBitmap *write_set; /* Active column sets */
90
146
    return in_use;
91
147
  }
92
148
 
 
149
  unsigned char *getInsertRecord()
 
150
  {
 
151
    return record[0];
 
152
  }
 
153
 
 
154
  unsigned char *getUpdateRecord()
 
155
  {
 
156
    return record[1];
 
157
  }
 
158
 
93
159
  unsigned char *record[2]; /**< Pointer to "records" */
94
 
  unsigned char *insert_values; /* used by INSERT ... UPDATE */
95
 
  KEY  *key_info; /**< data of keys in database */
 
160
  std::vector<unsigned char> insert_values; /* used by INSERT ... UPDATE */
 
161
  KeyInfo  *key_info; /**< data of keys in database */
96
162
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
97
163
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
98
164
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
99
165
 
100
166
  TableList *pos_in_table_list; /* Element referring to this table */
101
167
  order_st *group;
 
168
  
 
169
  const char *getAlias() const
 
170
  {
 
171
    return alias;
 
172
  }
 
173
 
102
174
  const char *alias; /**< alias or table name if no alias */
 
175
 
103
176
  unsigned char *null_flags;
104
177
 
105
178
  uint32_t lock_position; /**< Position in DRIZZLE_LOCK.table */
106
179
  uint32_t lock_data_start; /**< Start pos. in DRIZZLE_LOCK.locks */
107
180
  uint32_t lock_count; /**< Number of locks */
108
181
  uint32_t used_fields;
109
 
  uint32_t status; /* What's in record[0] */
 
182
  uint32_t status; /* What's in getInsertRecord() */
110
183
  /* number of select if it is derived table */
111
184
  uint32_t derived_select_number;
112
185
  int current_lock; /**< Type of lock on table */
126
199
  bool null_row;
127
200
 
128
201
  bool force_index;
129
 
  bool distinct,const_table,no_rows;
 
202
  bool distinct;
 
203
  bool const_table;
 
204
  bool no_rows;
130
205
  bool key_read;
131
206
  bool no_keyread;
132
207
  /*
241
316
  uint32_t quick_key_parts[MAX_KEY];
242
317
  uint32_t quick_n_ranges[MAX_KEY];
243
318
 
 
319
private:
244
320
  memory::Root mem_root;
 
321
 
 
322
  void init_mem_root()
 
323
  {
 
324
    init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
325
  }
 
326
public:
 
327
  memory::Root *getMemRoot()
 
328
  {
 
329
    if (not mem_root.alloc_root_inited())
 
330
    {
 
331
      init_mem_root();
 
332
    }
 
333
 
 
334
    return &mem_root;
 
335
  }
 
336
 
 
337
  void *alloc_root(size_t arg)
 
338
  {
 
339
    if (not mem_root.alloc_root_inited())
 
340
    {
 
341
      init_mem_root();
 
342
    }
 
343
 
 
344
    return mem_root.alloc_root(arg);
 
345
  }
 
346
 
 
347
  char *strmake_root(const char *str_arg, size_t len_arg)
 
348
  {
 
349
    if (not mem_root.alloc_root_inited())
 
350
    {
 
351
      init_mem_root();
 
352
    }
 
353
 
 
354
    return mem_root.strmake_root(str_arg, len_arg);
 
355
  }
 
356
 
245
357
  filesort_info_st sort;
246
358
 
247
359
  Table();
 
360
  virtual ~Table() { };
248
361
 
249
362
  int report_error(int error);
250
363
  /**
251
364
   * Free information allocated by openfrm
252
365
   *
253
366
   * @param If true if we also want to free table_share
 
367
   * @note this should all be the destructor
254
368
   */
255
 
  int closefrm(bool free_share);
 
369
  int delete_table(bool free_share= false);
256
370
 
257
371
  void resetTable(Session *session, TableShare *share, uint32_t db_stat_arg);
258
372
 
259
373
  /* SHARE methods */
260
374
  inline const TableShare *getShare() const { assert(s); return s; } /* Get rid of this long term */
 
375
  inline bool hasShare() const { return s ? true : false ; } /* Get rid of this long term */
 
376
  inline TableShare *getMutableShare() { assert(s); return s; } /* Get rid of this long term */
261
377
  inline void setShare(TableShare *new_share) { s= new_share; } /* Get rid of this long term */
262
 
  inline uint32_t sizeKeys() { return s->keys; }
263
 
  inline uint32_t sizeFields() { return s->fields; }
264
 
  inline uint32_t getRecordLength() { return s->reclength; }
 
378
  inline uint32_t sizeKeys() { return s->sizeKeys(); }
 
379
  inline uint32_t sizeFields() { return s->sizeFields(); }
 
380
  inline uint32_t getRecordLength() const { return s->getRecordLength(); }
265
381
  inline uint32_t sizeBlobFields() { return s->blob_fields; }
266
 
  inline uint32_t *getBlobField() { return s->blob_field; }
 
382
  inline uint32_t *getBlobField() { return &s->blob_field[0]; }
 
383
 
 
384
  Field_blob *getBlobFieldAt(uint32_t arg) const
 
385
  {
 
386
    if (arg < s->blob_fields)
 
387
      return (Field_blob*) field[s->blob_field[arg]]; /*NOTE: Using 'Table.field' NOT SharedTable.field. */
 
388
 
 
389
    return NULL;
 
390
  }
 
391
  inline uint8_t getBlobPtrSize() { return s->blob_ptr_size; }
267
392
  inline uint32_t getNullBytes() { return s->null_bytes; }
268
393
  inline uint32_t getNullFields() { return s->null_fields; }
269
 
  inline unsigned char *getDefaultValues() { return s->default_values; }
 
394
  inline unsigned char *getDefaultValues() { return  s->getDefaultValues(); }
 
395
  inline const char *getSchemaName()  const { return s->getSchemaName(); }
 
396
  inline const char *getTableName()  const { return s->getTableName(); }
270
397
 
271
398
  inline bool isDatabaseLowByteFirst() { return s->db_low_byte_first; } /* Portable row format */
272
 
  inline bool isNameLock() { return s->name_lock; }
 
399
  inline bool isNameLock() const { return s->isNameLock(); }
273
400
  inline bool isReplaceWithNameLock() { return s->replace_with_name_lock; }
274
 
  inline bool isWaitingOnCondition() { return s->waiting_on_cond; } /* Protection against free */
275
401
 
276
402
  uint32_t index_flags(uint32_t idx) const
277
403
  {
278
 
    return s->storage_engine->index_flags(s->key_info[idx].algorithm);
 
404
    return s->storage_engine->index_flags(s->getKeyInfo(idx).algorithm);
279
405
  }
280
406
 
281
 
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
 
407
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
282
408
  {
283
409
    return s->storage_engine;
284
410
  }
285
411
 
286
 
  Cursor &getCursor() const     /* table_type for handler */
 
412
  Cursor &getCursor() const /* table_type for handler */
287
413
  {
288
414
    assert(cursor);
289
415
    return *cursor;
290
416
  }
291
417
 
292
418
  /* For TMP tables, should be pulled out as a class */
293
 
  void updateCreateInfo(message::Table *table_proto);
294
419
  void setup_tmp_table_column_bitmaps(unsigned char *bitmaps);
295
 
  bool create_myisam_tmp_table(KEY *keyinfo,
 
420
  bool create_myisam_tmp_table(KeyInfo *keyinfo,
296
421
                               MI_COLUMNDEF *start_recinfo,
297
422
                               MI_COLUMNDEF **recinfo,
298
423
                               uint64_t options);
422
547
  */
423
548
  inline bool needs_reopen_or_name_lock()
424
549
  { 
425
 
    return s->version != refresh_version;
 
550
    return s->getVersion() != refresh_version;
426
551
  }
427
552
 
428
553
  /**
440
565
    memset(null_flags, 255, s->null_bytes);
441
566
  }
442
567
 
443
 
  bool rename_temporary_table(const char *db, const char *table_name);
444
568
  void free_io_cache();
445
569
  void filesort_free_buffers(bool full= false);
446
570
  void intern_close_table();
470
594
  */
471
595
  bool operator<(const Table &right) const
472
596
  {
473
 
    int result= strcmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
474
 
 
475
 
    if (result <  0)
476
 
      return true;
477
 
 
478
 
    if (result >  0)
479
 
      return false;
480
 
 
481
 
    result= strcmp(this->getShare()->getTableName(), right.getShare()->getTableName());
482
 
 
483
 
    if (result <  0)
484
 
      return true;
485
 
 
486
 
    if (result >  0)
487
 
      return false;
488
 
 
489
 
    if (this->getShare()->getTableProto()->type()  < 
490
 
        right.getShare()->getTableProto()->type())
 
597
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
 
598
 
 
599
    if (result <  0)
 
600
      return true;
 
601
 
 
602
    if (result >  0)
 
603
      return false;
 
604
 
 
605
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
 
606
 
 
607
    if (result <  0)
 
608
      return true;
 
609
 
 
610
    if (result >  0)
 
611
      return false;
 
612
 
 
613
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
491
614
      return true;
492
615
 
493
616
    return false;
511
634
    return output;  // for multiple << operators.
512
635
  }
513
636
 
 
637
protected:
 
638
  bool is_placeholder_created;
 
639
 
 
640
public:
 
641
  bool isPlaceHolder()
 
642
  {
 
643
    return is_placeholder_created;
 
644
  }
514
645
};
515
646
 
516
 
Table *create_virtual_tmp_table(Session *session, List<CreateField> &field_list);
517
 
 
518
 
typedef struct st_foreign_key_info
 
647
/**
 
648
 * @class
 
649
 *  ForeignKeyInfo
 
650
 *
 
651
 * @brief
 
652
 *  This class defines the information for foreign keys.
 
653
 */
 
654
class ForeignKeyInfo
519
655
{
520
 
  LEX_STRING *forein_id;
521
 
  LEX_STRING *referenced_db;
522
 
  LEX_STRING *referenced_table;
523
 
  LEX_STRING *update_method;
524
 
  LEX_STRING *delete_method;
525
 
  LEX_STRING *referenced_key_name;
526
 
  List<LEX_STRING> foreign_fields;
527
 
  List<LEX_STRING> referenced_fields;
528
 
} FOREIGN_KEY_INFO;
529
 
 
530
 
 
 
656
public:
 
657
    /**
 
658
     * @brief
 
659
     *  This is the constructor with all properties set.
 
660
     *
 
661
     * @param[in] in_foreign_id The id of the foreign key
 
662
     * @param[in] in_referenced_db The referenced database name of the foreign key
 
663
     * @param[in] in_referenced_table The referenced table name of the foreign key
 
664
     * @param[in] in_update_method The update method of the foreign key.
 
665
     * @param[in] in_delete_method The delete method of the foreign key.
 
666
     * @param[in] in_referenced_key_name The name of referenced key
 
667
     * @param[in] in_foreign_fields The foreign fields
 
668
     * @param[in] in_referenced_fields The referenced fields
 
669
     */
 
670
    ForeignKeyInfo(LEX_STRING *in_foreign_id,
 
671
                   LEX_STRING *in_referenced_db,
 
672
                   LEX_STRING *in_referenced_table,
 
673
                   LEX_STRING *in_update_method,
 
674
                   LEX_STRING *in_delete_method,
 
675
                   LEX_STRING *in_referenced_key_name,
 
676
                   List<LEX_STRING> in_foreign_fields,
 
677
                   List<LEX_STRING> in_referenced_fields)
 
678
    :
 
679
      foreign_id(in_foreign_id),
 
680
      referenced_db(in_referenced_db),
 
681
      referenced_table(in_referenced_table),
 
682
      update_method(in_update_method),
 
683
      delete_method(in_delete_method),
 
684
      referenced_key_name(in_referenced_key_name),
 
685
      foreign_fields(in_foreign_fields),
 
686
      referenced_fields(in_referenced_fields)
 
687
    {}
 
688
 
 
689
    /**
 
690
     * @brief
 
691
     *  This is the default constructor. All properties are set to default values for their types.
 
692
     */
 
693
    ForeignKeyInfo()
 
694
    : foreign_id(NULL), referenced_db(NULL), referenced_table(NULL),
 
695
      update_method(NULL), delete_method(NULL), referenced_key_name(NULL)
 
696
    {}
 
697
 
 
698
    /**
 
699
     * @brief
 
700
     *  Gets the foreign id.
 
701
     *
 
702
     * @ retval  the foreign id
 
703
     */
 
704
    const LEX_STRING *getForeignId() const
 
705
    {
 
706
        return foreign_id;
 
707
    }
 
708
 
 
709
    /**
 
710
     * @brief
 
711
     *  Gets the name of the referenced database.
 
712
     *
 
713
     * @ retval  the name of the referenced database
 
714
     */
 
715
    const LEX_STRING *getReferencedDb() const
 
716
    {
 
717
        return referenced_db;
 
718
    }
 
719
 
 
720
    /**
 
721
     * @brief
 
722
     *  Gets the name of the referenced table.
 
723
     *
 
724
     * @ retval  the name of the referenced table
 
725
     */
 
726
    const LEX_STRING *getReferencedTable() const
 
727
    {
 
728
        return referenced_table;
 
729
    }
 
730
 
 
731
    /**
 
732
     * @brief
 
733
     *  Gets the update method.
 
734
     *
 
735
     * @ retval  the update method
 
736
     */
 
737
    const LEX_STRING *getUpdateMethod() const
 
738
    {
 
739
        return update_method;
 
740
    }
 
741
 
 
742
    /**
 
743
     * @brief
 
744
     *  Gets the delete method.
 
745
     *
 
746
     * @ retval  the delete method
 
747
     */
 
748
    const LEX_STRING *getDeleteMethod() const
 
749
    {
 
750
        return delete_method;
 
751
    }
 
752
 
 
753
    /**
 
754
     * @brief
 
755
     *  Gets the name of the referenced key.
 
756
     *
 
757
     * @ retval  the name of the referenced key
 
758
     */
 
759
    const LEX_STRING *getReferencedKeyName() const
 
760
    {
 
761
        return referenced_key_name;
 
762
    }
 
763
 
 
764
    /**
 
765
     * @brief
 
766
     *  Gets the foreign fields.
 
767
     *
 
768
     * @ retval  the foreign fields
 
769
     */
 
770
    const List<LEX_STRING> &getForeignFields() const
 
771
    {
 
772
        return foreign_fields;
 
773
    }
 
774
 
 
775
    /**
 
776
     * @brief
 
777
     *  Gets the referenced fields.
 
778
     *
 
779
     * @ retval  the referenced fields
 
780
     */
 
781
    const List<LEX_STRING> &getReferencedFields() const
 
782
    {
 
783
        return referenced_fields;
 
784
    }
 
785
private:
 
786
    /**
 
787
     * The foreign id.
 
788
     */
 
789
    LEX_STRING *foreign_id;
 
790
    /**
 
791
     * The name of the reference database.
 
792
     */
 
793
    LEX_STRING *referenced_db;
 
794
    /**
 
795
     * The name of the reference table.
 
796
     */
 
797
    LEX_STRING *referenced_table;
 
798
    /**
 
799
     * The update method.
 
800
     */
 
801
    LEX_STRING *update_method;
 
802
    /**
 
803
     * The delete method.
 
804
     */
 
805
    LEX_STRING *delete_method;
 
806
    /**
 
807
     * The name of the referenced key.
 
808
     */
 
809
    LEX_STRING *referenced_key_name;
 
810
    /**
 
811
     * The foreign fields.
 
812
     */
 
813
    List<LEX_STRING> foreign_fields;
 
814
    /**
 
815
     * The referenced fields.
 
816
     */
 
817
    List<LEX_STRING> referenced_fields;
 
818
};
531
819
 
532
820
class TableList;
533
821
 
534
 
#define JOIN_TYPE_LEFT  1
535
 
#define JOIN_TYPE_RIGHT 2
 
822
#define JOIN_TYPE_LEFT  1
 
823
#define JOIN_TYPE_RIGHT 2
536
824
 
537
825
struct st_lex;
538
826
class select_union;
540
828
 
541
829
struct open_table_list_st
542
830
{
543
 
  std::string   db;
544
 
  std::string   table;
 
831
  std::string   db;
 
832
  std::string   table;
545
833
  uint32_t in_use;
546
834
  uint32_t locked;
547
835
 
552
840
 
553
841
};
554
842
 
555
 
TableShare *alloc_table_share(TableList *table_list, char *key,
556
 
                               uint32_t key_length);
557
 
int open_table_def(Session& session, TableShare *share);
558
 
void open_table_error(TableShare *share, int error, int db_errno, int errarg);
559
 
int open_table_from_share(Session *session, TableShare *share, const char *alias,
560
 
                          uint32_t db_stat, uint32_t ha_open_flags,
561
 
                          Table *outparam);
562
843
void free_blobs(Table *table);
563
844
int set_zone(int nr,int min_zone,int max_zone);
564
845
uint32_t convert_period_to_month(uint32_t period);
571
852
 
572
853
ha_rows filesort(Session *session,
573
854
                 Table *form,
574
 
                 st_sort_field *sortorder,
 
855
                 SortField *sortorder,
575
856
                 uint32_t s_length,
576
857
                 optimizer::SqlSelect *select,
577
858
                 ha_rows max_rows,
593
874
 
594
875
int rename_file_ext(const char * from,const char * to,const char * ext);
595
876
bool check_column_name(const char *name);
596
 
bool check_db_name(LEX_STRING *org_name);
 
877
bool check_db_name(Session *session, SchemaIdentifier &schema);
597
878
bool check_table_name(const char *name, uint32_t length);
598
879
 
599
880
} /* namespace drizzled */