1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-18413: Find constraint correlated indexes

Find indexes of one table which parts participate in one constraint.
These indexes are called constraint correlated.

New methods: TABLE::find_constraint_correlated_indexes() and
virtual method check_index_dependence() were added.
For each index it's own constraint correlated index map was created
where all indexes that are constraint correlated with the current are
marked.

The results of this task are used for MDEV-16188 (Use in-memory
PK filters built from range index scans).
This commit is contained in:
Galina Shalygina
2019-02-10 22:36:46 +03:00
parent 15fe81c571
commit 3955d2a153
8 changed files with 1726 additions and 6 deletions

View File

@@ -1194,6 +1194,8 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table,
goto end;
}
table->find_constraint_correlated_indexes();
res=0;
end:
thd->restore_active_arena(table->expr_arena, &backup_arena);
@@ -1274,6 +1276,80 @@ void TABLE_SHARE::set_overlapped_keys()
}
bool Item_field::check_index_dependence(void *arg)
{
TABLE *table= (TABLE *)arg;
KEY *key= table->key_info;
for (uint j= 0; j < table->s->keys; j++, key++)
{
if (table->constraint_dependent_keys.is_set(j))
continue;
KEY_PART_INFO *key_part= key->key_part;
uint n= key->user_defined_key_parts;
for (uint k= 0; k < n; k++, key_part++)
{
if (this->field == key_part->field)
{
table->constraint_dependent_keys.set_bit(j);
break;
}
}
}
return false;
}
/**
@brief
Find keys that occur in the same constraint on this table
@details
Constraints on this table are checked only.
The method goes through constraints list trying to find at
least two keys which parts participate in some constraint.
These keys are called constraint correlated.
Each key has its own key map with the information about with
which keys it is constraint correlated. Bit in this map is set
only if keys are constraint correlated.
This method fills each keys constraint correlated key map.
*/
void TABLE::find_constraint_correlated_indexes()
{
if (s->keys == 0)
return;
KEY *key= key_info;
for (uint i= 0; i < s->keys; i++, key++)
{
key->constraint_correlated.clear_all();
key->constraint_correlated.set_bit(i);
}
if (!check_constraints)
return;
for (Virtual_column_info **chk= check_constraints ; *chk ; chk++)
{
constraint_dependent_keys.clear_all();
(*chk)->expr->walk(&Item::check_index_dependence, 0, this);
if (constraint_dependent_keys.bits_set() <= 1)
continue;
uint key_no= 0;
key_map::Iterator ki(constraint_dependent_keys);
while ((key_no= ki++) != key_map::Iterator::BITMAP_END)
key_info[key_no].constraint_correlated.merge(constraint_dependent_keys);
}
}
/**
Read data from a binary .frm file image into a TABLE_SHARE