MySQL 9.1.0
Source Code Documentation
|
A Key_use represents an equality predicate of the form (table.column = val), where the column is indexed by keypart
in key
and val
is either a constant, a column from other table, or an expression over column(s) from other table(s).
More...
#include <sql_select.h>
Public Member Functions | |
Key_use () | |
Key_use (Table_ref *table_ref_arg, Item *val_arg, table_map used_tables_arg, uint key_arg, uint keypart_arg, uint optimize_arg, key_part_map keypart_map_arg, ha_rows ref_table_rows_arg, bool null_rejecting_arg, bool *cond_guard_arg, uint sj_pred_no_arg) | |
Public Attributes | |
Table_ref * | table_ref |
table owning the index More... | |
Item * | val |
Value used for lookup into key . More... | |
table_map | used_tables |
All tables used in val , that is all tables that provide bindings for the expression val . More... | |
uint | key |
number of index More... | |
uint | keypart |
used part of the index More... | |
uint | optimize |
0, or KEY_OPTIMIZE_* More... | |
key_part_map | keypart_map |
like keypart, but as a bitmap More... | |
ha_rows | ref_table_rows |
Estimate of how many rows for a key value. More... | |
bool | null_rejecting |
If true, the comparison this value was created from will not be satisfied if val has NULL 'value' (unless KEY_OPTIMIZE_REF_OR_NULL is set). More... | |
bool * | cond_guard |
!NULL - This Key_use was created from an equality that was wrapped into an Item_func_trig_cond. More... | |
uint | sj_pred_no |
0..63 <=> This was created from semi-join IN-equality # sj_pred_no. More... | |
key_part_map | bound_keyparts |
The key columns which are equal to expressions depending only of earlier tables of the current join prefix. More... | |
double | fanout |
Fanout of the ref access path for this index, in the current join prefix. More... | |
double | read_cost |
Cost of the ref access path for the current join prefix, i.e. More... | |
A Key_use represents an equality predicate of the form (table.column = val), where the column is indexed by keypart
in key
and val
is either a constant, a column from other table, or an expression over column(s) from other table(s).
If val
is not a constant, then the Key_use specifies an equi-join predicate, and table
must be put in the join plan after all tables in used_tables
.
At an abstract level a Key_use instance can be viewed as a directed arc of an equi-join graph, where the arc originates from the table(s) containing the column(s) that produce the values used for index lookup into table
, and the arc points into table
.
For instance, assuming there is only an index t3(c), the query
would generate two arcs (instances of Key_use)
If there were indexes t1(a), and t2(b), then the equi-join graph would have two additional arcs "c->a" and "c->b" recording the fact that it is possible to perform lookup in either direction.
The query
can be viewed as a graph with one "multi-source" arc:
The graph of all equi-join conditions usable for index lookup is stored as an ordered sequence of Key_use elements in JOIN::keyuse_array. See sort_keyuse() for details on the ordering. Each JOIN_TAB::keyuse points to the first array element with the same table.
|
inline |
|
inline |
key_part_map Key_use::bound_keyparts |
The key columns which are equal to expressions depending only of earlier tables of the current join prefix.
This information is stored only in the first Key_use of the index.
bool* Key_use::cond_guard |
!NULL - This Key_use was created from an equality that was wrapped into an Item_func_trig_cond.
This means the equality (and validity of this Key_use element) can be turned on and off. The on/off state is indicted by the pointed value: cond_guard == true <=> equality condition is on cond_guard == false <=> equality condition is off
NULL - Otherwise (the source equality can't be turned off)
Not used if the index is fulltext (such index cannot be used for equalities).
double Key_use::fanout |
Fanout of the ref access path for this index, in the current join prefix.
This information is stored only in the first Key_use of the index.
uint Key_use::key |
number of index
uint Key_use::keypart |
used part of the index
key_part_map Key_use::keypart_map |
like keypart, but as a bitmap
bool Key_use::null_rejecting |
If true, the comparison this value was created from will not be satisfied if val has NULL 'value' (unless KEY_OPTIMIZE_REF_OR_NULL is set).
Not used if the index is fulltext (such index cannot be used for equalities).
uint Key_use::optimize |
0, or KEY_OPTIMIZE_*
double Key_use::read_cost |
Cost of the ref access path for the current join prefix, i.e.
the cost of using ref access once multiplied by estimated number of partial rows from tables earlier in the join sequence. read_cost does NOT include cost of processing rows on the server side (row_evaluate_cost).
Example: If the cost of ref access on this index is 5, and the estimated number of partial rows from earlier tables is 10, read_cost=50.
This information is stored only in the first Key_use of the index.
ha_rows Key_use::ref_table_rows |
Estimate of how many rows for a key value.
uint Key_use::sj_pred_no |
0..63 <=> This was created from semi-join IN-equality # sj_pred_no.
UINT_MAX Otherwise
Not used if the index is fulltext (such index cannot be used for semijoin).
Table_ref* Key_use::table_ref |
table owning the index
table_map Key_use::used_tables |
All tables used in val
, that is all tables that provide bindings for the expression val
.
These tables must be in the plan before executing the equi-join described by a Key_use. For all expressions except for the MATCH function, this is the same as val->used_tables(). For the MATCH function, val is the actual MATCH function, and used_tables is the set of tables used in the AGAINST argument.
Item* Key_use::val |
Value used for lookup into key
.
It may be an Item_field, a constant or any other expression. If val
contains a field from another table, then we have a join condition, and the table(s) of the field(s) in val
should be before table
in the join plan.