Skip to content

Commit 1859caf

Browse files
committed
MDEV-10175: range optimizer calls records_in_range() for full extended keys
Make the range optimizer not call records_in_range() when it would not give any benefit.
1 parent 825427f commit 1859caf

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

sql/opt_range_mrr.cc

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,28 @@ bool sel_arg_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range)
266266
range->end_key.flag= (cur->max_key_flag & NEAR_MAX ? HA_READ_BEFORE_KEY :
267267
HA_READ_AFTER_KEY);
268268
range->end_key.keypart_map= make_prev_keypart_map(cur->max_key_parts);
269-
269+
270+
KEY *key_info;
271+
if (seq->real_keyno== MAX_KEY)
272+
key_info= NULL;
273+
else
274+
key_info= &seq->param->table->key_info[seq->real_keyno];
275+
276+
/*
277+
Conditions below:
278+
(1) - range analysis is used for estimating condition selectivity
279+
(2) - This is a unique key, and we have conditions for all its
280+
user-defined key parts.
281+
(3) - The table uses extended keys, and we have conditions for
282+
all key parts.
283+
*/
270284
if (!(cur->min_key_flag & ~NULL_RANGE) && !cur->max_key_flag &&
271-
(seq->real_keyno == MAX_KEY ||
272-
((uint)key_tree->part+1 ==
273-
seq->param->table->key_info[seq->real_keyno].user_defined_key_parts &&
274-
(seq->param->table->key_info[seq->real_keyno].flags & HA_NOSAME))) &&
285+
(!key_info || // (1)
286+
((uint)key_tree->part+1 == key_info->user_defined_key_parts && // (2)
287+
key_info->flags & HA_NOSAME) || // (2)
288+
(seq->param->table->s->use_ext_keys && // (3)
289+
(uint)key_tree->part+1 == key_info->ext_key_parts) // (3)
290+
) &&
275291
range->start_key.length == range->end_key.length &&
276292
!memcmp(seq->param->min_key,seq->param->max_key,range->start_key.length))
277293
range->range_flag= UNIQUE_RANGE | (cur->min_key_flag & NULL_RANGE);

0 commit comments

Comments
 (0)