~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.h

  • Committer: Brian Aker
  • Date: 2008-08-19 17:29:21 UTC
  • Revision ID: brian@tangent.org-20080819172921-bc3kpgsrzsdv338l
Moved Field iterator out to its own definition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <drizzled/filesort_info.h>
25
25
#include <drizzled/natural_join_column.h>
26
26
#include <drizzled/nested_join.h>
 
27
#include <drizzled/field_iterator.h>
27
28
 
28
29
class Item;                             /* Needed by order_st */
29
30
class Item_subselect;
704
705
};
705
706
 
706
707
 
707
 
/*
708
 
  Table reference in the FROM clause.
709
 
 
710
 
  These table references can be of several types that correspond to
711
 
  different SQL elements. Below we list all types of TableLists with
712
 
  the necessary conditions to determine when a TableList instance
713
 
  belongs to a certain type.
714
 
 
715
 
  1) table (TableList::view == NULL)
716
 
     - base table
717
 
       (TableList::derived == NULL)
718
 
     - subquery - TableList::table is a temp table
719
 
       (TableList::derived != NULL)
720
 
     - information schema table
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)
729
 
     - table sequence - e.g. (t1, t2, t3)
730
 
       TODO: how to distinguish from a JOIN?
731
 
     - general JOIN
732
 
       TODO: how to distinguish from a table sequence?
733
 
     - NATURAL JOIN
734
 
       (TableList::natural_join != NULL)
735
 
       - JOIN ... USING
736
 
         (TableList::join_using_fields != NULL)
737
 
     - semi-join
738
 
       ;
739
 
*/
740
 
 
741
 
class Item;
742
 
 
743
 
/*
744
 
  Iterator over the fields of a generic table reference.
745
 
*/
746
 
 
747
 
class Field_iterator: public Sql_alloc
748
 
{
749
 
public:
750
 
  Field_iterator() {}                         /* Remove gcc warning */
751
 
  virtual ~Field_iterator() {}
752
 
  virtual void set(TableList *)= 0;
753
 
  virtual void next()= 0;
754
 
  virtual bool end_of_fields()= 0;              /* Return 1 at end of list */
755
 
  virtual const char *name()= 0;
756
 
  virtual Item *create_item(THD *)= 0;
757
 
  virtual Field *field()= 0;
758
 
};
759
 
 
760
 
 
761
 
/* 
762
 
  Iterator over the fields of a base table, view with temporary
763
 
  table, or subquery.
764
 
*/
765
 
 
766
 
class TableList;
767
 
class Field_iterator_table: public Field_iterator
768
 
{
769
 
  Field **ptr;
770
 
public:
771
 
  Field_iterator_table() :ptr(0) {}
772
 
  void set(TableList *table);
773
 
  void set_table(Table *table) { ptr= table->field; }
774
 
  void next() { ptr++; }
775
 
  bool end_of_fields() { return *ptr == 0; }
776
 
  const char *name();
777
 
  Item *create_item(THD *thd);
778
 
  Field *field() { return *ptr; }
779
 
};
780
 
 
781
 
 
782
 
/* Iterator over the fields of a merge view. */
783
 
 
784
 
/*
785
 
  Field_iterator interface to the list of materialized fields of a
786
 
  NATURAL/USING join.
787
 
*/
788
 
 
789
 
class Field_iterator_natural_join: public Field_iterator
790
 
{
791
 
  List_iterator_fast<Natural_join_column> column_ref_it;
792
 
  Natural_join_column *cur_column_ref;
793
 
public:
794
 
  Field_iterator_natural_join() :cur_column_ref(NULL) {}
795
 
  ~Field_iterator_natural_join() {}
796
 
  void set(TableList *table);
797
 
  void next();
798
 
  bool end_of_fields() { return !cur_column_ref; }
799
 
  const char *name() { return cur_column_ref->name(); }
800
 
  Item *create_item(THD *thd) { return cur_column_ref->create_item(thd); }
801
 
  Field *field() { return cur_column_ref->field(); }
802
 
  Natural_join_column *column_ref() { return cur_column_ref; }
803
 
};
804
 
 
805
 
 
806
 
/*
807
 
  Generic iterator over the fields of an arbitrary table reference.
808
 
 
809
 
  DESCRIPTION
810
 
    This class unifies the various ways of iterating over the columns
811
 
    of a table reference depending on the type of SQL entity it
812
 
    represents. If such an entity represents a nested table reference,
813
 
    this iterator encapsulates the iteration over the columns of the
814
 
    members of the table reference.
815
 
 
816
 
  IMPLEMENTATION
817
 
    The implementation assumes that all underlying NATURAL/USING table
818
 
    references already contain their result columns and are linked into
819
 
    the list TableList::next_name_resolution_table.
820
 
*/
821
 
 
822
 
class Field_iterator_table_ref: public Field_iterator
823
 
{
824
 
  TableList *table_ref, *first_leaf, *last_leaf;
825
 
  Field_iterator_table        table_field_it;
826
 
  Field_iterator_natural_join natural_join_it;
827
 
  Field_iterator *field_it;
828
 
  void set_field_iterator();
829
 
public:
830
 
  Field_iterator_table_ref() :field_it(NULL) {}
831
 
  void set(TableList *table);
832
 
  void next();
833
 
  bool end_of_fields()
834
 
  { return (table_ref == last_leaf && field_it->end_of_fields()); }
835
 
  const char *name() { return field_it->name(); }
836
 
  const char *table_name();
837
 
  const char *db_name();
838
 
  Item *create_item(THD *thd) { return field_it->create_item(thd); }
839
 
  Field *field() { return field_it->field(); }
840
 
  Natural_join_column *get_or_create_column_ref(TableList *parent_table_ref);
841
 
  Natural_join_column *get_natural_column_ref();
842
 
};
843
 
 
844
 
 
845
708
typedef struct st_changed_table_list
846
709
{
847
710
  struct        st_changed_table_list *next;