~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
20
20
 
21
21
/* Structs that defines the Table */
22
22
 
23
 
 
24
 
 
25
23
#ifndef DRIZZLED_TABLE_H
26
24
#define DRIZZLED_TABLE_H
27
25
 
35
33
#include "drizzled/cursor.h"
36
34
#include "drizzled/lex_string.h"
37
35
#include "drizzled/table_list.h"
38
 
#include "drizzled/table/instance.h"
 
36
#include "drizzled/definition/table.h"
39
37
#include "drizzled/atomics.h"
40
38
#include "drizzled/query_id.h"
41
39
 
42
 
#include "drizzled/visibility.h"
43
 
 
44
40
namespace drizzled
45
41
{
46
42
 
47
 
class COND_EQUAL;
48
 
class Field_blob;
49
43
class Item;
50
44
class Item_subselect;
 
45
class Select_Lex_Unit;
 
46
class Select_Lex;
 
47
class COND_EQUAL;
51
48
class SecurityContext;
52
 
class Select_Lex;
53
 
class Select_Lex_Unit;
54
49
class TableList;
55
 
namespace field { class Epoch; }
56
 
namespace plugin { class StorageEngine; }
 
50
class Field_timestamp;
 
51
class Field_blob;
 
52
 
 
53
extern uint64_t refresh_version;
57
54
 
58
55
typedef enum enum_table_category TABLE_CATEGORY;
59
56
typedef struct st_columndef MI_COLUMNDEF;
62
59
 * Class representing a set of records, either in a temporary, 
63
60
 * normal, or derived table.
64
61
 */
65
 
class DRIZZLED_API Table 
 
62
class Table 
66
63
{
67
64
  Field **field; /**< Pointer to fields collection */
 
65
public:
68
66
 
69
 
public:
70
67
  Field **getFields() const
71
68
  {
72
69
    return field;
88
85
  }
89
86
 
90
87
  Cursor *cursor; /**< Pointer to the storage engine's Cursor managing this table */
91
 
 
92
88
private:
93
89
  Table *next;
94
 
 
95
90
public:
96
91
  Table *getNext() const
97
92
  {
148
143
    return in_use;
149
144
  }
150
145
 
151
 
  unsigned char *getInsertRecord() const
 
146
  unsigned char *getInsertRecord()
152
147
  {
153
148
    return record[0];
154
149
  }
163
158
  KeyInfo  *key_info; /**< data of keys in database */
164
159
  Field *next_number_field; /**< Set if next_number is activated. @TODO What the heck is the difference between this and the next member? */
165
160
  Field *found_next_number_field; /**< Points to the "next-number" field (autoincrement field) */
166
 
  field::Epoch *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
 
161
  Field_timestamp *timestamp_field; /**< Points to the auto-setting timestamp field, if any */
167
162
 
168
163
  TableList *pos_in_table_list; /* Element referring to this table */
169
 
  Order *group;
 
164
  order_st *group;
170
165
  
171
166
  const char *getAlias() const
172
167
  {
285
280
    statement then the variable contains TIMESTAMP_NO_AUTO_SET (i.e. 0).
286
281
 
287
282
    Value of this variable is set for each statement in open_table() and
288
 
    if needed cleared later in statement processing code (see update_query()
 
283
    if needed cleared later in statement processing code (see mysql_update()
289
284
    as example).
290
285
  */
291
286
  timestamp_auto_set_type timestamp_field_type;
313
308
    The set is implemented as a bitmap.
314
309
  */
315
310
  key_map keys_in_use_for_query;
316
 
 
317
311
  /* Map of keys that can be used to calculate GROUP BY without sorting */
318
312
  key_map keys_in_use_for_group_by;
319
 
 
320
313
  /* Map of keys that can be used to calculate ORDER BY without sorting */
321
314
  key_map keys_in_use_for_order_by;
322
315
 
392
385
  virtual bool hasShare() const= 0; /* Get rid of this long term */
393
386
  virtual void setShare(TableShare *new_share)= 0; /* Get rid of this long term */
394
387
 
395
 
  virtual void release(void)= 0;
396
 
 
397
388
  uint32_t sizeKeys() { return getMutableShare()->sizeKeys(); }
398
389
  uint32_t sizeFields() { return getMutableShare()->sizeFields(); }
399
390
  uint32_t getRecordLength() const { return getShare()->getRecordLength(); }
415
406
 
416
407
    return NULL;
417
408
  }
418
 
  inline uint8_t getBlobPtrSize() const { return getShare()->sizeBlobPtr(); }
419
 
  inline uint32_t getNullBytes() const { return getShare()->null_bytes; }
420
 
  inline uint32_t getNullFields() const { return getShare()->null_fields; }
 
409
  inline uint8_t getBlobPtrSize() { return getShare()->blob_ptr_size; }
 
410
  inline uint32_t getNullBytes() { return getShare()->null_bytes; }
 
411
  inline uint32_t getNullFields() { return getShare()->null_fields; }
421
412
  inline unsigned char *getDefaultValues() { return  getMutableShare()->getDefaultValues(); }
422
413
  inline const char *getSchemaName()  const { return getShare()->getSchemaName(); }
423
414
  inline const char *getTableName()  const { return getShare()->getTableName(); }
424
415
 
425
 
  inline bool isDatabaseLowByteFirst() const { return getShare()->db_low_byte_first; } /* Portable row format */
426
 
  inline bool isNameLock() const { return open_placeholder; }
 
416
  inline bool isDatabaseLowByteFirst() { return getShare()->db_low_byte_first; } /* Portable row format */
 
417
  inline bool isNameLock() const { return getShare()->isNameLock(); }
 
418
  inline bool isReplaceWithNameLock() { return getShare()->replace_with_name_lock; }
427
419
 
428
 
  uint32_t index_flags(uint32_t idx) const;
 
420
  uint32_t index_flags(uint32_t idx) const
 
421
  {
 
422
    return getShare()->storage_engine->index_flags(getShare()->getKeyInfo(idx).algorithm);
 
423
  }
429
424
 
430
425
  inline plugin::StorageEngine *getEngine() const   /* table_type for handler */
431
426
  {
432
 
    return getShare()->getEngine();
 
427
    return getShare()->storage_engine;
433
428
  }
434
429
 
435
430
  Cursor &getCursor() const /* table_type for handler */
441
436
  size_t max_row_length(const unsigned char *data);
442
437
  uint32_t find_shortest_key(const key_map *usable_keys);
443
438
  bool compare_record(Field **ptr);
444
 
  bool records_are_comparable();
445
 
  bool compare_records();
 
439
  bool compare_record();
446
440
  /* TODO: the (re)storeRecord's may be able to be further condensed */
447
441
  void storeRecord();
448
442
  void storeRecordAsInsert();
451
445
  void restoreRecordAsDefault();
452
446
  void emptyRecord();
453
447
 
454
 
 
455
448
  /* See if this can be blown away */
456
449
  inline uint32_t getDBStat () { return db_stat; }
457
450
  inline uint32_t setDBStat () { return db_stat; }
555
548
  {
556
549
    return db_stat || open_placeholder;
557
550
  }
558
 
 
559
551
  /*
560
552
    Is this instance of the table should be reopen or represents a name-lock?
561
553
  */
562
 
  bool needs_reopen_or_name_lock() const;
 
554
  inline bool needs_reopen_or_name_lock()
 
555
  { 
 
556
    return getShare()->getVersion() != refresh_version;
 
557
  }
563
558
 
564
559
  /**
565
560
    clean/setup table fields and map.
580
575
  void filesort_free_buffers(bool full= false);
581
576
  void intern_close_table();
582
577
 
583
 
  void print_error(int error, myf errflag) const;
 
578
  void print_error(int error, myf errflag)
 
579
  {
 
580
    getShare()->storage_engine->print_error(error, errflag, *this);
 
581
  }
584
582
 
585
583
  /**
586
584
    @return
587
585
    key if error because of duplicated keys
588
586
  */
589
 
  uint32_t get_dup_key(int error) const
 
587
  uint32_t get_dup_key(int error)
590
588
  {
591
589
    cursor->errkey  = (uint32_t) -1;
592
590
    if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
602
600
  */
603
601
  bool operator<(const Table &right) const
604
602
  {
605
 
    return getShare()->getCacheKey() < right.getShare()->getCacheKey();
 
603
    int result= strcasecmp(this->getShare()->getSchemaName(), right.getShare()->getSchemaName());
 
604
 
 
605
    if (result <  0)
 
606
      return true;
 
607
 
 
608
    if (result >  0)
 
609
      return false;
 
610
 
 
611
    result= strcasecmp(this->getShare()->getTableName(), right.getShare()->getTableName());
 
612
 
 
613
    if (result <  0)
 
614
      return true;
 
615
 
 
616
    if (result >  0)
 
617
      return false;
 
618
 
 
619
    if (this->getShare()->getTableProto()->type()  < right.getShare()->getTableProto()->type())
 
620
      return true;
 
621
 
 
622
    return false;
606
623
  }
607
624
 
608
625
  static bool compare(const Table *a, const Table *b)
612
629
 
613
630
  friend std::ostream& operator<<(std::ostream& output, const Table &table)
614
631
  {
615
 
    if (table.getShare())
616
 
    {
617
 
      output << "Table:(";
618
 
      output << table.getShare()->getSchemaName();
619
 
      output << ", ";
620
 
      output <<  table.getShare()->getTableName();
621
 
      output << ", ";
622
 
      output <<  table.getShare()->getTableTypeAsString();
623
 
      output << ")";
624
 
    }
625
 
    else
626
 
    {
627
 
      output << "Table:(has no share)";
628
 
    }
 
632
    output << "Table:(";
 
633
    output << table.getShare()->getSchemaName();
 
634
    output << ", ";
 
635
    output <<  table.getShare()->getTableName();
 
636
    output << ", ";
 
637
    output <<  table.getShare()->getTableTypeAsString();
 
638
    output << ")";
629
639
 
630
640
    return output;  // for multiple << operators.
631
641
  }
829
839
 
830
840
namespace optimizer { class SqlSelect; }
831
841
 
 
842
ha_rows filesort(Session *session,
 
843
                 Table *form,
 
844
                 SortField *sortorder,
 
845
                 uint32_t s_length,
 
846
                 optimizer::SqlSelect *select,
 
847
                 ha_rows max_rows,
 
848
                 bool sort_positions,
 
849
                 ha_rows *examined_rows);
 
850
 
 
851
void filesort_free_buffers(Table *table, bool full);
832
852
void change_double_for_sort(double nr,unsigned char *to);
 
853
double my_double_round(double value, int64_t dec, bool dec_unsigned,
 
854
                       bool truncate);
833
855
int get_quick_record(optimizer::SqlSelect *select);
834
856
 
835
857
void find_date(char *pos,uint32_t *vek,uint32_t flag);
836
858
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
837
859
TYPELIB *typelib(memory::Root *mem_root, List<String> &strings);
838
860
ulong get_form_pos(int file, unsigned char *head, TYPELIB *save_names);
 
861
ulong next_io_size(ulong pos);
839
862
void append_unescaped(String *res, const char *pos, uint32_t length);
840
863
 
841
 
DRIZZLED_API int rename_file_ext(const char * from,const char * to,const char * ext);
 
864
int rename_file_ext(const char * from,const char * to,const char * ext);
842
865
bool check_column_name(const char *name);
843
 
bool check_db_name(Session *session, identifier::Schema &schema);
 
866
bool check_db_name(Session *session, SchemaIdentifier &schema);
844
867
bool check_table_name(const char *name, uint32_t length);
845
868
 
846
869
} /* namespace drizzled */
847
870
 
848
 
#include "drizzled/table/singular.h"
 
871
#include "drizzled/table/instance.h"
849
872
#include "drizzled/table/concurrent.h"
850
873
 
851
874
#endif /* DRIZZLED_TABLE_H */