~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2008-08-18 22:20:43 UTC
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: brian@tangent.org-20080818222043-et6zf93ogrgx1cz9
Refactoring table.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <storage/myisam/myisam.h>
23
23
#include <drizzled/order.h>
24
24
#include <drizzled/filesort_info.h>
 
25
#include <drizzled/natural_join_column.h>
 
26
#include <drizzled/nested_join.h>
25
27
 
26
28
class Item;                             /* Needed by order_st */
27
29
class Item_subselect;
29
31
class st_select_lex;
30
32
class COND_EQUAL;
31
33
class Security_context;
32
 
class TABLE_LIST;
 
34
class TableList;
33
35
 
34
36
/*************************************************************************/
35
37
 
410
412
  Field *found_next_number_field;       /* Set on open */
411
413
  Field_timestamp *timestamp_field;
412
414
 
413
 
  TABLE_LIST *pos_in_table_list;/* Element referring to this table */
 
415
  TableList *pos_in_table_list;/* Element referring to this table */
414
416
  order_st *group;
415
417
  const char    *alias;                   /* alias or table name */
416
418
  uchar         *null_flags;
667
669
} ST_FIELD_INFO;
668
670
 
669
671
 
670
 
class TABLE_LIST;
 
672
class TableList;
671
673
typedef class Item COND;
672
674
 
673
675
struct ST_SCHEMA_TABLE
675
677
  const char* table_name;
676
678
  ST_FIELD_INFO *fields_info;
677
679
  /* Create information_schema table */
678
 
  Table *(*create_table)  (THD *thd, TABLE_LIST *table_list);
 
680
  Table *(*create_table)  (THD *thd, TableList *table_list);
679
681
  /* Fill table with data */
680
 
  int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond);
 
682
  int (*fill_table) (THD *thd, TableList *tables, COND *cond);
681
683
  /* Handle fileds for old SHOW */
682
684
  int (*old_format) (THD *thd, struct ST_SCHEMA_TABLE *schema_table);
683
 
  int (*process_table) (THD *thd, TABLE_LIST *tables, Table *table,
 
685
  int (*process_table) (THD *thd, TableList *tables, Table *table,
684
686
                        bool res, LEX_STRING *db_name, LEX_STRING *table_name);
685
687
  int idx_field1, idx_field2; 
686
688
  bool hidden;
695
697
class select_union;
696
698
class TMP_TABLE_PARAM;
697
699
 
698
 
Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
 
700
Item *create_view_field(THD *thd, TableList *view, Item **field_ref,
699
701
                        const char *name);
700
702
 
701
703
struct Field_translator
706
708
 
707
709
 
708
710
/*
709
 
  Column reference of a NATURAL/USING join. Since column references in
710
 
  joins can be both from views and stored tables, may point to either a
711
 
  Field (for tables), or a Field_translator (for views).
712
 
*/
713
 
 
714
 
class Natural_join_column: public Sql_alloc
715
 
{
716
 
public:
717
 
  Field_translator *view_field;  /* Column reference of merge view. */
718
 
  Field            *table_field; /* Column reference of table or temp view. */
719
 
  TABLE_LIST *table_ref; /* Original base table/view reference. */
720
 
  /*
721
 
    True if a common join column of two NATURAL/USING join operands. Notice
722
 
    that when we have a hierarchy of nested NATURAL/USING joins, a column can
723
 
    be common at some level of nesting but it may not be common at higher
724
 
    levels of nesting. Thus this flag may change depending on at which level
725
 
    we are looking at some column.
726
 
  */
727
 
  bool is_common;
728
 
public:
729
 
  Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
730
 
  Natural_join_column(Field *field_param, TABLE_LIST *tab);
731
 
  const char *name();
732
 
  Item *create_item(THD *thd);
733
 
  Field *field();
734
 
  const char *table_name();
735
 
  const char *db_name();
736
 
};
737
 
 
738
 
 
739
 
/*
740
711
  Table reference in the FROM clause.
741
712
 
742
713
  These table references can be of several types that correspond to
743
 
  different SQL elements. Below we list all types of TABLE_LISTs with
744
 
  the necessary conditions to determine when a TABLE_LIST instance
 
714
  different SQL elements. Below we list all types of TableLists with
 
715
  the necessary conditions to determine when a TableList instance
745
716
  belongs to a certain type.
746
717
 
747
 
  1) table (TABLE_LIST::view == NULL)
 
718
  1) table (TableList::view == NULL)
748
719
     - base table
749
 
       (TABLE_LIST::derived == NULL)
750
 
     - subquery - TABLE_LIST::table is a temp table
751
 
       (TABLE_LIST::derived != NULL)
 
720
       (TableList::derived == NULL)
 
721
     - subquery - TableList::table is a temp table
 
722
       (TableList::derived != NULL)
752
723
     - information schema table
753
 
       (TABLE_LIST::schema_table != NULL)
754
 
       NOTICE: for schema tables TABLE_LIST::field_translation may be != NULL
755
 
  2) view (TABLE_LIST::view != NULL)
756
 
     - merge    (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_MERGE)
757
 
           also (TABLE_LIST::field_translation != NULL)
758
 
     - tmptable (TABLE_LIST::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
759
 
           also (TABLE_LIST::field_translation == NULL)
760
 
  3) nested table reference (TABLE_LIST::nested_join != NULL)
 
724
       (TableList::schema_table != NULL)
 
725
       NOTICE: for schema tables TableList::field_translation may be != NULL
 
726
  2) view (TableList::view != NULL)
 
727
     - merge    (TableList::effective_algorithm == VIEW_ALGORITHM_MERGE)
 
728
           also (TableList::field_translation != NULL)
 
729
     - tmptable (TableList::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
 
730
           also (TableList::field_translation == NULL)
 
731
  3) nested table reference (TableList::nested_join != NULL)
761
732
     - table sequence - e.g. (t1, t2, t3)
762
733
       TODO: how to distinguish from a JOIN?
763
734
     - general JOIN
764
735
       TODO: how to distinguish from a table sequence?
765
736
     - NATURAL JOIN
766
 
       (TABLE_LIST::natural_join != NULL)
 
737
       (TableList::natural_join != NULL)
767
738
       - JOIN ... USING
768
 
         (TABLE_LIST::join_using_fields != NULL)
 
739
         (TableList::join_using_fields != NULL)
769
740
     - semi-join
770
741
       ;
771
742
*/
781
752
public:
782
753
  Field_iterator() {}                         /* Remove gcc warning */
783
754
  virtual ~Field_iterator() {}
784
 
  virtual void set(TABLE_LIST *)= 0;
 
755
  virtual void set(TableList *)= 0;
785
756
  virtual void next()= 0;
786
757
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
787
758
  virtual const char *name()= 0;
795
766
  table, or subquery.
796
767
*/
797
768
 
798
 
class TABLE_LIST;
 
769
class TableList;
799
770
class Field_iterator_table: public Field_iterator
800
771
{
801
772
  Field **ptr;
802
773
public:
803
774
  Field_iterator_table() :ptr(0) {}
804
 
  void set(TABLE_LIST *table);
 
775
  void set(TableList *table);
805
776
  void set_table(Table *table) { ptr= table->field; }
806
777
  void next() { ptr++; }
807
778
  bool end_of_fields() { return *ptr == 0; }
816
787
class Field_iterator_view: public Field_iterator
817
788
{
818
789
  Field_translator *ptr, *array_end;
819
 
  TABLE_LIST *view;
 
790
  TableList *view;
820
791
public:
821
792
  Field_iterator_view() :ptr(0), array_end(0) {}
822
 
  void set(TABLE_LIST *table);
 
793
  void set(TableList *table);
823
794
  void next() { ptr++; }
824
795
  bool end_of_fields() { return ptr == array_end; }
825
796
  const char *name();
843
814
public:
844
815
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
845
816
  ~Field_iterator_natural_join() {}
846
 
  void set(TABLE_LIST *table);
 
817
  void set(TableList *table);
847
818
  void next();
848
819
  bool end_of_fields() { return !cur_column_ref; }
849
820
  const char *name() { return cur_column_ref->name(); }
866
837
  IMPLEMENTATION
867
838
    The implementation assumes that all underlying NATURAL/USING table
868
839
    references already contain their result columns and are linked into
869
 
    the list TABLE_LIST::next_name_resolution_table.
 
840
    the list TableList::next_name_resolution_table.
870
841
*/
871
842
 
872
843
class Field_iterator_table_ref: public Field_iterator
873
844
{
874
 
  TABLE_LIST *table_ref, *first_leaf, *last_leaf;
 
845
  TableList *table_ref, *first_leaf, *last_leaf;
875
846
  Field_iterator_table        table_field_it;
876
847
  Field_iterator_view         view_field_it;
877
848
  Field_iterator_natural_join natural_join_it;
879
850
  void set_field_iterator();
880
851
public:
881
852
  Field_iterator_table_ref() :field_it(NULL) {}
882
 
  void set(TABLE_LIST *table);
 
853
  void set(TableList *table);
883
854
  void next();
884
855
  bool end_of_fields()
885
856
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
888
859
  const char *db_name();
889
860
  Item *create_item(THD *thd) { return field_it->create_item(thd); }
890
861
  Field *field() { return field_it->field(); }
891
 
  Natural_join_column *get_or_create_column_ref(TABLE_LIST *parent_table_ref);
 
862
  Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
892
863
  Natural_join_column *get_natural_column_ref();
893
864
};
894
865
 
895
866
 
896
 
typedef struct st_nested_join
897
 
{
898
 
  List<TABLE_LIST>  join_list;       /* list of elements in the nested join */
899
 
  table_map         used_tables;     /* bitmap of tables in the nested join */
900
 
  table_map         not_null_tables; /* tables that rejects nulls           */
901
 
  struct st_join_table *first_nested;/* the first nested table in the plan  */
902
 
  /* 
903
 
    Used to count tables in the nested join in 2 isolated places:
904
 
    1. In make_outerjoin_info(). 
905
 
    2. check_interleaving_with_nj/restore_prev_nj_state (these are called
906
 
       by the join optimizer. 
907
 
    Before each use the counters are zeroed by reset_nj_counters.
908
 
  */
909
 
  uint              counter_;
910
 
  nested_join_map   nj_map;          /* Bit used to identify this nested join*/
911
 
  /*
912
 
    (Valid only for semi-join nests) Bitmap of tables outside the semi-join
913
 
    that are used within the semi-join's ON condition.
914
 
  */
915
 
  table_map         sj_depends_on;
916
 
  /* Outer non-trivially correlated tables */
917
 
  table_map         sj_corr_tables;
918
 
  List<Item>        sj_outer_expr_list;
919
 
} NESTED_JOIN;
920
 
 
921
 
 
922
867
typedef struct st_changed_table_list
923
868
{
924
869
  struct        st_changed_table_list *next;
925
870
  char          *key;
926
871
  uint32_t        key_length;
927
 
} CHANGED_TABLE_LIST;
 
872
} CHANGED_TableList;
928
873
 
929
874
 
930
875
typedef struct st_open_table_list{
931
876
  struct st_open_table_list *next;
932
877
  char  *db,*table;
933
878
  uint32_t in_use,locked;
934
 
} OPEN_TABLE_LIST;
 
879
} OPEN_TableList;
935
880
 
936
881
 
937
882