1928
Create Item_field for each column in the table.
1931
Table::fill_item_list()
1932
item_list a pointer to an empty list used to store items
1935
Create Item_field object for each column in the table and
1936
initialize it with the corresponding Field. New items are
1937
created in the current Session memory root.
1944
bool Table::fill_item_list(List<Item> *item_list) const
1947
All Item_field's created using a direct pointer to a field
1948
are fixed in Item_field constructor.
1950
for (Field **ptr= field; *ptr; ptr++)
1952
Item_field *item= new Item_field(*ptr);
1953
if (!item || item_list->push_back(item))
1961
Find underlying base tables (TableList) which represent given
1962
table_to_find (Table)
1965
TableList::find_underlying_table()
1966
table_to_find table to find
1969
0 table is not found
1970
found table reference
1973
TableList *TableList::find_underlying_table(Table *table_to_find)
1975
/* is this real table and table which we are looking for? */
1976
if (table == table_to_find)
1983
bool TableList::placeholder()
1985
return derived || schema_table || (create && !table->getDBStat()) || !table;
1990
Set insert_values buffer
1994
mem_root memory pool for allocating
1998
TRUE - out of memory
2001
bool TableList::set_insert_values(MEM_ROOT *mem_root)
2005
if (!table->insert_values &&
2006
!(table->insert_values= (unsigned char *)alloc_root(mem_root,
2007
table->s->rec_buff_length)))
2016
Test if this is a leaf with respect to name resolution.
2019
TableList::is_leaf_for_name_resolution()
2022
A table reference is a leaf with respect to name resolution if
2023
it is either a leaf node in a nested join tree (table, view,
2024
schema table, subquery), or an inner node that represents a
2025
NATURAL/USING join, or a nested join with materialized join
2029
TRUE if a leaf, false otherwise.
2031
bool TableList::is_leaf_for_name_resolution()
2033
return (is_natural_join || is_join_columns_complete || !nested_join);
2038
Retrieve the first (left-most) leaf in a nested join tree with
2039
respect to name resolution.
2042
TableList::first_leaf_for_name_resolution()
2045
Given that 'this' is a nested table reference, recursively walk
2046
down the left-most children of 'this' until we reach a leaf
2047
table reference with respect to name resolution.
2050
The left-most child of a nested table reference is the last element
2051
in the list of children because the children are inserted in
2055
If 'this' is a nested table reference - the left-most child of
2056
the tree rooted in 'this',
2060
TableList *TableList::first_leaf_for_name_resolution()
2062
TableList *cur_table_ref= NULL;
2063
nested_join_st *cur_nested_join;
2065
if (is_leaf_for_name_resolution())
2067
assert(nested_join);
2069
for (cur_nested_join= nested_join;
2071
cur_nested_join= cur_table_ref->nested_join)
2073
List_iterator_fast<TableList> it(cur_nested_join->join_list);
2074
cur_table_ref= it++;
2076
If the current nested join is a RIGHT JOIN, the operands in
2077
'join_list' are in reverse order, thus the first operand is
2078
already at the front of the list. Otherwise the first operand
2079
is in the end of the list of join operands.
2081
if (!(cur_table_ref->outer_join & JOIN_TYPE_RIGHT))
2084
while ((next= it++))
2085
cur_table_ref= next;
2087
if (cur_table_ref->is_leaf_for_name_resolution())
2090
return cur_table_ref;
2095
Retrieve the last (right-most) leaf in a nested join tree with
2096
respect to name resolution.
2099
TableList::last_leaf_for_name_resolution()
2102
Given that 'this' is a nested table reference, recursively walk
2103
down the right-most children of 'this' until we reach a leaf
2104
table reference with respect to name resolution.
2107
The right-most child of a nested table reference is the first
2108
element in the list of children because the children are inserted
2112
- If 'this' is a nested table reference - the right-most child of
2113
the tree rooted in 'this',
2117
TableList *TableList::last_leaf_for_name_resolution()
2119
TableList *cur_table_ref= this;
2120
nested_join_st *cur_nested_join;
2122
if (is_leaf_for_name_resolution())
2124
assert(nested_join);
2126
for (cur_nested_join= nested_join;
2128
cur_nested_join= cur_table_ref->nested_join)
2130
cur_table_ref= cur_nested_join->join_list.head();
2132
If the current nested is a RIGHT JOIN, the operands in
2133
'join_list' are in reverse order, thus the last operand is in the
2136
if ((cur_table_ref->outer_join & JOIN_TYPE_RIGHT))
2138
List_iterator_fast<TableList> it(cur_nested_join->join_list);
2140
cur_table_ref= it++;
2141
while ((next= it++))
2142
cur_table_ref= next;
2144
if (cur_table_ref->is_leaf_for_name_resolution())
2147
return cur_table_ref;
2151
1927
/*****************************************************************************
2152
1928
Functions to handle column usage bitmaps (read_set, write_set etc...)
2153
1929
*****************************************************************************/
2384
2160
mark_auto_increment_column();
2388
Return subselect that contains the FROM list this table is taken from
2391
TableList::containing_subselect()
2394
Subselect item for the subquery that contains the FROM list
2395
this table is taken from if there is any
2400
Item_subselect *TableList::containing_subselect()
2402
return (select_lex ? select_lex->master_unit()->item : 0);
2406
Compiles the tagged hints list and fills up the bitmasks.
2409
process_index_hints()
2410
table the Table to operate on.
2413
The parser collects the index hints for each table in a "tagged list"
2414
(TableList::index_hints). Using the information in this tagged list
2415
this function sets the members Table::keys_in_use_for_query,
2416
Table::keys_in_use_for_group_by, Table::keys_in_use_for_order_by,
2417
Table::force_index and Table::covering_keys.
2419
Current implementation of the runtime does not allow mixing FORCE INDEX
2420
and USE INDEX, so this is checked here. Then the FORCE INDEX list
2421
(if non-empty) is appended to the USE INDEX list and a flag is set.
2423
Multiple hints of the same kind are processed so that each clause
2424
is applied to what is computed in the previous clause.
2426
USE INDEX (i1) USE INDEX (i2)
2429
and means "consider only i1 and i2".
2432
USE INDEX () USE INDEX (i1)
2435
and means "consider only the index i1"
2437
It is OK to have the same index several times, e.g. "USE INDEX (i1,i1)" is
2440
Different kind of hints (USE/FORCE/IGNORE) are processed in the following
2442
1. All indexes in USE (or FORCE) INDEX are added to the mask.
2445
e.g. "USE INDEX i1, IGNORE INDEX i1, USE INDEX i1" will not use i1 at all
2446
as if we had "USE INDEX i1, USE INDEX i1, IGNORE INDEX i1".
2448
As an optimization if there is a covering index, and we have
2449
IGNORE INDEX FOR GROUP/order_st, and this index is used for the JOIN part,
2450
then we have to ignore the IGNORE INDEX FROM GROUP/order_st.
2453
false no errors found
2454
TRUE found and reported an error.
2456
bool TableList::process_index_hints(Table *tbl)
2458
/* initialize the result variables */
2459
tbl->keys_in_use_for_query= tbl->keys_in_use_for_group_by=
2460
tbl->keys_in_use_for_order_by= tbl->s->keys_in_use;
2462
/* index hint list processing */
2465
key_map index_join[INDEX_HINT_FORCE + 1];
2466
key_map index_order[INDEX_HINT_FORCE + 1];
2467
key_map index_group[INDEX_HINT_FORCE + 1];
2470
bool have_empty_use_join= false, have_empty_use_order= false,
2471
have_empty_use_group= false;
2472
List_iterator <Index_hint> iter(*index_hints);
2474
/* initialize temporary variables used to collect hints of each kind */
2475
for (type= INDEX_HINT_IGNORE; type <= INDEX_HINT_FORCE; type++)
2477
index_join[type].reset();
2478
index_order[type].reset();
2479
index_group[type].reset();
2482
/* iterate over the hints list */
2483
while ((hint= iter++))
2487
/* process empty USE INDEX () */
2488
if (hint->type == INDEX_HINT_USE && !hint->key_name.str)
2490
if (hint->clause & INDEX_HINT_MASK_JOIN)
2492
index_join[hint->type].reset();
2493
have_empty_use_join= true;
2495
if (hint->clause & INDEX_HINT_MASK_ORDER)
2497
index_order[hint->type].reset();
2498
have_empty_use_order= true;
2500
if (hint->clause & INDEX_HINT_MASK_GROUP)
2502
index_group[hint->type].reset();
2503
have_empty_use_group= true;
2509
Check if an index with the given name exists and get his offset in
2510
the keys bitmask for the table
2512
if (tbl->s->keynames.type_names == 0 ||
2513
(pos= find_type(&tbl->s->keynames, hint->key_name.str,
2514
hint->key_name.length, 1)) <= 0)
2516
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name.str, alias);
2522
/* add to the appropriate clause mask */
2523
if (hint->clause & INDEX_HINT_MASK_JOIN)
2524
index_join[hint->type].set(pos);
2525
if (hint->clause & INDEX_HINT_MASK_ORDER)
2526
index_order[hint->type].set(pos);
2527
if (hint->clause & INDEX_HINT_MASK_GROUP)
2528
index_group[hint->type].set(pos);
2531
/* cannot mix USE INDEX and FORCE INDEX */
2532
if ((index_join[INDEX_HINT_FORCE].any() ||
2533
index_order[INDEX_HINT_FORCE].any() ||
2534
index_group[INDEX_HINT_FORCE].any()) &&
2535
(index_join[INDEX_HINT_USE].any() || have_empty_use_join ||
2536
index_order[INDEX_HINT_USE].any() || have_empty_use_order ||
2537
index_group[INDEX_HINT_USE].any() || have_empty_use_group))
2539
my_error(ER_WRONG_USAGE, MYF(0), index_hint_type_name[INDEX_HINT_USE],
2540
index_hint_type_name[INDEX_HINT_FORCE]);
2544
/* process FORCE INDEX as USE INDEX with a flag */
2545
if (index_join[INDEX_HINT_FORCE].any() ||
2546
index_order[INDEX_HINT_FORCE].any() ||
2547
index_group[INDEX_HINT_FORCE].any())
2549
tbl->force_index= true;
2550
index_join[INDEX_HINT_USE]|= index_join[INDEX_HINT_FORCE];
2551
index_order[INDEX_HINT_USE]|= index_order[INDEX_HINT_FORCE];
2552
index_group[INDEX_HINT_USE]|= index_group[INDEX_HINT_FORCE];
2555
/* apply USE INDEX */
2556
if (index_join[INDEX_HINT_USE].any() || have_empty_use_join)
2557
tbl->keys_in_use_for_query&= index_join[INDEX_HINT_USE];
2558
if (index_order[INDEX_HINT_USE].any() || have_empty_use_order)
2559
tbl->keys_in_use_for_order_by&= index_order[INDEX_HINT_USE];
2560
if (index_group[INDEX_HINT_USE].any() || have_empty_use_group)
2561
tbl->keys_in_use_for_group_by&= index_group[INDEX_HINT_USE];
2563
/* apply IGNORE INDEX */
2564
key_map_subtract(tbl->keys_in_use_for_query, index_join[INDEX_HINT_IGNORE]);
2565
key_map_subtract(tbl->keys_in_use_for_order_by, index_order[INDEX_HINT_IGNORE]);
2566
key_map_subtract(tbl->keys_in_use_for_group_by, index_group[INDEX_HINT_IGNORE]);
2569
/* make sure covering_keys don't include indexes disabled with a hint */
2570
tbl->covering_keys&= tbl->keys_in_use_for_query;
2575
2165
size_t Table::max_row_length(const unsigned char *data)