~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_list.h

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
21
 
 
22
 
#ifndef DRIZZLED_TMP_TABLE_H
23
 
#define DRIZZLED_TMP_TABLE_H
24
 
 
25
 
/*
26
 
  Table reference in the FROM clause.
27
 
 
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.
32
 
 
33
 
  1) table (TableList::view == NULL)
34
 
     - base table
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?
49
 
     - general JOIN
50
 
       TODO: how to distinguish from a table sequence?
51
 
     - NATURAL JOIN
52
 
       (TableList::natural_join != NULL)
53
 
       - JOIN ... USING
54
 
         (TableList::join_using_fields != NULL)
55
 
     - semi-join
56
 
       ;
57
 
*/
58
 
 
59
 
 
60
 
#include "table.h"
61
 
 
62
 
class Index_hint;
63
 
class COND_EQUAL;
64
 
class Natural_join_column;
65
 
class select_union;
66
 
class st_select_lex_unit;
67
 
class ST_SCHEMA_TABLE;
68
 
class st_select_lex;
69
 
class TMP_TABLE_PARAM;
70
 
class Field_translator;
71
 
class Item_subselect;
72
 
class Table;
73
 
 
74
 
enum enum_schema_table_state
75
 
76
 
  NOT_PROCESSED= 0,
77
 
  PROCESSED_BY_CREATE_SORT_INDEX,
78
 
  PROCESSED_BY_JOIN_EXEC
79
 
};
80
 
 
81
 
 
82
 
class TableList
83
 
{
84
 
public:
85
 
  TableList() {}                          /* Remove gcc warning */
86
 
 
87
 
  /**
88
 
    Prepare TableList that consists of one table instance to use in
89
 
    simple_open_and_lock_tables
90
 
  */
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)
94
 
  {
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;
99
 
  }
100
 
 
101
 
  /*
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().
105
 
  */
106
 
  TableList *next_local;
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 */
112
 
  Item          *sj_on_expr;
113
 
  /*
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
117
 
    nest's children).
118
 
  */
119
 
  table_map     sj_inner_tables;
120
 
  /* Number of IN-compared expressions */
121
 
  uint32_t          sj_in_exprs; 
122
 
  /*
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.
129
 
  */
130
 
  Item          *prep_on_expr;
131
 
  COND_EQUAL    *cond_equal;            /* Used with outer join */
132
 
  /*
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).
137
 
  */
138
 
  TableList *natural_join;
139
 
  /*
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'.
143
 
  */
144
 
  bool is_natural_join;
145
 
  /* Field names in a USING clause for JOIN ... USING. */
146
 
  List<String> *join_using_fields;
147
 
  /*
148
 
    Explicitly store the result columns of either a NATURAL/USING join or
149
 
    an operand of such a join.
150
 
  */
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;
154
 
 
155
 
  /*
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.
161
 
  */
162
 
  TableList *next_name_resolution_table;
163
 
  /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */
164
 
  List<Index_hint> *index_hints;
165
 
  Table        *table;    /* opened table */
166
 
  uint32_t          table_id; /* table id (from binlog) for opened table */
167
 
  /*
168
 
    select_result for derived table to pass it from table creation to table
169
 
    filling procedure
170
 
  */
171
 
  select_union  *derived_result;
172
 
  /*
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)
178
 
  */
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;
183
 
  /*
184
 
    True when the view field translation table is used to convert
185
 
    schema table fields for backwards compatibility with SHOW command.
186
 
  */
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;
194
 
  /*
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
197
 
    for merged views.
198
 
  */
199
 
  TableList     *merge_underlying_list;
200
 
  /*
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().
204
 
  */
205
 
  TableList     *next_leaf;
206
 
  thr_lock_type lock_type;
207
 
  uint          outer_join;             /* Which join type */
208
 
  uint          shared;                 /* Used in multi-upd */
209
 
  size_t        db_length;
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) */
223
 
  /*
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).
227
 
  */
228
 
  bool          create;
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. */
234
 
  bool          is_alias;
235
 
  /** true if the table is referred to in the statement using a fully
236
 
      qualified name (<db_name>.<table_name>).
237
 
  */
238
 
  bool          is_fqtn;
239
 
 
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;
245
 
  void set_underlying_merge();
246
 
  bool setup_underlying(THD *thd);
247
 
  void cleanup_items();
248
 
  /*
249
 
    If you change placeholder(), please check the condition in
250
 
    check_transactional_lock() too.
251
 
  */
252
 
  bool placeholder()
253
 
  {
254
 
    return derived || schema_table || (create && !table->getDBStat()) || !table;
255
 
  }
256
 
  void print(THD *thd, String *str, enum_query_type query_type);
257
 
  bool set_insert_values(MEM_ROOT *mem_root);
258
 
  TableList *find_underlying_table(Table *table);
259
 
  TableList *first_leaf_for_name_resolution();
260
 
  TableList *last_leaf_for_name_resolution();
261
 
  bool is_leaf_for_name_resolution();
262
 
  inline TableList *top_table()
263
 
    { return this; }
264
 
 
265
 
  /*
266
 
    Cleanup for re-execution in a prepared statement or a stored
267
 
    procedure.
268
 
  */
269
 
  void reinit_before_use(THD *thd);
270
 
  Item_subselect *containing_subselect();
271
 
 
272
 
  /* 
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.
276
 
  */
277
 
  bool process_index_hints(Table *table);
278
 
};
279
 
#endif /* DRIZZLED_TMP_TABLE_H */