~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2008-08-19 15:11:04 UTC
  • mfrom: (327.2.6 drizzle-good)
  • Revision ID: brian@gir.tangent.org-20080819151104-uxk5lgoaj0fwgx9z
Merge of Brian's tree to main tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#define DRIZZLED_TABLE_H
21
21
 
22
22
#include <storage/myisam/myisam.h>
 
23
#include <drizzled/order.h>
 
24
#include <drizzled/filesort_info.h>
 
25
#include <drizzled/natural_join_column.h>
 
26
#include <drizzled/nested_join.h>
23
27
 
24
 
class Item;                             /* Needed by ORDER */
 
28
class Item;                             /* Needed by order_st */
25
29
class Item_subselect;
26
30
class st_select_lex_unit;
27
31
class st_select_lex;
28
32
class COND_EQUAL;
29
33
class Security_context;
30
 
class TABLE_LIST;
 
34
class TableList;
31
35
 
32
36
/*************************************************************************/
33
37
 
34
 
/* Order clause list element */
35
 
 
36
 
typedef struct st_order {
37
 
  struct st_order *next;
38
 
  Item   **item;                        /* Point at item in select fields */
39
 
  Item   *item_ptr;                     /* Storage for initial item */
40
 
  Item   **item_copy;                   /* For SPs; the original item ptr */
41
 
  int    counter;                       /* position in SELECT list, correct
42
 
                                           only if counter_used is true*/
43
 
  bool   asc;                           /* true if ascending */
44
 
  bool   free_me;                       /* true if item isn't shared  */
45
 
  bool   in_field_list;                 /* true if in select field list */
46
 
  bool   counter_used;                  /* parameter was counter of columns */
47
 
  Field  *field;                        /* If tmp-table group */
48
 
  char   *buff;                         /* If tmp-table group */
49
 
  table_map used, depend_map;
50
 
} ORDER;
51
 
 
52
38
enum tmp_table_type
53
39
{
54
40
  NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
60
46
 
61
47
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
62
48
 
63
 
typedef struct st_filesort_info
64
 
{
65
 
  IO_CACHE *io_cache;           /* If sorted through filesort */
66
 
  uchar     **sort_keys;        /* Buffer for sorting keys */
67
 
  uchar     *buffpek;           /* Buffer for buffpek structures */
68
 
  uint      buffpek_len;        /* Max number of buffpeks in the buffer */
69
 
  uchar     *addon_buf;         /* Pointer to a buffer if sorted with fields */
70
 
  size_t    addon_length;       /* Length of the buffer */
71
 
  struct st_sort_addon_field *addon_field;     /* Pointer to the fields info */
72
 
  void    (*unpack)(struct st_sort_addon_field *, uchar *); /* To unpack back */
73
 
  uchar     *record_pointers;    /* If sorted in memory */
74
 
  ha_rows   found_records;      /* How many records in sort */
75
 
} FILESORT_INFO;
76
 
 
77
 
 
78
49
/*
79
50
  Values in this enum are used to indicate how a tables TIMESTAMP field
80
51
  should be treated. It can be set to the current timestamp on insert or
349
320
  INDEX_HINT_FORCE
350
321
};
351
322
 
 
323
typedef struct st_table_field_w_type
 
324
{
 
325
  LEX_STRING name;
 
326
  LEX_STRING type;
 
327
  LEX_STRING cset;
 
328
} TABLE_FIELD_W_TYPE;
 
329
 
352
330
bool create_myisam_from_heap(THD *thd, Table *table,
353
331
                             MI_COLUMNDEF *start_recinfo,
354
332
                             MI_COLUMNDEF **recinfo, 
389
367
  void free_tmp_table(THD *thd);
390
368
  bool open_tmp_table();
391
369
 
 
370
  bool table_check_intact(const uint table_f_count, const TABLE_FIELD_W_TYPE *table_def);
 
371
 
392
372
  /* See if this can be blown away */
393
373
  inline uint getDBStat () { return db_stat; }
394
374
  inline uint setDBStat () { return db_stat; }
432
412
  Field *found_next_number_field;       /* Set on open */
433
413
  Field_timestamp *timestamp_field;
434
414
 
435
 
  TABLE_LIST *pos_in_table_list;/* Element referring to this table */
436
 
  ORDER         *group;
 
415
  TableList *pos_in_table_list;/* Element referring to this table */
 
416
  order_st *group;
437
417
  const char    *alias;                   /* alias or table name */
438
418
  uchar         *null_flags;
439
419
  my_bitmap_map *bitmap_init_value;
559
539
 
560
540
  REGINFO reginfo;                      /* field connections */
561
541
  MEM_ROOT mem_root;
562
 
  FILESORT_INFO sort;
 
542
  filesort_info_st sort;
563
543
 
564
544
  bool fill_item_list(List<Item> *item_list) const;
565
545
  void reset_item_list(List<Item> *item_list) const;
689
669
} ST_FIELD_INFO;
690
670
 
691
671
 
692
 
class TABLE_LIST;
 
672
class TableList;
693
673
typedef class Item COND;
694
674
 
695
675
struct ST_SCHEMA_TABLE
697
677
  const char* table_name;
698
678
  ST_FIELD_INFO *fields_info;
699
679
  /* Create information_schema table */
700
 
  Table *(*create_table)  (THD *thd, TABLE_LIST *table_list);
 
680
  Table *(*create_table)  (THD *thd, TableList *table_list);
701
681
  /* Fill table with data */
702
 
  int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond);
 
682
  int (*fill_table) (THD *thd, TableList *tables, COND *cond);
703
683
  /* Handle fileds for old SHOW */
704
684
  int (*old_format) (THD *thd, struct ST_SCHEMA_TABLE *schema_table);
705
 
  int (*process_table) (THD *thd, TABLE_LIST *tables, Table *table,
 
685
  int (*process_table) (THD *thd, TableList *tables, Table *table,
706
686
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
707
687
  int idx_field1, idx_field2; 
708
688
  bool hidden;
717
697
class select_union;
718
698
class TMP_TABLE_PARAM;
719
699
 
720
 
Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
721
 
                        const char *name);
722
 
 
723
700
struct Field_translator
724
701
{
725
702
  Item *item;
728
705
 
729
706
 
730
707
/*
731
 
  Column reference of a NATURAL/USING join. Since column references in
732
 
  joins can be both from views and stored tables, may point to either a
733
 
  Field (for tables), or a Field_translator (for views).
734
 
*/
735
 
 
736
 
class Natural_join_column: public Sql_alloc
737
 
{
738
 
public:
739
 
  Field_translator *view_field;  /* Column reference of merge view. */
740
 
  Field            *table_field; /* Column reference of table or temp view. */
741
 
  TABLE_LIST *table_ref; /* Original base table/view reference. */
742
 
  /*
743
 
    True if a common join column of two NATURAL/USING join operands. Notice
744
 
    that when we have a hierarchy of nested NATURAL/USING joins, a column can
745
 
    be common at some level of nesting but it may not be common at higher
746
 
    levels of nesting. Thus this flag may change depending on at which level
747
 
    we are looking at some column.
748
 
  */
749
 
  bool is_common;
750
 
public:
751
 
  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
752
 
  Natural_join_column(Field *field_param, TABLE_LIST *tab);
753
 
  const char *name();
754
 
  Item *create_item(THD *thd);
755
 
  Field *field();
756
 
  const char *table_name();
757
 
  const char *db_name();
758
 
};
759
 
 
760
 
 
761
 
/*
762
708
  Table reference in the FROM clause.
763
709
 
764
710
  These table references can be of several types that correspond to
765
 
  different SQL elements. Below we list all types of TABLE_LISTs with
766
 
  the necessary conditions to determine when a TABLE_LIST instance
 
711
  different SQL elements. Below we list all types of TableLists with
 
712
  the necessary conditions to determine when a TableList instance
767
713
  belongs to a certain type.
768
714
 
769
 
  1) table (TABLE_LIST::view == NULL)
 
715
  1) table (TableList::view == NULL)
770
716
     - base table
771
 
       (TABLE_LIST::derived == NULL)
772
 
     - subquery - TABLE_LIST::table is a temp table
773
 
       (TABLE_LIST::derived != NULL)
 
717
       (TableList::derived == NULL)
 
718
     - subquery - TableList::table is a temp table
 
719
       (TableList::derived != NULL)
774
720
     - information schema table
775
 
       (TABLE_LIST::schema_table != NULL)
776
 
       NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
777
 
  2) view (TABLE_LIST::view != NULL)
778
 
     - merge    (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
779
 
           also (TABLE_LIST::field_translation != NULL)
780
 
     - tmptable (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
781
 
           also (TABLE_LIST::field_translation == NULL)
782
 
  3) nested table reference (TABLE_LIST::nested_join != NULL)
 
721
       (TableList::schema_table != NULL)
 
722
       NOTICE: for schema tables TableList::field_translation may be != NULL
 
723
  2) view (TableList::view != NULL)
 
724
     - merge    (TableList::effective_algorithm == VIEW_ALGORITHM_MERGE)
 
725
           also (TableList::field_translation != NULL)
 
726
     - tmptable (TableList::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
 
727
           also (TableList::field_translation == NULL)
 
728
  3) nested table reference (TableList::nested_join != NULL)
783
729
     - table sequence - e.g. (t1, t2, t3)
784
730
       TODO: how to distinguish from a JOIN?
785
731
     - general JOIN
786
732
       TODO: how to distinguish from a table sequence?
787
733
     - NATURAL JOIN
788
 
       (TABLE_LIST::natural_join != NULL)
 
734
       (TableList::natural_join != NULL)
789
735
       - JOIN ... USING
790
 
         (TABLE_LIST::join_using_fields != NULL)
 
736
         (TableList::join_using_fields != NULL)
791
737
     - semi-join
792
738
       ;
793
739
*/
803
749
public:
804
750
  Field_iterator() {}                         /* Remove gcc warning */
805
751
  virtual ~Field_iterator() {}
806
 
  virtual void set(TABLE_LIST *)= 0;
 
752
  virtual void set(TableList *)= 0;
807
753
  virtual void next()= 0;
808
754
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
809
755
  virtual const char *name()= 0;
817
763
  table, or subquery.
818
764
*/
819
765
 
820
 
class TABLE_LIST;
 
766
class TableList;
821
767
class Field_iterator_table: public Field_iterator
822
768
{
823
769
  Field **ptr;
824
770
public:
825
771
  Field_iterator_table() :ptr(0) {}
826
 
  void set(TABLE_LIST *table);
 
772
  void set(TableList *table);
827
773
  void set_table(Table *table) { ptr= table->field; }
828
774
  void next() { ptr++; }
829
775
  bool end_of_fields() { return *ptr == 0; }
835
781
 
836
782
/* Iterator over the fields of a merge view. */
837
783
 
838
 
class Field_iterator_view: public Field_iterator
839
 
{
840
 
  Field_translator *ptr, *array_end;
841
 
  TABLE_LIST *view;
842
 
public:
843
 
  Field_iterator_view() :ptr(0), array_end(0) {}
844
 
  void set(TABLE_LIST *table);
845
 
  void next() { ptr++; }
846
 
  bool end_of_fields() { return ptr == array_end; }
847
 
  const char *name();
848
 
  Item *create_item(THD *thd);
849
 
  Item **item_ptr() {return &ptr->item; }
850
 
  Field *field() { return 0; }
851
 
  inline Item *item() { return ptr->item; }
852
 
  Field_translator *field_translator() { return ptr; }
853
 
};
854
 
 
855
 
 
856
784
/*
857
785
  Field_iterator interface to the list of materialized fields of a
858
786
  NATURAL/USING join.
865
793
public:
866
794
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
867
795
  ~Field_iterator_natural_join() {}
868
 
  void set(TABLE_LIST *table);
 
796
  void set(TableList *table);
869
797
  void next();
870
798
  bool end_of_fields() { return !cur_column_ref; }
871
799
  const char *name() { return cur_column_ref->name(); }
888
816
  IMPLEMENTATION
889
817
    The implementation assumes that all underlying NATURAL/USING table
890
818
    references already contain their result columns and are linked into
891
 
    the list TABLE_LIST::next_name_resolution_table.
 
819
    the list TableList::next_name_resolution_table.
892
820
*/
893
821
 
894
822
class Field_iterator_table_ref: public Field_iterator
895
823
{
896
 
  TABLE_LIST *table_ref, *first_leaf, *last_leaf;
 
824
  TableList *table_ref, *first_leaf, *last_leaf;
897
825
  Field_iterator_table        table_field_it;
898
 
  Field_iterator_view         view_field_it;
899
826
  Field_iterator_natural_join natural_join_it;
900
827
  Field_iterator *field_it;
901
828
  void set_field_iterator();
902
829
public:
903
830
  Field_iterator_table_ref() :field_it(NULL) {}
904
 
  void set(TABLE_LIST *table);
 
831
  void set(TableList *table);
905
832
  void next();
906
833
  bool end_of_fields()
907
834
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
910
837
  const char *db_name();
911
838
  Item *create_item(THD *thd) { return field_it->create_item(thd); }
912
839
  Field *field() { return field_it->field(); }
913
 
  Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref);
 
840
  Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
914
841
  Natural_join_column *get_natural_column_ref();
915
842
};
916
843
 
917
844
 
918
 
typedef struct st_nested_join
919
 
{
920
 
  List<TABLE_LIST>  join_list;       /* list of elements in the nested join */
921
 
  table_map         used_tables;     /* bitmap of tables in the nested join */
922
 
  table_map         not_null_tables; /* tables that rejects nulls           */
923
 
  struct st_join_table *first_nested;/* the first nested table in the plan  */
924
 
  /* 
925
 
    Used to count tables in the nested join in 2 isolated places:
926
 
    1. In make_outerjoin_info(). 
927
 
    2. check_interleaving_with_nj/restore_prev_nj_state (these are called
928
 
       by the join optimizer. 
929
 
    Before each use the counters are zeroed by reset_nj_counters.
930
 
  */
931
 
  uint              counter_;
932
 
  nested_join_map   nj_map;          /* Bit used to identify this nested join*/
933
 
  /*
934
 
    (Valid only for semi-join nests) Bitmap of tables outside the semi-join
935
 
    that are used within the semi-join's ON condition.
936
 
  */
937
 
  table_map         sj_depends_on;
938
 
  /* Outer non-trivially correlated tables */
939
 
  table_map         sj_corr_tables;
940
 
  List<Item>        sj_outer_expr_list;
941
 
} NESTED_JOIN;
942
 
 
943
 
 
944
845
typedef struct st_changed_table_list
945
846
{
946
847
  struct        st_changed_table_list *next;
947
848
  char          *key;
948
849
  uint32_t        key_length;
949
 
} CHANGED_TABLE_LIST;
950
 
 
951
 
 
952
 
typedef struct st_open_table_list{
 
850
} CHANGED_TableList;
 
851
 
 
852
 
 
853
typedef struct st_open_table_list
 
854
{
953
855
  struct st_open_table_list *next;
954
856
  char  *db,*table;
955
857
  uint32_t in_use,locked;
956
 
} OPEN_TABLE_LIST;
957
 
 
958
 
typedef struct st_table_field_w_type
959
 
{
960
 
  LEX_STRING name;
961
 
  LEX_STRING type;
962
 
  LEX_STRING cset;
963
 
} TABLE_FIELD_W_TYPE;
964
 
 
965
 
 
966
 
bool
967
 
table_check_intact(Table *table, const uint table_f_count,
968
 
                   const TABLE_FIELD_W_TYPE *table_def);
 
858
} OPEN_TableList;
 
859
 
969
860
 
970
861
static inline my_bitmap_map *tmp_use_all_columns(Table *table,
971
862
                                                 MY_BITMAP *bitmap)
982
873
  bitmap->bitmap= old;
983
874
}
984
875
 
985
 
/* The following is only needed for debugging */
986
 
 
987
 
static inline my_bitmap_map *dbug_tmp_use_all_columns(Table *table __attribute__((unused)),
988
 
                                                      MY_BITMAP *bitmap __attribute__((unused)))
989
 
{
990
 
  return 0;
991
 
}
992
 
 
993
 
static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap __attribute__((unused)),
994
 
                                               my_bitmap_map *old __attribute__((unused)))
995
 
{
996
 
  return;
997
 
}
998
 
 
999
876
size_t max_row_length(Table *table, const uchar *data);
1000
877
 
1001
878
#endif /* DRIZZLED_TABLE_H */