MySQL 9.0.0
Source Code Documentation
Key_use Class Reference

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_reftable_ref
 table owning the index More...
 
Itemval
 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...
 

Detailed Description

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

SELECT * FROM t1, t2, t3
WHERE t1.a = t3.c AND
t2.b = t3.c;
const std::string SELECT("SELECT")
Name of the static privileges.
@ WHERE
Definition: sql_yacc.h:687
@ FROM
Definition: sql_yacc.h:250

would generate two arcs (instances of Key_use)

t1-- a ->- c --.
|
V
t3
^
|
t2-- b ->- c --'

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.

t1-- a ->- c --. ,-- c -<- b --- t2
^ | | ^
| | | |
`-- a -<- c - v v-- c ->- b ----'
t3

The query

SELECT * FROM t1, t2, t3 WHERE t1.a + t2.b = t3.c;

can be viewed as a graph with one "multi-source" arc:

t1-- a ---
|
>-- c --> t3
|
t2-- b ---

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.

Constructor & Destructor Documentation

◆ Key_use() [1/2]

Key_use::Key_use ( )
inline

◆ Key_use() [2/2]

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 
)
inline

Member Data Documentation

◆ bound_keyparts

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.

◆ cond_guard

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).

◆ fanout

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.

◆ key

uint Key_use::key

number of index

◆ keypart

uint Key_use::keypart

used part of the index

◆ keypart_map

key_part_map Key_use::keypart_map

like keypart, but as a bitmap

◆ null_rejecting

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).

◆ optimize

uint Key_use::optimize

0, or KEY_OPTIMIZE_*

◆ read_cost

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.

◆ ref_table_rows

ha_rows Key_use::ref_table_rows

Estimate of how many rows for a key value.

◆ sj_pred_no

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).

See also
get_semi_join_select_list_index()

◆ table_ref

Table_ref* Key_use::table_ref

table owning the index

◆ used_tables

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.

◆ val

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.


The documentation for this class was generated from the following file: