12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
16
#include <drizzled/error.h>
21
17
#include <drizzled/table_list.h>
23
19
#include <drizzled/item/field.h>
24
20
#include <drizzled/nested_join.h>
25
21
#include <drizzled/sql_lex.h>
22
#include <drizzled/server_includes.h>
26
23
#include <drizzled/sql_select.h>
27
#include <drizzled/strfunc.h>
29
27
using namespace std;
37
bool TableList::set_insert_values(memory::Root *)
33
Create a table cache key
36
create_table_def_key()
37
key Create key here (must be of size MAX_DBKEY_LENGTH)
38
table_list Table definition
41
The table cache_key is created from:
45
if the table is a tmp table, we add the following to make each tmp table
48
4 bytes for master thread id
49
4 bytes pseudo thread id
55
uint32_t TableList::create_table_def_key(char *key)
57
return TableShare::createKey(key, db, table_name);
62
Set insert_values buffer
66
mem_root memory pool for allocating
73
bool TableList::set_insert_values(MEM_ROOT *mem_root)
41
table->insert_values.resize(table->getShare()->rec_buff_length);
77
if (!table->insert_values &&
78
!(table->insert_values= (unsigned char *)alloc_root(mem_root,
79
table->s->rec_buff_length)))
88
Test if this is a leaf with respect to name resolution.
91
TableList::is_leaf_for_name_resolution()
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
101
TRUE if a leaf, false otherwise.
47
103
bool TableList::is_leaf_for_name_resolution()
49
105
return (is_natural_join || is_join_columns_complete || !nested_join);
111
Create Item_field for each column in the table.
114
Table::fill_item_list()
115
item_list a pointer to an empty list used to store items
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.
127
bool Table::fill_item_list(List<Item> *item_list) const
130
All Item_field's created using a direct pointer to a field
131
are fixed in Item_field constructor.
133
for (Field **ptr= field; *ptr; ptr++)
135
Item_field *item= new Item_field(*ptr);
136
if (!item || item_list->push_back(item))
144
Find underlying base tables (TableList) which represent given
145
table_to_find (Table)
148
TableList::find_underlying_table()
149
table_to_find table to find
153
found table reference
52
156
TableList *TableList::find_underlying_table(Table *table_to_find)
54
158
/* is this real table and table which we are looking for? */
61
bool TableList::isCartesian() const
66
166
bool TableList::placeholder()
68
return derived || (create && !table->getDBStat()) || !table;
168
return derived || schema_table || (create && !table->getDBStat()) || !table;
72
* The right-most child of a nested table reference is the first
73
* element in the list of children because the children are inserted
173
Retrieve the last (right-most) leaf in a nested join tree with
174
respect to name resolution.
177
TableList::last_leaf_for_name_resolution()
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.
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
190
- If 'this' is a nested table reference - the right-most child of
191
the tree rooted in 'this',
76
195
TableList *TableList::last_leaf_for_name_resolution()
78
197
TableList *cur_table_ref= this;
79
NestedJoin *cur_nested_join;
198
nested_join_st *cur_nested_join;
81
200
if (is_leaf_for_name_resolution())
106
225
return cur_table_ref;
110
* The left-most child of a nested table reference is the last element
111
* in the list of children because the children are inserted in
230
Retrieve the first (left-most) leaf in a nested join tree with
231
respect to name resolution.
234
TableList::first_leaf_for_name_resolution()
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.
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
247
If 'this' is a nested table reference - the left-most child of
248
the tree rooted in 'this',
114
252
TableList *TableList::first_leaf_for_name_resolution()
116
254
TableList *cur_table_ref= NULL;
117
NestedJoin *cur_nested_join;
255
nested_join_st *cur_nested_join;
119
257
if (is_leaf_for_name_resolution())
144
282
return cur_table_ref;
287
Return subselect that contains the FROM list this table is taken from
290
TableList::containing_subselect()
293
Subselect item for the subquery that contains the FROM list
294
this table is taken from if there is any
147
299
Item_subselect *TableList::containing_subselect()
149
301
return (select_lex ? select_lex->master_unit()->item : 0);
306
Compiles the tagged hints list and fills up the bitmasks.
309
process_index_hints()
310
table the Table to operate on.
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.
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.
323
Multiple hints of the same kind are processed so that each clause
324
is applied to what is computed in the previous clause.
326
USE INDEX (i1) USE INDEX (i2)
329
and means "consider only i1 and i2".
332
USE INDEX () USE INDEX (i1)
335
and means "consider only the index i1"
337
It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
340
Different kind of hints (USE/FORCE/IGNORE) are processed in the following
342
1. All indexes in USE (or FORCE) INDEX are added to the mask.
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".
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.
353
false no errors found
354
TRUE found and reported an error.
152
356
bool TableList::process_index_hints(Table *tbl)
154
358
/* initialize the result variables */
155
359
tbl->keys_in_use_for_query= tbl->keys_in_use_for_group_by=
156
tbl->keys_in_use_for_order_by= tbl->getShare()->keys_in_use;
360
tbl->keys_in_use_for_order_by= tbl->s->keys_in_use;
158
362
/* index hint list processing */
166
370
bool have_empty_use_join= false, have_empty_use_order= false,
167
371
have_empty_use_group= false;
168
List_iterator <Index_hint> iter(index_hints->begin());
372
List_iterator <Index_hint> iter(*index_hints);
170
374
/* initialize temporary variables used to collect hints of each kind */
171
375
for (type= INDEX_HINT_IGNORE; type <= INDEX_HINT_FORCE; type++)
205
409
Check if an index with the given name exists and get his offset in
206
410
the keys bitmask for the table
208
if (not tbl->getShare()->doesKeyNameExist(hint->key_name.str, hint->key_name.length, pos))
412
if (tbl->s->keynames.type_names == 0 ||
413
(pos= find_type(&tbl->s->keynames, hint->key_name.str,
414
hint->key_name.length, 1)) <= 0)
210
416
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name.str, alias);
213
422
/* add to the appropriate clause mask */
214
423
if (hint->clause & INDEX_HINT_MASK_JOIN)
215
424
index_join[hint->type].set(pos);
288
503
str->append_identifier(db, db_length);
289
504
str->append('.');
291
str->append_identifier(table_name, table_name_length);
292
cmp_name= table_name;
508
str->append_identifier(schema_table_name, strlen(schema_table_name));
509
cmp_name= schema_table_name;
513
str->append_identifier(table_name, table_name_length);
514
cmp_name= table_name;
294
517
if (my_strcasecmp(table_alias_charset, cmp_name, alias))