mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-16934 Query with very large IN clause lists runs slowly
This patch introduces support for the system variable eq_range_index_dive_limit that existed in MySQL starting from 5.6. The variable sets a limit for index dives into equality ranges. Index dives are performed by optimizer to estimate the number of rows in range scans. Index dives usually provide good estimate but they are pretty expensive. To estimate the number of rows in equality ranges statistical data on indexes can be employed. Its usage gives not so good estimates but it's cheap. So if the number of equality dives required by an index scan exceeds the set limit no dives for equality ranges are performed by the optimizer for this index. As the new system variable is introduced in a stable version the default value for it is set to a special value meaning there is no limit for the number of index dives performed by the optimizer. The patch partially uses the MySQL code for WL 5957 'Statistics-based Range optimization for many ranges'.
This commit is contained in:
@ -14617,6 +14617,33 @@ void QUICK_GROUP_MIN_MAX_SELECT::add_keys_and_lengths(String *key_names,
|
||||
}
|
||||
|
||||
|
||||
/* Check whether the number for equality ranges exceeds the set threshold */
|
||||
|
||||
bool eq_ranges_exceeds_limit(RANGE_SEQ_IF *seq, void *seq_init_param)
|
||||
{
|
||||
KEY_MULTI_RANGE range;
|
||||
range_seq_t seq_it;
|
||||
uint count = 0;
|
||||
PARAM *param= ((SEL_ARG_RANGE_SEQ*) seq_init_param)->param;
|
||||
uint limit= param->thd->variables.eq_range_index_dive_limit;
|
||||
|
||||
if (limit == 0)
|
||||
{
|
||||
/* 'Statistics instead of index dives' feature is turned off */
|
||||
return false;
|
||||
}
|
||||
seq_it= seq->init(seq_init_param, 0, 0);
|
||||
while (!seq->next(seq_it, &range))
|
||||
{
|
||||
if ((range.range_flag & EQ_RANGE) && !(range.range_flag & NULL_RANGE))
|
||||
{
|
||||
if (++count >= limit)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef DBUG_OFF
|
||||
|
||||
static void print_sel_tree(PARAM *param, SEL_TREE *tree, key_map *tree_map,
|
||||
|
Reference in New Issue
Block a user