18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22
#ifndef DRIZZLED_TABLE_LIST_H
22
23
#define DRIZZLED_TABLE_LIST_H
26
Table reference in the FROM clause.
28
These table references can be of several types that correspond to
29
different SQL elements. Below we list all types of TableLists with
30
the necessary conditions to determine when a TableList instance
31
belongs to a certain type.
33
1) table (TableList::view == NULL)
35
(TableList::derived == NULL)
36
- subquery - TableList::table is a temp table
37
(TableList::derived != NULL)
38
- information schema table
39
(TableList::schema_table != NULL)
40
NOTICE: for schema tables TableList::field_translation may be != NULL
41
2) view (TableList::view != NULL)
42
- merge (TableList::effective_algorithm == VIEW_ALGORITHM_MERGE)
43
also (TableList::field_translation != NULL)
44
- tmptable (TableList::effective_algorithm == VIEW_ALGORITHM_TMPTABLE)
45
also (TableList::field_translation == NULL)
46
3) nested table reference (TableList::nested_join != NULL)
47
- table sequence - e.g. (t1, t2, t3)
48
TODO: how to distinguish from a JOIN?
50
TODO: how to distinguish from a table sequence?
52
(TableList::natural_join != NULL)
54
(TableList::join_using_fields != NULL)
24
60
#include <drizzled/table.h>
31
64
class Natural_join_column;
32
65
class select_union;
33
class Select_Lex_Unit;
35
class Tmp_Table_Param;
66
class st_select_lex_unit;
67
class ST_SCHEMA_TABLE;
69
class TMP_TABLE_PARAM;
70
class Field_translator;
36
71
class Item_subselect;
44
74
struct nested_join_st;
47
* A Table referenced in the FROM clause.
49
* These table references can be of several types that correspond to
50
* different SQL elements. Below we list all types of TableLists with
51
* the necessary conditions to determine when a TableList instance
52
* belongs to a certain type.
54
* 1) table (TableList::view == NULL)
56
* (TableList::derived == NULL)
57
* - subquery - TableList::table is a temp table
58
* (TableList::derived != NULL)
62
* for schema tables TableList::field_translation may be != NULL
65
* 3) nested table reference (TableList::nested_join != NULL)
66
* - table sequence - e.g. (t1, t2, t3)
67
* @todo how to distinguish from a JOIN?
69
* @todo how to distinguish from a table sequence?
71
* (TableList::natural_join != NULL)
73
* (TableList::join_using_fields != NULL)
92
is_natural_join(false),
93
is_join_columns_complete(false),
98
join_using_fields(NULL),
100
next_name_resolution_table(NULL),
102
derived_result(NULL),
104
schema_select_lex(NULL),
109
i_s_requested_object(0),
111
table_name_length(0),
113
on_expr_dep_tables(0),
118
internal_tmp_table(false),
121
has_db_lookup_value(false),
122
has_table_lookup_value(false)
79
TableList() {} /* Remove gcc warning */
126
* List of tables local to a subquery (used by SQL_LIST). Considers
127
* views as leaves (unlike 'next_leaf' below). Created at parse time
128
* in Select_Lex::add_table_to_list() -> table_list.link_in_list().
82
Prepare TableList that consists of one table instance to use in
83
simple_open_and_lock_tables
85
inline void init_one_table(const char *db_name_arg,
86
const char *table_name_arg,
87
enum thr_lock_type lock_type_arg)
89
memset(this, 0, sizeof(*this));
90
db= (char*) db_name_arg;
91
table_name= alias= (char*) table_name_arg;
92
lock_type= lock_type_arg;
96
List of tables local to a subquery (used by SQL_LIST). Considers
97
views as leaves (unlike 'next_leaf' below). Created at parse time
98
in st_select_lex::add_table_to_list() -> table_list.link_in_list().
130
100
TableList *next_local;
132
/** link in a global list of all queries tables */
133
TableList *next_global;
134
TableList **prev_global;
139
char *option; ///< Used by cache index
140
Item *on_expr; ///< Used with outer join
141
Table *table; ///< opened table
143
* The structure of ON expression presented in the member above
144
* can be changed during certain optimizations. This member
145
* contains a snapshot of AND-OR structure of the ON expression
146
* made after permanent transformations of the parse tree, and is
147
* used to restore ON clause before every reexecution of a prepared
148
* statement or stored procedure.
151
COND_EQUAL *cond_equal; ///< Used with outer join
153
* During parsing - left operand of NATURAL/USING join where 'this' is
154
* the right operand. After parsing (this->natural_join == this) iff
155
* 'this' represents a NATURAL or USING join operation. Thus after
156
* parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
101
/* link in a global list of all queries tables */
102
TableList *next_global, **prev_global;
103
char *db, *alias, *table_name, *schema_table_name;
104
char *option; /* Used by cache index */
105
Item *on_expr; /* Used with outer join */
108
(Valid only for semi-join nests) Bitmap of tables that are within the
109
semi-join (this is different from bitmap of all nest's children because
110
tables that were pulled out of the semi-join nest remain listed as
113
table_map sj_inner_tables;
114
/* Number of IN-compared expressions */
115
uint32_t sj_in_exprs;
117
The structure of ON expression presented in the member above
118
can be changed during certain optimizations. This member
119
contains a snapshot of AND-OR structure of the ON expression
120
made after permanent transformations of the parse tree, and is
121
used to restore ON clause before every reexecution of a prepared
122
statement or stored procedure.
125
COND_EQUAL *cond_equal; /* Used with outer join */
127
During parsing - left operand of NATURAL/USING join where 'this' is
128
the right operand. After parsing (this->natural_join == this) iff
129
'this' represents a NATURAL or USING join operation. Thus after
130
parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
158
132
TableList *natural_join;
160
* True if 'this' represents a nested join that is a NATURAL JOIN.
161
* For one of the operands of 'this', the member 'natural_join' points
162
* to the other operand of 'this'.
134
True if 'this' represents a nested join that is a NATURAL JOIN.
135
For one of the operands of 'this', the member 'natural_join' points
136
to the other operand of 'this'.
164
138
bool is_natural_join;
166
/** true if join_columns contains all columns of this table reference. */
167
bool is_join_columns_complete;
169
bool straight; ///< optimize with prev table
170
bool force_index; ///< prefer index over table scan
171
bool ignore_leaves; ///< preload only non-leaf nodes
174
* This TableList object corresponds to the table to be created
175
* so it is possible that it does not exist (used in CREATE TABLE
176
* ... SELECT implementation).
180
/** Field names in a USING clause for JOIN ... USING. */
139
/* Field names in a USING clause for JOIN ... USING. */
181
140
List<String> *join_using_fields;
183
* Explicitly store the result columns of either a NATURAL/USING join or
184
* an operand of such a join.
142
Explicitly store the result columns of either a NATURAL/USING join or
143
an operand of such a join.
186
145
List<Natural_join_column> *join_columns;
146
/* true if join_columns contains all columns of this table reference. */
147
bool is_join_columns_complete;
189
* List of nodes in a nested join tree, that should be considered as
190
* leaves with respect to name resolution. The leaves are: views,
191
* top-most nodes representing NATURAL/USING joins, subqueries, and
192
* base tables. All of these TableList instances contain a
193
* materialized list of columns. The list is local to a subquery.
150
List of nodes in a nested join tree, that should be considered as
151
leaves with respect to name resolution. The leaves are: views,
152
top-most nodes representing NATURAL/USING joins, subqueries, and
153
base tables. All of these TableList instances contain a
154
materialized list of columns. The list is local to a subquery.
195
156
TableList *next_name_resolution_table;
196
/** Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
157
/* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
197
158
List<Index_hint> *index_hints;
199
* select_result for derived table to pass it from table creation to table
202
select_union *derived_result;
203
Select_Lex_Unit *derived; ///< Select_Lex_Unit of derived table */
204
Select_Lex *schema_select_lex;
205
/** link to select_lex where this table was used */
206
Select_Lex *select_lex;
208
* List of all base tables local to a subquery including all view
209
* tables. Unlike 'next_local', this in this list views are *not*
210
* leaves. Created in setup_tables() -> make_leaves_list().
212
TableList *next_leaf;
159
Table *table; /* opened table */
160
uint32_t table_id; /* table id (from binlog) for opened table */
162
select_result for derived table to pass it from table creation to table
165
select_union *derived_result;
167
Reference from aux_tables to local list entry of main select of
168
multi-delete statement:
169
delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
170
here it will be reference of first occurrence of t1 to second (as you
171
can see this lists can't be merged)
173
TableList *correspondent_table;
174
st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */
175
ST_SCHEMA_TABLE *schema_table; /* Information_schema table */
176
st_select_lex *schema_select_lex;
178
True when the view field translation table is used to convert
179
schema table fields for backwards compatibility with SHOW command.
181
bool schema_table_reformed;
182
TMP_TABLE_PARAM *schema_table_param;
183
/* link to select_lex where this table was used */
184
st_select_lex *select_lex;
185
Field_translator *field_translation; /* array of VIEW fields */
186
/* pointer to element after last one in translation table above */
187
Field_translator *field_translation_end;
189
List (based on next_local) of underlying tables of this view. I.e. it
190
does not include the tables of subqueries used in the view. Is set only
193
TableList *merge_underlying_list;
195
List of all base tables local to a subquery including all view
196
tables. Unlike 'next_local', this in this list views are *not*
197
leaves. Created in setup_tables() -> make_leaves_list().
199
TableList *next_leaf;
213
200
thr_lock_type lock_type;
214
uint32_t outer_join; ///< Which join type
215
uint32_t shared; ///<Used in multi-upd
201
uint outer_join; /* Which join type */
202
uint shared; /* Used in multi-upd */
204
size_t table_name_length;
205
bool straight; /* optimize with prev table */
206
bool updating; /* for replicate-do/ignore table */
207
bool force_index; /* prefer index over table scan */
208
bool ignore_leaves; /* preload only non-leaf nodes */
209
table_map dep_tables; /* tables the table depends on */
210
table_map on_expr_dep_tables; /* tables on expression depends on */
211
nested_join_st *nested_join; /* if the element is a nested join */
212
TableList *embedding; /* nested join containing the table */
213
List<TableList> *join_list;/* join list the table belongs to */
214
bool cacheable_table; /* stop PS caching */
215
handlerton *db_type; /* table_type for handler */
216
char timestamp_buffer[20]; /* buffer for timestamp (19+1) */
218
This TableList object corresponds to the table to be created
219
so it is possible that it does not exist (used in CREATE TABLE
220
... SELECT implementation).
223
/* For transactional locking. */
224
int lock_timeout; /* NOWAIT or WAIT [X] */
225
bool lock_transactional; /* If transactional lock requested. */
226
bool internal_tmp_table;
227
/** true if an alias for this table was specified in the SQL. */
229
/** true if the table is referred to in the statement using a fully
230
qualified name (<db_name>.<table_name>).
216
234
uint32_t i_s_requested_object;
218
size_t table_name_length;
219
table_map dep_tables; ///< tables the table depends on
220
table_map on_expr_dep_tables; ///< tables on expression depends on
221
nested_join_st *nested_join; ///< if the element is a nested join
222
TableList *embedding; ///< nested join containing the table
223
List<TableList> *join_list; ///< join list the table belongs to
224
plugin::StorageEngine *db_type; ///< table_type for handler
225
char timestamp_buffer[20]; ///< buffer for timestamp (19+1)
226
bool internal_tmp_table;
227
/** true if an alias for this table was specified in the SQL. */
230
* true if the table is referred to in the statement using a fully
231
* qualified name (<db_name>.<table_name>).
235
235
bool has_db_lookup_value;
236
236
bool has_table_lookup_value;
237
uint32_t table_open_method;
238
enum enum_schema_table_state schema_table_state;
238
239
void set_underlying_merge();
239
240
bool setup_underlying(Session *session);
242
* If you change placeholder(), please check the condition in
243
* check_transactional_lock() too.
241
void cleanup_items();
243
If you change placeholder(), please check the condition in
244
check_transactional_lock() too.
245
246
bool placeholder();
247
* Print table as it should be in join list.
249
* @param str string where table should be printed
251
247
void print(Session *session, String *str, enum_query_type query_type);
253
* Sets insert_values buffer
255
* @param[in] memory pool for allocating
260
* true - out of memory
262
bool set_insert_values(memory::Root *mem_root);
264
* Find underlying base tables (TableList) which represent given
265
* table_to_find (Table)
267
* @param[in] table to find
270
* NULL if table is not found
272
* Pointer to found table reference
248
bool set_insert_values(MEM_ROOT *mem_root);
274
249
TableList *find_underlying_table(Table *table);
276
* Retrieve the first (left-most) leaf in a nested join tree with
277
* respect to name resolution.
281
* Given that 'this' is a nested table reference, recursively walk
282
* down the left-most children of 'this' until we reach a leaf
283
* table reference with respect to name resolution.
286
* If 'this' is a nested table reference - the left-most child of
287
* the tree rooted in 'this',
290
250
TableList *first_leaf_for_name_resolution();
292
* Retrieve the last (right-most) leaf in a nested join tree with
293
* respect to name resolution.
297
* Given that 'this' is a nested table reference, recursively walk
298
* down the right-most children of 'this' until we reach a leaf
299
* table reference with respect to name resolution.
302
* If 'this' is a nested table reference - the right-most child of
303
* the tree rooted in 'this',
306
251
TableList *last_leaf_for_name_resolution();
308
* Test if this is a leaf with respect to name resolution.
312
* A table reference is a leaf with respect to name resolution if
313
* it is either a leaf node in a nested join tree (table, view,
314
* schema table, subquery), or an inner node that represents a
315
* NATURAL/USING join, or a nested join with materialized join
319
* true if a leaf, false otherwise.
321
252
bool is_leaf_for_name_resolution();
322
253
inline TableList *top_table()
326
* Return subselect that contains the FROM list this table is taken from
329
* Subselect item for the subquery that contains the FROM list
330
* this table is taken from if there is any
257
Cleanup for re-execution in a prepared statement or a stored
260
void reinit_before_use(Session *session);
334
261
Item_subselect *containing_subselect();
337
* Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
338
* st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
339
* st_table::force_index and st_table::covering_keys.
341
* @param the Table to operate on.
345
* The parser collects the index hints for each table in a "tagged list"
346
* (TableList::index_hints). Using the information in this tagged list
347
* this function sets the members Table::keys_in_use_for_query,
348
* Table::keys_in_use_for_group_by, Table::keys_in_use_for_order_by,
349
* Table::force_index and Table::covering_keys.
351
* Current implementation of the runtime does not allow mixing FORCE INDEX
352
* and USE INDEX, so this is checked here. Then the FORCE INDEX list
353
* (if non-empty) is appended to the USE INDEX list and a flag is set.
355
* Multiple hints of the same kind are processed so that each clause
356
* is applied to what is computed in the previous clause.
359
* USE INDEX (i1) USE INDEX (i2)
362
* and means "consider only i1 and i2".
365
* USE INDEX () USE INDEX (i1)
368
* and means "consider only the index i1"
370
* It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
373
* Different kind of hints (USE/FORCE/IGNORE) are processed in the following
375
* 1. All indexes in USE (or FORCE) INDEX are added to the mask.
376
* 2. All IGNORE INDEX
377
* e.g. "USE INDEX i1, IGNORE INDEX i1, USE INDEX i1" will not use i1 at all
378
* as if we had "USE INDEX i1, USE INDEX i1, IGNORE INDEX i1".
379
* As an optimization if there is a covering index, and we have
380
* IGNORE INDEX FOR GROUP/order_st, and this index is used for the JOIN part,
381
* then we have to ignore the IGNORE INDEX FROM GROUP/order_st.
384
* false no errors found
386
* true found and reported an error.
264
Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
265
st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
266
st_table::force_index and st_table::covering_keys.
388
268
bool process_index_hints(Table *table);
390
* Creates a table definition cache key for this table entry.
392
* @param[out] Create key here (must be of size MAX_DBKEY_LENGTH)
396
* The table cache_key is created from:
400
* if the table is a tmp table, we add the following to make each tmp table
401
* unique on the slave:
403
* 4 bytes for master thread id
404
* 4 bytes pseudo thread id
409
uint32_t create_table_def_key(char *key);
412
271
void close_thread_tables(Session *session);
414
} /* namespace drizzled */
416
273
#endif /* DRIZZLED_TABLE_LIST_H */