~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_list.cc

  • Committer: Jay Pipes
  • Date: 2009-09-21 14:33:44 UTC
  • mfrom: (1126.10.26 dtrace-probes)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: jpipes@serialcoder-20090921143344-jnarp7gcn6zmg19c
Merge fixes from Trond and Padraig on dtrace probes.

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 "config.h"
 
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>
17
24
 
18
25
#include <string>
19
26
 
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
 
#include "drizzled/strfunc.h"
28
 
 
29
27
using namespace std;
30
28
 
31
 
namespace drizzled
32
 
{
33
 
 
34
29
class Item;
35
30
class Item_field;
36
31
 
 
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
 
37
55
uint32_t TableList::create_table_def_key(char *key)
38
56
{
39
57
  return TableShare::createKey(key, db, table_name);
40
58
}
41
59
 
42
 
bool TableList::set_insert_values(memory::Root *mem_root)
 
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
bool TableList::set_insert_values(MEM_ROOT *mem_root)
43
74
{
44
75
  if (table)
45
76
  {
52
83
  return false;
53
84
}
54
85
 
 
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
*/
55
103
bool TableList::is_leaf_for_name_resolution()
56
104
{
57
105
  return (is_natural_join || is_join_columns_complete || !nested_join);
58
106
}
59
107
 
 
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
 
60
156
TableList *TableList::find_underlying_table(Table *table_to_find)
61
157
{
62
158
  /* is this real table and table which we are looking for? */
66
162
  return NULL;
67
163
}
68
164
 
 
165
 
69
166
bool TableList::placeholder()
70
167
{
71
 
  return derived || (create && !table->getDBStat()) || !table;
 
168
  return derived || schema_table || (create && !table->getDBStat()) || !table;
72
169
}
73
170
 
 
171
 
74
172
/*
75
 
 * The right-most child of a nested table reference is the first
76
 
 * element in the list of children because the children are inserted
77
 
 * in reverse order.
78
 
 */
 
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
 
79
195
TableList *TableList::last_leaf_for_name_resolution()
80
196
{
81
197
  TableList *cur_table_ref= this;
109
225
  return cur_table_ref;
110
226
}
111
227
 
 
228
 
112
229
/*
113
 
 * The left-most child of a nested table reference is the last element
114
 
 * in the list of children because the children are inserted in
115
 
 * reverse order.
116
 
 */
 
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
 
117
252
TableList *TableList::first_leaf_for_name_resolution()
118
253
{
119
254
  TableList *cur_table_ref= NULL;
147
282
  return cur_table_ref;
148
283
}
149
284
 
 
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
 
150
299
Item_subselect *TableList::containing_subselect()
151
300
{
152
301
  return (select_lex ? select_lex->master_unit()->item : 0);
153
302
}
154
303
 
 
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
*/
155
356
bool TableList::process_index_hints(Table *tbl)
156
357
{
157
358
  /* initialize the result variables */
270
471
  return 0;
271
472
}
272
473
 
 
474
 
 
475
/**
 
476
  Print table as it should be in join list.
 
477
 
 
478
  @param str   string where table should be printed
 
479
*/
273
480
void TableList::print(Session *session, String *str, enum_query_type query_type)
274
481
{
275
482
  if (nested_join)
296
503
        str->append_identifier(db, db_length);
297
504
        str->append('.');
298
505
      }
299
 
      str->append_identifier(table_name, table_name_length);
300
 
      cmp_name= table_name;
 
506
      if (schema_table)
 
507
      {
 
508
        str->append_identifier(schema_table_name, strlen(schema_table_name));
 
509
        cmp_name= schema_table_name;
 
510
      }
 
511
      else
 
512
      {
 
513
        str->append_identifier(table_name, table_name_length);
 
514
        cmp_name= table_name;
 
515
      }
301
516
    }
302
517
    if (my_strcasecmp(table_alias_charset, cmp_name, alias))
303
518
    {
328
543
    }
329
544
  }
330
545
}
331
 
 
332
 
} /* namespace drizzled */