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