20
20
#define DRIZZLED_TABLE_H
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>
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;
29
33
class Security_context;
32
36
/*************************************************************************/
34
/* Order clause list element */
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;
52
38
enum tmp_table_type
54
40
NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
61
47
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
63
typedef struct st_filesort_info
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 */
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
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;
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).
736
class Natural_join_column: public Sql_alloc
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. */
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.
751
Natural_join_column(Field_translator *field_param, TABLE_LIST *tab);
752
Natural_join_column(Field *field_param, TABLE_LIST *tab);
754
Item *create_item(THD *thd);
756
const char *table_name();
757
const char *db_name();
762
708
Table reference in the FROM clause.
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.
769
1) table (TABLE_LIST::view == NULL)
715
1) table (TableList::view == NULL)
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?
786
732
TODO: how to distinguish from a table sequence?
788
(TABLE_LIST::natural_join != NULL)
734
(TableList::natural_join != NULL)
790
(TABLE_LIST::join_using_fields != NULL)
736
(TableList::join_using_fields != NULL)
836
782
/* Iterator over the fields of a merge view. */
838
class Field_iterator_view: public Field_iterator
840
Field_translator *ptr, *array_end;
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; }
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; }
857
785
Field_iterator interface to the list of materialized fields of a
858
786
NATURAL/USING join.
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.
894
822
class Field_iterator_table_ref: public Field_iterator
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();
903
830
Field_iterator_table_ref() :field_it(NULL) {}
904
void set(TABLE_LIST *table);
831
void set(TableList *table);
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();
918
typedef struct st_nested_join
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 */
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.
932
nested_join_map nj_map; /* Bit used to identify this nested join*/
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.
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;
944
845
typedef struct st_changed_table_list
946
847
struct st_changed_table_list *next;
948
849
uint32_t key_length;
949
} CHANGED_TABLE_LIST;
952
typedef struct st_open_table_list{
853
typedef struct st_open_table_list
953
855
struct st_open_table_list *next;
955
857
uint32_t in_use,locked;
958
typedef struct st_table_field_w_type
963
} TABLE_FIELD_W_TYPE;
967
table_check_intact(Table *table, const uint table_f_count,
968
const TABLE_FIELD_W_TYPE *table_def);
970
861
static inline my_bitmap_map *tmp_use_all_columns(Table *table,
971
862
MY_BITMAP *bitmap)
982
873
bitmap->bitmap= old;
985
/* The following is only needed for debugging */
987
static inline my_bitmap_map *dbug_tmp_use_all_columns(Table *table __attribute__((unused)),
988
MY_BITMAP *bitmap __attribute__((unused)))
993
static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap __attribute__((unused)),
994
my_bitmap_map *old __attribute__((unused)))
999
876
size_t max_row_length(Table *table, const uchar *data);
1001
878
#endif /* DRIZZLED_TABLE_H */