18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef DRIZZLED_TABLE_LIST_H
22
#define DRIZZLED_TABLE_LIST_H
24
#include <drizzled/nested_join.h>
25
#include <drizzled/table.h>
22
#ifndef DRIZZLED_TMP_TABLE_H
23
#define DRIZZLED_TMP_TABLE_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)
32
64
class Natural_join_column;
33
65
class select_union;
34
class Select_Lex_Unit;
36
class Tmp_Table_Param;
66
class st_select_lex_unit;
67
class ST_SCHEMA_TABLE;
69
class TMP_TABLE_PARAM;
70
class Field_translator;
37
71
class Item_subselect;
46
* A Table referenced in the FROM clause.
48
* These table references can be of several types that correspond to
49
* different SQL elements. Below we list all types of TableLists with
50
* the necessary conditions to determine when a TableList instance
51
* belongs to a certain type.
53
* 1) table (TableList::view == NULL)
55
* (TableList::derived == NULL)
56
* - subquery - TableList::table is a temp table
57
* (TableList::derived != NULL)
61
* for schema tables TableList::field_translation may be != NULL
64
* 3) nested table reference (TableList::nested_join != NULL)
65
* - table sequence - e.g. (t1, t2, t3)
66
* @todo how to distinguish from a JOIN?
68
* @todo how to distinguish from a table sequence?
70
* (TableList::natural_join != NULL)
72
* (TableList::join_using_fields != NULL)
74
enum enum_schema_table_state
77
PROCESSED_BY_CREATE_SORT_INDEX,
78
PROCESSED_BY_JOIN_EXEC
91
is_natural_join(false),
92
is_join_columns_complete(false),
96
join_using_fields(NULL),
98
next_name_resolution_table(NULL),
100
derived_result(NULL),
102
schema_select_lex(NULL),
107
table_name_length(0),
109
on_expr_dep_tables(0),
114
internal_tmp_table(false),
85
TableList() {} /* Remove gcc warning */
121
* List of tables local to a subquery (used by SQL_LIST). Considers
122
* views as leaves (unlike 'next_leaf' below). Created at parse time
123
* in Select_Lex::add_table_to_list() -> table_list.link_in_list().
88
Prepare TableList that consists of one table instance to use in
89
simple_open_and_lock_tables
91
inline void init_one_table(const char *db_name_arg,
92
const char *table_name_arg,
93
enum thr_lock_type lock_type_arg)
95
memset(this, 0, sizeof(*this));
96
db= (char*) db_name_arg;
97
table_name= alias= (char*) table_name_arg;
98
lock_type= lock_type_arg;
102
List of tables local to a subquery (used by SQL_LIST). Considers
103
views as leaves (unlike 'next_leaf' below). Created at parse time
104
in st_select_lex::add_table_to_list() -> table_list.link_in_list().
125
106
TableList *next_local;
127
/** link in a global list of all queries tables */
128
TableList *next_global;
129
TableList **prev_global;
135
const char *getSchemaName()
140
char **getSchemaNamePtr()
145
void setSchemaName(char *arg)
153
const char *table_name;
156
const char *getTableName()
161
void setTableName(const char *arg)
166
char *option; ///< Used by cache index
167
Item *on_expr; ///< Used with outer join
168
Table *table; ///< opened table
170
* The structure of ON expression presented in the member above
171
* can be changed during certain optimizations. This member
172
* contains a snapshot of AND-OR structure of the ON expression
173
* made after permanent transformations of the parse tree, and is
174
* used to restore ON clause before every reexecution of a prepared
175
* statement or stored procedure.
178
COND_EQUAL *cond_equal; ///< Used with outer join
180
* During parsing - left operand of NATURAL/USING join where 'this' is
181
* the right operand. After parsing (this->natural_join == this) iff
182
* 'this' represents a NATURAL or USING join operation. Thus after
183
* parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
107
/* link in a global list of all queries tables */
108
TableList *next_global, **prev_global;
109
char *db, *alias, *table_name, *schema_table_name;
110
char *option; /* Used by cache index */
111
Item *on_expr; /* Used with outer join */
114
(Valid only for semi-join nests) Bitmap of tables that are within the
115
semi-join (this is different from bitmap of all nest's children because
116
tables that were pulled out of the semi-join nest remain listed as
119
table_map sj_inner_tables;
120
/* Number of IN-compared expressions */
121
uint32_t sj_in_exprs;
123
The structure of ON expression presented in the member above
124
can be changed during certain optimizations. This member
125
contains a snapshot of AND-OR structure of the ON expression
126
made after permanent transformations of the parse tree, and is
127
used to restore ON clause before every reexecution of a prepared
128
statement or stored procedure.
131
COND_EQUAL *cond_equal; /* Used with outer join */
133
During parsing - left operand of NATURAL/USING join where 'this' is
134
the right operand. After parsing (this->natural_join == this) iff
135
'this' represents a NATURAL or USING join operation. Thus after
136
parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
185
138
TableList *natural_join;
187
* True if 'this' represents a nested join that is a NATURAL JOIN.
188
* For one of the operands of 'this', the member 'natural_join' points
189
* to the other operand of 'this'.
140
True if 'this' represents a nested join that is a NATURAL JOIN.
141
For one of the operands of 'this', the member 'natural_join' points
142
to the other operand of 'this'.
191
144
bool is_natural_join;
193
/** true if join_columns contains all columns of this table reference. */
194
bool is_join_columns_complete;
196
bool straight; ///< optimize with prev table
197
bool force_index; ///< prefer index over table scan
198
bool ignore_leaves; ///< preload only non-leaf nodes
201
is the table a cartesian join, assumption is yes unless "solved"
203
bool isCartesian() const;
205
/** Field names in a USING clause for JOIN ... USING. */
145
/* Field names in a USING clause for JOIN ... USING. */
206
146
List<String> *join_using_fields;
208
* Explicitly store the result columns of either a NATURAL/USING join or
209
* an operand of such a join.
148
Explicitly store the result columns of either a NATURAL/USING join or
149
an operand of such a join.
211
151
List<Natural_join_column> *join_columns;
152
/* true if join_columns contains all columns of this table reference. */
153
bool is_join_columns_complete;
214
* List of nodes in a nested join tree, that should be considered as
215
* leaves with respect to name resolution. The leaves are: views,
216
* top-most nodes representing NATURAL/USING joins, subqueries, and
217
* base tables. All of these TableList instances contain a
218
* materialized list of columns. The list is local to a subquery.
156
List of nodes in a nested join tree, that should be considered as
157
leaves with respect to name resolution. The leaves are: views,
158
top-most nodes representing NATURAL/USING joins, subqueries, and
159
base tables. All of these TableList instances contain a
160
materialized list of columns. The list is local to a subquery.
220
162
TableList *next_name_resolution_table;
221
/** Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
163
/* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
222
164
List<Index_hint> *index_hints;
224
* select_result for derived table to pass it from table creation to table
227
select_union *derived_result;
228
Select_Lex_Unit *derived; ///< Select_Lex_Unit of derived table */
229
Select_Lex *schema_select_lex;
230
/** link to select_lex where this table was used */
231
Select_Lex *select_lex;
233
* List of all base tables local to a subquery including all view
234
* tables. Unlike 'next_local', this in this list views are *not*
235
* leaves. Created in setup_tables() -> make_leaves_list().
237
TableList *next_leaf;
165
Table *table; /* opened table */
166
uint32_t table_id; /* table id (from binlog) for opened table */
168
select_result for derived table to pass it from table creation to table
171
select_union *derived_result;
173
Reference from aux_tables to local list entry of main select of
174
multi-delete statement:
175
delete t1 from t2,t1 where t1.a<'B' and t2.b=t1.b;
176
here it will be reference of first occurrence of t1 to second (as you
177
can see this lists can't be merged)
179
TableList *correspondent_table;
180
st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */
181
ST_SCHEMA_TABLE *schema_table; /* Information_schema table */
182
st_select_lex *schema_select_lex;
184
True when the view field translation table is used to convert
185
schema table fields for backwards compatibility with SHOW command.
187
bool schema_table_reformed;
188
TMP_TABLE_PARAM *schema_table_param;
189
/* link to select_lex where this table was used */
190
st_select_lex *select_lex;
191
Field_translator *field_translation; /* array of VIEW fields */
192
/* pointer to element after last one in translation table above */
193
Field_translator *field_translation_end;
195
List (based on next_local) of underlying tables of this view. I.e. it
196
does not include the tables of subqueries used in the view. Is set only
199
TableList *merge_underlying_list;
201
List of all base tables local to a subquery including all view
202
tables. Unlike 'next_local', this in this list views are *not*
203
leaves. Created in setup_tables() -> make_leaves_list().
205
TableList *next_leaf;
238
206
thr_lock_type lock_type;
239
uint32_t outer_join; ///< Which join type
241
size_t table_name_length;
207
uint outer_join; /* Which join type */
208
uint shared; /* Used in multi-upd */
210
size_t table_name_length;
211
bool straight; /* optimize with prev table */
212
bool updating; /* for replicate-do/ignore table */
213
bool force_index; /* prefer index over table scan */
214
bool ignore_leaves; /* preload only non-leaf nodes */
215
table_map dep_tables; /* tables the table depends on */
216
table_map on_expr_dep_tables; /* tables on expression depends on */
217
nested_join_st *nested_join; /* if the element is a nested join */
218
TableList *embedding; /* nested join containing the table */
219
List<TableList> *join_list;/* join list the table belongs to */
220
bool cacheable_table; /* stop PS caching */
221
handlerton *db_type; /* table_type for handler */
222
char timestamp_buffer[20]; /* buffer for timestamp (19+1) */
224
This TableList object corresponds to the table to be created
225
so it is possible that it does not exist (used in CREATE TABLE
226
... SELECT implementation).
229
/* For transactional locking. */
230
int lock_timeout; /* NOWAIT or WAIT [X] */
231
bool lock_transactional; /* If transactional lock requested. */
232
bool internal_tmp_table;
233
/** true if an alias for this table was specified in the SQL. */
235
/** true if the table is referred to in the statement using a fully
236
qualified name (<db_name>.<table_name>).
240
uint32_t i_s_requested_object;
241
bool has_db_lookup_value;
242
bool has_table_lookup_value;
243
uint32_t table_open_method;
244
enum enum_schema_table_state schema_table_state;
243
245
void set_underlying_merge();
244
bool setup_underlying(Session *session);
247
* If you change placeholder(), please check the condition in
248
* check_transactional_lock() too.
252
* Print table as it should be in join list.
254
* @param str string where table should be printed
256
void print(Session *session, String *str, enum_query_type query_type);
258
* Sets insert_values buffer
260
* @param[in] memory pool for allocating
265
* true - out of memory
267
bool set_insert_values(memory::Root *mem_root);
269
* Find underlying base tables (TableList) which represent given
270
* table_to_find (Table)
272
* @param[in] table to find
275
* NULL if table is not found
277
* Pointer to found table reference
246
bool setup_underlying(THD *thd);
247
void cleanup_items();
249
If you change placeholder(), please check the condition in
250
check_transactional_lock() too.
254
return derived || schema_table || (create && !table->getDBStat()) || !table;
256
void print(THD *thd, String *str, enum_query_type query_type);
257
bool set_insert_values(MEM_ROOT *mem_root);
279
258
TableList *find_underlying_table(Table *table);
281
* Retrieve the first (left-most) leaf in a nested join tree with
282
* respect to name resolution.
286
* Given that 'this' is a nested table reference, recursively walk
287
* down the left-most children of 'this' until we reach a leaf
288
* table reference with respect to name resolution.
291
* If 'this' is a nested table reference - the left-most child of
292
* the tree rooted in 'this',
295
259
TableList *first_leaf_for_name_resolution();
297
* Retrieve the last (right-most) leaf in a nested join tree with
298
* respect to name resolution.
302
* Given that 'this' is a nested table reference, recursively walk
303
* down the right-most children of 'this' until we reach a leaf
304
* table reference with respect to name resolution.
307
* If 'this' is a nested table reference - the right-most child of
308
* the tree rooted in 'this',
311
260
TableList *last_leaf_for_name_resolution();
313
* Test if this is a leaf with respect to name resolution.
317
* A table reference is a leaf with respect to name resolution if
318
* it is either a leaf node in a nested join tree (table, view,
319
* schema table, subquery), or an inner node that represents a
320
* NATURAL/USING join, or a nested join with materialized join
324
* true if a leaf, false otherwise.
326
261
bool is_leaf_for_name_resolution();
327
262
inline TableList *top_table()
331
* Return subselect that contains the FROM list this table is taken from
334
* Subselect item for the subquery that contains the FROM list
335
* this table is taken from if there is any
266
Cleanup for re-execution in a prepared statement or a stored
269
void reinit_before_use(THD *thd);
339
270
Item_subselect *containing_subselect();
342
* Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
343
* st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
344
* st_table::force_index and st_table::covering_keys.
346
* @param the Table to operate on.
350
* The parser collects the index hints for each table in a "tagged list"
351
* (TableList::index_hints). Using the information in this tagged list
352
* this function sets the members Table::keys_in_use_for_query,
353
* Table::keys_in_use_for_group_by, Table::keys_in_use_for_order_by,
354
* Table::force_index and Table::covering_keys.
356
* Current implementation of the runtime does not allow mixing FORCE INDEX
357
* and USE INDEX, so this is checked here. Then the FORCE INDEX list
358
* (if non-empty) is appended to the USE INDEX list and a flag is set.
360
* Multiple hints of the same kind are processed so that each clause
361
* is applied to what is computed in the previous clause.
364
* USE INDEX (i1) USE INDEX (i2)
367
* and means "consider only i1 and i2".
370
* USE INDEX () USE INDEX (i1)
373
* and means "consider only the index i1"
375
* It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
378
* Different kind of hints (USE/FORCE/IGNORE) are processed in the following
380
* 1. All indexes in USE (or FORCE) INDEX are added to the mask.
381
* 2. All IGNORE INDEX
382
* e.g. "USE INDEX i1, IGNORE INDEX i1, USE INDEX i1" will not use i1 at all
383
* as if we had "USE INDEX i1, USE INDEX i1, IGNORE INDEX i1".
384
* As an optimization if there is a covering index, and we have
385
* IGNORE INDEX FOR GROUP/order_st, and this index is used for the JOIN part,
386
* then we have to ignore the IGNORE INDEX FROM GROUP/order_st.
389
* false no errors found
391
* true found and reported an error.
273
Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
274
st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
275
st_table::force_index and st_table::covering_keys.
393
277
bool process_index_hints(Table *table);
395
friend std::ostream& operator<<(std::ostream& output, const TableList &list)
397
output << "TableList:(";
400
output << list.table_name;
402
output << list.alias;
404
output << "is_natural_join:" << list.is_natural_join;
406
output << "is_join_columns_complete:" << list.is_join_columns_complete;
408
output << "straight:" << list.straight;
410
output << "force_index" << list.force_index;
412
output << "ignore_leaves:" << list.ignore_leaves;
414
output << "create:" << list.create;
416
output << "outer_join:" << list.outer_join;
418
output << "nested_join:" << list.nested_join;
421
return output; // for multiple << operators.
424
void setIsAlias(bool in_is_alias)
426
is_alias= in_is_alias;
429
void setIsFqtn(bool in_is_fqtn)
434
void setCreate(bool in_create)
439
void setInternalTmpTable(bool in_internal_tmp_table)
441
internal_tmp_table= in_internal_tmp_table;
444
void setDbType(plugin::StorageEngine *in_db_type)
449
void setJoinList(List<TableList> *in_join_list)
451
join_list= in_join_list;
454
void setEmbedding(TableList *in_embedding)
456
embedding= in_embedding;
459
void setNestedJoin(NestedJoin *in_nested_join)
461
nested_join= in_nested_join;
464
void setDepTables(table_map in_dep_tables)
466
dep_tables= in_dep_tables;
469
void setOnExprDepTables(table_map in_on_expr_dep_tables)
471
on_expr_dep_tables= in_on_expr_dep_tables;
474
bool getIsAlias() const
479
bool getIsFqtn() const
484
bool isCreate() const
489
bool getInternalTmpTable() const
491
return internal_tmp_table;
494
plugin::StorageEngine *getDbType() const
499
TableList *getEmbedding() const
504
List<TableList> *getJoinList() const
509
NestedJoin *getNestedJoin() const
514
table_map getDepTables() const
519
table_map getOnExprDepTables() const
521
return on_expr_dep_tables;
524
void unlock_table_name();
525
void unlock_table_names(TableList *last_table= NULL);
528
table_map dep_tables; ///< tables the table depends on
529
table_map on_expr_dep_tables; ///< tables on expression depends on
530
NestedJoin *nested_join; ///< if the element is a nested join
531
TableList *embedding; ///< nested join containing the table
532
List<TableList> *join_list; ///< join list the table belongs to
533
plugin::StorageEngine *db_type; ///< table_type for handler
534
bool internal_tmp_table;
536
/** true if an alias for this table was specified in the SQL. */
540
* true if the table is referred to in the statement using a fully
541
* qualified name (<db_name>.<table_name>).
546
* This TableList object corresponds to the table to be created
547
* so it is possible that it does not exist (used in CREATE TABLE
548
* ... SELECT implementation).
554
void close_thread_tables(Session *session);
556
} /* namespace drizzled */
558
#endif /* DRIZZLED_TABLE_LIST_H */
279
#endif /* DRIZZLED_TMP_TABLE_H */