~drizzle-trunk/drizzle/development

327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1
#ifdef USE_PRAGMA_INTERFACE
2
#pragma interface			/* gcc class implementation */
3
#endif
4
5
6
#ifndef DRIZZLED_TMP_TABLE_H
7
#define DRIZZLED_TMP_TABLE_H
8
9
#include "table.h"
10
11
class Index_hint;
12
class COND_EQUAL;
13
class Natural_join_column;
14
class select_union;
15
class st_select_lex_unit;
16
class ST_SCHEMA_TABLE;
17
class st_select_lex;
18
class TMP_TABLE_PARAM;
19
class Field_translator;
20
class Item_subselect;
21
class Table;
22
23
enum enum_schema_table_state
24
{ 
25
  NOT_PROCESSED= 0,
26
  PROCESSED_BY_CREATE_SORT_INDEX,
27
  PROCESSED_BY_JOIN_EXEC
28
};
29
30
31
class TABLE_LIST
32
{
33
public:
34
  TABLE_LIST() {}                          /* Remove gcc warning */
35
36
  /**
37
    Prepare TABLE_LIST that consists of one table instance to use in
38
    simple_open_and_lock_tables
39
  */
40
  inline void init_one_table(const char *db_name_arg,
41
                             const char *table_name_arg,
42
                             enum thr_lock_type lock_type_arg)
43
  {
44
    memset(this, 0, sizeof(*this));
45
    db= (char*) db_name_arg;
46
    table_name= alias= (char*) table_name_arg;
47
    lock_type= lock_type_arg;
48
  }
49
50
  /*
51
    List of tables local to a subquery (used by SQL_LIST). Considers
52
    views as leaves (unlike 'next_leaf' below). Created at parse time
53
    in st_select_lex::add_table_to_list() -> table_list.link_in_list().
54
  */
55
  TABLE_LIST *next_local;
56
  /* link in a global list of all queries tables */
57
  TABLE_LIST *next_global, **prev_global;
58
  char		*db, *alias, *table_name, *schema_table_name;
59
  char          *option;                /* Used by cache index  */
60
  Item		*on_expr;		/* Used with outer join */
61
  Item          *sj_on_expr;
62
  /*
63
    (Valid only for semi-join nests) Bitmap of tables that are within the
64
    semi-join (this is different from bitmap of all nest's children because
65
    tables that were pulled out of the semi-join nest remain listed as
66
    nest's children).
67
  */
68
  table_map     sj_inner_tables;
69
  /* Number of IN-compared expressions */
70
  uint          sj_in_exprs; 
71
  /*
72
    The structure of ON expression presented in the member above
73
    can be changed during certain optimizations. This member
74
    contains a snapshot of AND-OR structure of the ON expression
75
    made after permanent transformations of the parse tree, and is
76
    used to restore ON clause before every reexecution of a prepared
77
    statement or stored procedure.
78
  */
79
  Item          *prep_on_expr;
80
  COND_EQUAL    *cond_equal;            /* Used with outer join */
81
  /*
82
    During parsing - left operand of NATURAL/USING join where 'this' is
83
    the right operand. After parsing (this->natural_join == this) iff
84
    'this' represents a NATURAL or USING join operation. Thus after
85
    parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
86
  */
87
  TABLE_LIST *natural_join;
88
  /*
89
    True if 'this' represents a nested join that is a NATURAL JOIN.
90
    For one of the operands of 'this', the member 'natural_join' points
91
    to the other operand of 'this'.
92
  */
93
  bool is_natural_join;
94
  /* Field names in a USING clause for JOIN ... USING. */
95
  List<String> *join_using_fields;
96
  /*
97
    Explicitly store the result columns of either a NATURAL/USING join or
98
    an operand of such a join.
99
  */
100
  List<Natural_join_column> *join_columns;
101
  /* true if join_columns contains all columns of this table reference. */
102
  bool is_join_columns_complete;
103
104
  /*
105
    List of nodes in a nested join tree, that should be considered as
106
    leaves with respect to name resolution. The leaves are: views,
107
    top-most nodes representing NATURAL/USING joins, subqueries, and
108
    base tables. All of these TABLE_LIST instances contain a
109
    materialized list of columns. The list is local to a subquery.
110
  */
111
  TABLE_LIST *next_name_resolution_table;
112
  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
113
  List<Index_hint> *index_hints;
114
  Table        *table;    /* opened table */
115
  uint          table_id; /* table id (from binlog) for opened table */
116
  /*
117
    select_result for derived table to pass it from table creation to table
118
    filling procedure
119
  */
120
  select_union  *derived_result;
121
  /*
122
    Reference from aux_tables to local list entry of main select of
123
    multi-delete statement:
124
    delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
125
    here it will be reference of first occurrence of t1 to second (as you
126
    can see this lists can't be merged)
127
  */
128
  TABLE_LIST	*correspondent_table;
129
  st_select_lex_unit *derived;		/* SELECT_LEX_UNIT of derived table */
130
  ST_SCHEMA_TABLE *schema_table;        /* Information_schema table */
131
  st_select_lex	*schema_select_lex;
132
  /*
133
    True when the view field translation table is used to convert
134
    schema table fields for backwards compatibility with SHOW command.
135
  */
136
  bool schema_table_reformed;
137
  TMP_TABLE_PARAM *schema_table_param;
138
  /* link to select_lex where this table was used */
139
  st_select_lex	*select_lex;
140
  Field_translator *field_translation;	/* array of VIEW fields */
141
  /* pointer to element after last one in translation table above */
142
  Field_translator *field_translation_end;
143
  /*
144
    List (based on next_local) of underlying tables of this view. I.e. it
145
    does not include the tables of subqueries used in the view. Is set only
146
    for merged views.
147
  */
148
  TABLE_LIST	*merge_underlying_list;
149
  /*
150
    List of all base tables local to a subquery including all view
151
    tables. Unlike 'next_local', this in this list views are *not*
152
    leaves. Created in setup_tables() -> make_leaves_list().
153
  */
154
  TABLE_LIST	*next_leaf;
155
  thr_lock_type lock_type;
156
  uint		outer_join;		/* Which join type */
157
  uint		shared;			/* Used in multi-upd */
158
  size_t        db_length;
159
  size_t        table_name_length;
160
  bool		straight;		/* optimize with prev table */
161
  bool          updating;               /* for replicate-do/ignore table */
162
  bool		force_index;		/* prefer index over table scan */
163
  bool          ignore_leaves;          /* preload only non-leaf nodes */
164
  table_map     dep_tables;             /* tables the table depends on      */
165
  table_map     on_expr_dep_tables;     /* tables on expression depends on  */
166
  struct st_nested_join *nested_join;   /* if the element is a nested join  */
167
  TABLE_LIST *embedding;             /* nested join containing the table */
168
  List<TABLE_LIST> *join_list;/* join list the table belongs to   */
169
  bool		cacheable_table;	/* stop PS caching */
170
  handlerton	*db_type;		/* table_type for handler */
171
  char		timestamp_buffer[20];	/* buffer for timestamp (19+1) */
172
  /*
173
    This TABLE_LIST object corresponds to the table to be created
174
    so it is possible that it does not exist (used in CREATE TABLE
175
    ... SELECT implementation).
176
  */
177
  bool          create;
178
  /* For transactional locking. */
179
  int           lock_timeout;           /* NOWAIT or WAIT [X]               */
180
  bool          lock_transactional;     /* If transactional lock requested. */
181
  bool          internal_tmp_table;
182
  /** true if an alias for this table was specified in the SQL. */
183
  bool          is_alias;
184
  /** true if the table is referred to in the statement using a fully
185
      qualified name (<db_name>.<table_name>).
186
  */
187
  bool          is_fqtn;
188
189
  uint i_s_requested_object;
190
  bool has_db_lookup_value;
191
  bool has_table_lookup_value;
192
  uint table_open_method;
193
  enum enum_schema_table_state schema_table_state;
194
  void set_underlying_merge();
195
  bool setup_underlying(THD *thd);
196
  void cleanup_items();
197
  /*
198
    If you change placeholder(), please check the condition in
199
    check_transactional_lock() too.
200
  */
201
  bool placeholder()
202
  {
203
    return derived || schema_table || (create && !table->getDBStat()) || !table;
204
  }
205
  void print(THD *thd, String *str, enum_query_type query_type);
206
  bool set_insert_values(MEM_ROOT *mem_root);
207
  TABLE_LIST *find_underlying_table(Table *table);
208
  TABLE_LIST *first_leaf_for_name_resolution();
209
  TABLE_LIST *last_leaf_for_name_resolution();
210
  bool is_leaf_for_name_resolution();
211
  inline TABLE_LIST *top_table()
327.1.7 by Brian Aker
Removed belong_to_view variable
212
    { return this; }
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
213
214
  /*
215
    Cleanup for re-execution in a prepared statement or a stored
216
    procedure.
217
  */
218
  void reinit_before_use(THD *thd);
219
  Item_subselect *containing_subselect();
220
221
  /* 
222
    Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
223
    st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
224
    st_table::force_index and st_table::covering_keys.
225
  */
226
  bool process_index_hints(Table *table);
227
};
228
#endif /* DRIZZLED_TMP_TABLE_H */