~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
20
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
21
#ifndef DRIZZLED_TABLE_LIST_H
22
#define DRIZZLED_TABLE_LIST_H
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
23
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
24
#include <drizzled/table.h>
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
25
26
class Index_hint;
27
class COND_EQUAL;
28
class Natural_join_column;
29
class select_union;
848 by Brian Aker
typdef class removal (just... use the name of the class).
30
class Select_Lex_Unit;
846 by Brian Aker
Removing on typedeffed class.
31
class Select_Lex;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
32
class Tmp_Table_Param;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
33
class Item_subselect;
34
class Table;
35
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
36
namespace drizzled
37
{
38
namespace plugin
39
{
1130.1.7 by Monty Taylor
Renamed plugin::InfoSchema to plugin::InfoSchemaTable as per Jay.
40
  class InfoSchemaTable;
1130.3.9 by Monty Taylor
Wrapped table_proto_write.cc code in namespace drizzled.
41
  class StorageEngine;
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
42
}
43
}
44
553.1.3 by Monty Taylor
Split out nested_join.h.
45
struct nested_join_st;
46
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
47
/**
48
 * A Table referenced in the FROM clause.
49
 *
50
 * These table references can be of several types that correspond to
51
 * different SQL elements. Below we list all types of TableLists with
52
 * the necessary conditions to determine when a TableList instance
53
 * belongs to a certain type.
54
 *
55
 * 1) table (TableList::view == NULL)
56
 *    - base table
57
 *    (TableList::derived == NULL)
58
 *    - subquery - TableList::table is a temp table
59
 *    (TableList::derived != NULL)
60
 *    - information schema table
61
 *    (TableList::schema_table != NULL)
62
 *    
63
 *    @note
64
 *
65
 *    for schema tables TableList::field_translation may be != NULL
66
 *
67
 * 2) Was VIEW 
68
 * 3) nested table reference (TableList::nested_join != NULL)
69
 *     - table sequence - e.g. (t1, t2, t3)
70
 *     @todo how to distinguish from a JOIN?
71
 *     - general JOIN
72
 *     @todo how to distinguish from a table sequence?
73
 *     - NATURAL JOIN
74
 *     (TableList::natural_join != NULL)
75
 *     - JOIN ... USING
76
 *     (TableList::join_using_fields != NULL)
77
 *     - semi-join
78
 */
327.2.4 by Brian Aker
Refactoring table.h
79
class TableList
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
80
{
81
public:
1034.1.4 by Brian Aker
Fixed TableList to correctly construct (and removed memset() calls in
82
  TableList():
83
    next_local(NULL),
84
    next_global(NULL),
85
    prev_global(NULL),
86
    db(NULL),
87
    alias(NULL),
88
    table_name(NULL),
89
    schema_table_name(NULL),
90
    option(NULL),
91
    on_expr(NULL),
92
    table(NULL),
93
    prep_on_expr(NULL),
94
    cond_equal(NULL),
95
    natural_join(NULL),
96
    is_natural_join(false),
97
    is_join_columns_complete(false),
98
    straight(false),
99
    updating(false), 
100
    force_index(false),
101
    ignore_leaves(false),
102
    create(false),
103
    join_using_fields(NULL),
104
    join_columns(NULL),
105
    next_name_resolution_table(NULL),
106
    index_hints(NULL),
107
    derived_result(NULL),
108
    derived(NULL),
109
    schema_table(NULL),
110
    schema_select_lex(NULL),
111
    schema_table_param(NULL),
112
    select_lex(NULL),
113
    next_leaf(NULL),
114
    outer_join(0),
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
115
    shared(0),
1034.1.4 by Brian Aker
Fixed TableList to correctly construct (and removed memset() calls in
116
    i_s_requested_object(0),
117
    db_length(0),
118
    table_name_length(0),
119
    dep_tables(0),
120
    on_expr_dep_tables(0),
121
    nested_join(NULL),
122
    embedding(NULL),
123
    join_list(NULL),
124
    db_type(NULL),
125
    internal_tmp_table(false),
126
    is_alias(false),
127
    is_fqtn(false),
128
    has_db_lookup_value(false),
129
    has_table_lookup_value(false),
130
    table_open_method(0)
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
131
  {}
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
132
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
133
  /**
134
   * List of tables local to a subquery (used by SQL_LIST). Considers
135
   * views as leaves (unlike 'next_leaf' below). Created at parse time
136
   * in Select_Lex::add_table_to_list() -> table_list.link_in_list().
137
   */
327.2.4 by Brian Aker
Refactoring table.h
138
  TableList *next_local;
1034.1.4 by Brian Aker
Fixed TableList to correctly construct (and removed memset() calls in
139
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
140
  /** link in a global list of all queries tables */
1034.1.4 by Brian Aker
Fixed TableList to correctly construct (and removed memset() calls in
141
  TableList *next_global; 
142
  TableList **prev_global;
143
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
144
  char *db;
145
  const char *alias;
146
  char *table_name;
147
  char *schema_table_name;
148
  char *option; ///< Used by cache index
149
  Item *on_expr; ///< Used with outer join
150
  Table *table; ///< opened table
151
  /**
152
   * The structure of ON expression presented in the member above
153
   * can be changed during certain optimizations. This member
154
   * contains a snapshot of AND-OR structure of the ON expression
155
   * made after permanent transformations of the parse tree, and is
156
   * used to restore ON clause before every reexecution of a prepared
157
   * statement or stored procedure.
158
   */
159
  Item *prep_on_expr;
160
  COND_EQUAL *cond_equal; ///< Used with outer join
161
  /**
162
   * During parsing - left operand of NATURAL/USING join where 'this' is
163
   * the right operand. After parsing (this->natural_join == this) iff
164
   * 'this' represents a NATURAL or USING join operation. Thus after
165
   * parsing 'this' is a NATURAL/USING join iff (natural_join != NULL).
166
   */
327.2.4 by Brian Aker
Refactoring table.h
167
  TableList *natural_join;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
168
  /**
169
   * True if 'this' represents a nested join that is a NATURAL JOIN.
170
   * For one of the operands of 'this', the member 'natural_join' points
171
   * to the other operand of 'this'.
172
   */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
173
  bool is_natural_join;
1030.1.2 by Brian Aker
More alignment for structures
174
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
175
  /** true if join_columns contains all columns of this table reference. */
1030.1.2 by Brian Aker
More alignment for structures
176
  bool is_join_columns_complete;
177
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
178
  bool straight; ///< optimize with prev table
179
  bool updating; ///< for replicate-do/ignore table
180
  bool force_index; ///< prefer index over table scan
181
  bool ignore_leaves; ///< preload only non-leaf nodes
182
183
  /**
184
   * This TableList object corresponds to the table to be created
185
   * so it is possible that it does not exist (used in CREATE TABLE
186
   * ... SELECT implementation).
187
   */
188
  bool create;
189
190
  /** Field names in a USING clause for JOIN ... USING. */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
191
  List<String> *join_using_fields;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
192
  /**
193
   * Explicitly store the result columns of either a NATURAL/USING join or
194
   * an operand of such a join.
195
   */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
196
  List<Natural_join_column> *join_columns;
197
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
198
  /**
199
   * List of nodes in a nested join tree, that should be considered as
200
   * leaves with respect to name resolution. The leaves are: views,
201
   * top-most nodes representing NATURAL/USING joins, subqueries, and
202
   * base tables. All of these TableList instances contain a
203
   * materialized list of columns. The list is local to a subquery.
204
   */
327.2.4 by Brian Aker
Refactoring table.h
205
  TableList *next_name_resolution_table;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
206
  /** Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
207
  List<Index_hint> *index_hints;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
208
  /**
209
   * select_result for derived table to pass it from table creation to table
210
   * filling procedure
211
   */
212
  select_union *derived_result;
213
  Select_Lex_Unit *derived; ///< Select_Lex_Unit of derived table */
214
  drizzled::plugin::InfoSchemaTable *schema_table; ///< Information_schema table
215
  Select_Lex *schema_select_lex;
851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
216
  Tmp_Table_Param *schema_table_param;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
217
  /** link to select_lex where this table was used */
218
  Select_Lex *select_lex;
219
  /**
220
   * List of all base tables local to a subquery including all view
221
   * tables. Unlike 'next_local', this in this list views are *not*
222
   * leaves. Created in setup_tables() -> make_leaves_list().
223
   */
224
  TableList *next_leaf;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
225
  thr_lock_type lock_type;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
226
  uint32_t outer_join; ///< Which join type
227
  uint32_t shared; ///<Used in multi-upd
1030.1.2 by Brian Aker
More alignment for structures
228
  uint32_t i_s_requested_object;
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
229
  size_t db_length;
230
  size_t table_name_length;
231
  table_map dep_tables; ///< tables the table depends on
232
  table_map on_expr_dep_tables; ///< tables on expression depends on
233
  nested_join_st *nested_join; ///< if the element is a nested join
234
  TableList *embedding; ///< nested join containing the table
235
  List<TableList> *join_list; ///< join list the table belongs to
236
  drizzled::plugin::StorageEngine *db_type; ///< table_type for handler
237
  char timestamp_buffer[20]; ///< buffer for timestamp (19+1)
238
  bool internal_tmp_table;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
239
  /** true if an alias for this table was specified in the SQL. */
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
240
  bool is_alias;
241
  /** 
242
   * true if the table is referred to in the statement using a fully
243
   * qualified name (<db_name>.<table_name>).
244
   */
245
  bool is_fqtn;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
246
247
  bool has_db_lookup_value;
248
  bool has_table_lookup_value;
482 by Brian Aker
Remove uint.
249
  uint32_t table_open_method;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
250
  enum enum_schema_table_state schema_table_state;
1034.1.4 by Brian Aker
Fixed TableList to correctly construct (and removed memset() calls in
251
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
252
  void set_underlying_merge();
520.1.22 by Brian Aker
Second pass of thd cleanup
253
  bool setup_underlying(Session *session);
1034.1.4 by Brian Aker
Fixed TableList to correctly construct (and removed memset() calls in
254
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
255
  /**
256
   * If you change placeholder(), please check the condition in
257
   * check_transactional_lock() too.
258
   */
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
259
  bool placeholder();
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
260
  /**
261
   * Print table as it should be in join list.
262
   * 
263
   * @param str   string where table should be printed
264
   */
520.1.22 by Brian Aker
Second pass of thd cleanup
265
  void print(Session *session, String *str, enum_query_type query_type);
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
266
  /**
267
   * Sets insert_values buffer
268
   *
269
   * @param[in] memory pool for allocating
270
   *
271
   * @retval
272
   *  false - OK
273
   * @retval
274
   *  true - out of memory
275
   */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
276
  bool set_insert_values(MEM_ROOT *mem_root);
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
277
  /**
278
   * Find underlying base tables (TableList) which represent given
279
   * table_to_find (Table)
280
   *
281
   * @param[in] table to find
282
   *
283
   * @retval
284
   *  NULL if table is not found
285
   * @retval
286
   *  Pointer to found table reference
287
   */
327.2.4 by Brian Aker
Refactoring table.h
288
  TableList *find_underlying_table(Table *table);
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
289
  /**
290
   * Retrieve the first (left-most) leaf in a nested join tree with
291
   * respect to name resolution.
292
   *
293
   * @details
294
   *
295
   * Given that 'this' is a nested table reference, recursively walk
296
   * down the left-most children of 'this' until we reach a leaf
297
   * table reference with respect to name resolution.
298
   *
299
   * @retval
300
   *  If 'this' is a nested table reference - the left-most child of
301
   *  the tree rooted in 'this',
302
   *  else return 'this'
303
   */
327.2.4 by Brian Aker
Refactoring table.h
304
  TableList *first_leaf_for_name_resolution();
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
305
  /**
306
   * Retrieve the last (right-most) leaf in a nested join tree with
307
   * respect to name resolution.
308
   *
309
   * @details
310
   *
311
   * Given that 'this' is a nested table reference, recursively walk
312
   * down the right-most children of 'this' until we reach a leaf
313
   * table reference with respect to name resolution.
314
   *
315
   * @retval
316
   *  If 'this' is a nested table reference - the right-most child of
317
   *  the tree rooted in 'this',
318
   *  else 'this'
319
   */
327.2.4 by Brian Aker
Refactoring table.h
320
  TableList *last_leaf_for_name_resolution();
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
321
  /**
322
   * Test if this is a leaf with respect to name resolution.
323
   *
324
   * @details
325
   * 
326
   * A table reference is a leaf with respect to name resolution if
327
   * it is either a leaf node in a nested join tree (table, view,
328
   * schema table, subquery), or an inner node that represents a
329
   * NATURAL/USING join, or a nested join with materialized join
330
   * columns.
331
   *
332
   * @retval
333
   *  true if a leaf, false otherwise.
334
   */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
335
  bool is_leaf_for_name_resolution();
327.2.4 by Brian Aker
Refactoring table.h
336
  inline TableList *top_table()
1054.1.7 by Brian Aker
Refactor TableList methods.
337
  { return this; }
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
338
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
339
  /**
340
   * Return subselect that contains the FROM list this table is taken from
341
   *
342
   * @retval
343
   *  Subselect item for the subquery that contains the FROM list
344
   *  this table is taken from if there is any
345
   * @retval
346
   *  NULL otherwise
347
   */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
348
  Item_subselect *containing_subselect();
349
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
350
  /**
351
   * Compiles the tagged hints list and fills up st_table::keys_in_use_for_query,
352
   * st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by,
353
   * st_table::force_index and st_table::covering_keys.
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
354
   *
355
   * @param the Table to operate on.
356
   *
357
   * @details
358
   *
359
   * The parser collects the index hints for each table in a "tagged list"
360
   * (TableList::index_hints). Using the information in this tagged list
361
   * this function sets the members Table::keys_in_use_for_query,
362
   * Table::keys_in_use_for_group_by, Table::keys_in_use_for_order_by,
363
   * Table::force_index and Table::covering_keys.
364
   *
365
   * Current implementation of the runtime does not allow mixing FORCE INDEX
366
   * and USE INDEX, so this is checked here. Then the FORCE INDEX list
367
   * (if non-empty) is appended to the USE INDEX list and a flag is set.
368
   * 
369
   * Multiple hints of the same kind are processed so that each clause
370
   * is applied to what is computed in the previous clause.
371
   * 
372
   * For example:
373
   *       USE INDEX (i1) USE INDEX (i2)
374
   *    is equivalent to
375
   *       USE INDEX (i1,i2)
376
   *    and means "consider only i1 and i2".
377
   *
378
   * Similarly
379
   *       USE INDEX () USE INDEX (i1)
380
   *    is equivalent to
381
   *       USE INDEX (i1)
382
   *    and means "consider only the index i1"
383
   *
384
   * It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
385
   * not an error.
386
   *
387
   * Different kind of hints (USE/FORCE/IGNORE) are processed in the following
388
   * order:
389
   *    1. All indexes in USE (or FORCE) INDEX are added to the mask.
390
   *    2. All IGNORE INDEX
391
   *       e.g. "USE INDEX i1, IGNORE INDEX i1, USE INDEX i1" will not use i1 at all
392
   *       as if we had "USE INDEX i1, USE INDEX i1, IGNORE INDEX i1".
393
   *       As an optimization if there is a covering index, and we have
394
   *       IGNORE INDEX FOR GROUP/order_st, and this index is used for the JOIN part,
395
   *       then we have to ignore the IGNORE INDEX FROM GROUP/order_st.
396
   *
397
   * @retval
398
   *   false no errors found
399
   * @retval
400
   *   true found and reported an error.
1188.1.1 by Jay Pipes
Style-only cleanups and doxygenation of TableList class and its members.
401
   */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
402
  bool process_index_hints(Table *table);
1188.1.2 by Jay Pipes
Style and doxygen cleanup ONLY. Moves method documentation from source into header files. Removes TAB characters and cleans up indentation.
403
  /**
404
   * Creates a table definition cache key for this table entry.
405
   *
406
   * @param[out] Create key here (must be of size MAX_DBKEY_LENGTH)
407
   *
408
   * @note
409
   *
410
   * The table cache_key is created from:
411
   *   db_name + \0
412
   *   table_name + \0
413
   *
414
   * if the table is a tmp table, we add the following to make each tmp table
415
   * unique on the slave:
416
   *
417
   * 4 bytes for master thread id
418
   * 4 bytes pseudo thread id
419
   *
420
   * @retval
421
   *  Length of key
422
   */
1054.1.7 by Brian Aker
Refactor TableList methods.
423
  uint32_t create_table_def_key(char *key);
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
424
};
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
425
426
void close_thread_tables(Session *session);
427
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
428
#endif /* DRIZZLED_TABLE_LIST_H */