~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_list.cc

  • Committer: Eric Day
  • Date: 2009-10-31 21:53:33 UTC
  • mfrom: (1200 staging)
  • mto: This revision was merged to the branch mainline in revision 1202.
  • Revision ID: eday@oddments.org-20091031215333-j94bjoanwmi68p6f
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
  along with this program; if not, write to the Free Software
14
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/error.h>
17
 
#include <drizzled/table_list.h>
18
 
#include <drizzled/item.h>
19
 
#include <drizzled/item/field.h>
20
 
#include <drizzled/nested_join.h>
21
 
#include <drizzled/sql_lex.h>
22
 
#include <drizzled/server_includes.h>
23
 
#include <drizzled/sql_select.h>
 
16
#include "drizzled/server_includes.h"
24
17
 
25
18
#include <string>
26
19
 
 
20
#include "drizzled/error.h"
 
21
#include "drizzled/table_list.h"
 
22
#include "drizzled/item.h"
 
23
#include "drizzled/item/field.h"
 
24
#include "drizzled/nested_join.h"
 
25
#include "drizzled/sql_lex.h"
 
26
#include "drizzled/sql_select.h"
 
27
 
27
28
using namespace std;
28
29
 
29
30
class Item;
30
31
class Item_field;
31
32
 
32
 
/*
33
 
  Create a table cache key
34
 
 
35
 
  SYNOPSIS
36
 
  create_table_def_key()
37
 
  key                   Create key here (must be of size MAX_DBKEY_LENGTH)
38
 
  table_list            Table definition
39
 
 
40
 
  IMPLEMENTATION
41
 
  The table cache_key is created from:
42
 
  db_name + \0
43
 
  table_name + \0
44
 
 
45
 
  if the table is a tmp table, we add the following to make each tmp table
46
 
  unique on the slave:
47
 
 
48
 
  4 bytes for master thread id
49
 
  4 bytes pseudo thread id
50
 
 
51
 
  RETURN
52
 
  Length of key
53
 
*/
54
 
 
55
33
uint32_t TableList::create_table_def_key(char *key)
56
34
{
57
35
  return TableShare::createKey(key, db, table_name);
58
36
}
59
37
 
60
 
 
61
 
/*
62
 
  Set insert_values buffer
63
 
 
64
 
  SYNOPSIS
65
 
    set_insert_values()
66
 
    mem_root   memory pool for allocating
67
 
 
68
 
  RETURN
69
 
    false - OK
70
 
    TRUE  - out of memory
71
 
*/
72
 
 
73
38
bool TableList::set_insert_values(MEM_ROOT *mem_root)
74
39
{
75
40
  if (table)
83
48
  return false;
84
49
}
85
50
 
86
 
 
87
 
/*
88
 
  Test if this is a leaf with respect to name resolution.
89
 
 
90
 
  SYNOPSIS
91
 
    TableList::is_leaf_for_name_resolution()
92
 
 
93
 
  DESCRIPTION
94
 
    A table reference is a leaf with respect to name resolution if
95
 
    it is either a leaf node in a nested join tree (table, view,
96
 
    schema table, subquery), or an inner node that represents a
97
 
    NATURAL/USING join, or a nested join with materialized join
98
 
    columns.
99
 
 
100
 
  RETURN
101
 
    TRUE if a leaf, false otherwise.
102
 
*/
103
51
bool TableList::is_leaf_for_name_resolution()
104
52
{
105
53
  return (is_natural_join || is_join_columns_complete || !nested_join);
106
54
}
107
55
 
108
 
 
109
 
 
110
 
/*
111
 
  Create Item_field for each column in the table.
112
 
 
113
 
  SYNPOSIS
114
 
    Table::fill_item_list()
115
 
      item_list          a pointer to an empty list used to store items
116
 
 
117
 
  DESCRIPTION
118
 
    Create Item_field object for each column in the table and
119
 
    initialize it with the corresponding Field. New items are
120
 
    created in the current Session memory root.
121
 
 
122
 
  RETURN VALUE
123
 
    0                    success
124
 
    1                    out of memory
125
 
*/
126
 
 
127
 
bool Table::fill_item_list(List<Item> *item_list) const
128
 
{
129
 
  /*
130
 
    All Item_field's created using a direct pointer to a field
131
 
    are fixed in Item_field constructor.
132
 
  */
133
 
  for (Field **ptr= field; *ptr; ptr++)
134
 
  {
135
 
    Item_field *item= new Item_field(*ptr);
136
 
    if (!item || item_list->push_back(item))
137
 
      return true;
138
 
  }
139
 
  return false;
140
 
}
141
 
 
142
 
 
143
 
/*
144
 
  Find underlying base tables (TableList) which represent given
145
 
  table_to_find (Table)
146
 
 
147
 
  SYNOPSIS
148
 
    TableList::find_underlying_table()
149
 
    table_to_find table to find
150
 
 
151
 
  RETURN
152
 
    0  table is not found
153
 
    found table reference
154
 
*/
155
 
 
156
56
TableList *TableList::find_underlying_table(Table *table_to_find)
157
57
{
158
58
  /* is this real table and table which we are looking for? */
162
62
  return NULL;
163
63
}
164
64
 
165
 
 
166
65
bool TableList::placeholder()
167
66
{
168
67
  return derived || schema_table || (create && !table->getDBStat()) || !table;
169
68
}
170
69
 
171
 
 
172
70
/*
173
 
  Retrieve the last (right-most) leaf in a nested join tree with
174
 
  respect to name resolution.
175
 
 
176
 
  SYNOPSIS
177
 
    TableList::last_leaf_for_name_resolution()
178
 
 
179
 
  DESCRIPTION
180
 
    Given that 'this' is a nested table reference, recursively walk
181
 
    down the right-most children of 'this' until we reach a leaf
182
 
    table reference with respect to name resolution.
183
 
 
184
 
  IMPLEMENTATION
185
 
    The right-most child of a nested table reference is the first
186
 
    element in the list of children because the children are inserted
187
 
    in reverse order.
188
 
 
189
 
  RETURN
190
 
    - If 'this' is a nested table reference - the right-most child of
191
 
      the tree rooted in 'this',
192
 
    - else - 'this'
193
 
*/
194
 
 
 
71
 * The right-most child of a nested table reference is the first
 
72
 * element in the list of children because the children are inserted
 
73
 * in reverse order.
 
74
 */
195
75
TableList *TableList::last_leaf_for_name_resolution()
196
76
{
197
77
  TableList *cur_table_ref= this;
225
105
  return cur_table_ref;
226
106
}
227
107
 
228
 
 
229
108
/*
230
 
  Retrieve the first (left-most) leaf in a nested join tree with
231
 
  respect to name resolution.
232
 
 
233
 
  SYNOPSIS
234
 
    TableList::first_leaf_for_name_resolution()
235
 
 
236
 
  DESCRIPTION
237
 
    Given that 'this' is a nested table reference, recursively walk
238
 
    down the left-most children of 'this' until we reach a leaf
239
 
    table reference with respect to name resolution.
240
 
 
241
 
  IMPLEMENTATION
242
 
    The left-most child of a nested table reference is the last element
243
 
    in the list of children because the children are inserted in
244
 
    reverse order.
245
 
 
246
 
  RETURN
247
 
    If 'this' is a nested table reference - the left-most child of
248
 
      the tree rooted in 'this',
249
 
    else return 'this'
250
 
*/
251
 
 
 
109
 * The left-most child of a nested table reference is the last element
 
110
 * in the list of children because the children are inserted in
 
111
 * reverse order.
 
112
 */
252
113
TableList *TableList::first_leaf_for_name_resolution()
253
114
{
254
115
  TableList *cur_table_ref= NULL;
282
143
  return cur_table_ref;
283
144
}
284
145
 
285
 
 
286
 
/*
287
 
  Return subselect that contains the FROM list this table is taken from
288
 
 
289
 
  SYNOPSIS
290
 
    TableList::containing_subselect()
291
 
 
292
 
  RETURN
293
 
    Subselect item for the subquery that contains the FROM list
294
 
    this table is taken from if there is any
295
 
    0 - otherwise
296
 
 
297
 
*/
298
 
 
299
146
Item_subselect *TableList::containing_subselect()
300
147
{
301
148
  return (select_lex ? select_lex->master_unit()->item : 0);
302
149
}
303
150
 
304
 
 
305
 
/*
306
 
  Compiles the tagged hints list and fills up the bitmasks.
307
 
 
308
 
  SYNOPSIS
309
 
    process_index_hints()
310
 
      table         the Table to operate on.
311
 
 
312
 
  DESCRIPTION
313
 
    The parser collects the index hints for each table in a "tagged list"
314
 
    (TableList::index_hints). Using the information in this tagged list
315
 
    this function sets the members Table::keys_in_use_for_query,
316
 
    Table::keys_in_use_for_group_by, Table::keys_in_use_for_order_by,
317
 
    Table::force_index and Table::covering_keys.
318
 
 
319
 
    Current implementation of the runtime does not allow mixing FORCE INDEX
320
 
    and USE INDEX, so this is checked here. Then the FORCE INDEX list
321
 
    (if non-empty) is appended to the USE INDEX list and a flag is set.
322
 
 
323
 
    Multiple hints of the same kind are processed so that each clause
324
 
    is applied to what is computed in the previous clause.
325
 
    For example:
326
 
        USE INDEX (i1) USE INDEX (i2)
327
 
    is equivalent to
328
 
        USE INDEX (i1,i2)
329
 
    and means "consider only i1 and i2".
330
 
 
331
 
    Similarly
332
 
        USE INDEX () USE INDEX (i1)
333
 
    is equivalent to
334
 
        USE INDEX (i1)
335
 
    and means "consider only the index i1"
336
 
 
337
 
    It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
338
 
    not an error.
339
 
 
340
 
    Different kind of hints (USE/FORCE/IGNORE) are processed in the following
341
 
    order:
342
 
      1. All indexes in USE (or FORCE) INDEX are added to the mask.
343
 
      2. All IGNORE INDEX
344
 
 
345
 
    e.g. "USE INDEX i1, IGNORE INDEX i1, USE INDEX i1" will not use i1 at all
346
 
    as if we had "USE INDEX i1, USE INDEX i1, IGNORE INDEX i1".
347
 
 
348
 
    As an optimization if there is a covering index, and we have
349
 
    IGNORE INDEX FOR GROUP/order_st, and this index is used for the JOIN part,
350
 
    then we have to ignore the IGNORE INDEX FROM GROUP/order_st.
351
 
 
352
 
  RETURN VALUE
353
 
    false                no errors found
354
 
    TRUE                 found and reported an error.
355
 
*/
356
151
bool TableList::process_index_hints(Table *tbl)
357
152
{
358
153
  /* initialize the result variables */
471
266
  return 0;
472
267
}
473
268
 
474
 
 
475
 
/**
476
 
  Print table as it should be in join list.
477
 
 
478
 
  @param str   string where table should be printed
479
 
*/
480
269
void TableList::print(Session *session, String *str, enum_query_type query_type)
481
270
{
482
271
  if (nested_join)