diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2016-06-03 14:43:08 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2016-06-03 14:43:08 +0300 |
commit | 1859caf60b725f81f2ac6091eb44cb848a4a439a (patch) | |
tree | da6109fbb820f6bbab8b10a1e53cd144800ebb08 | |
parent | 825427fa9f4fa5c56301f392d10d254f9eca8a54 (diff) | |
download | mariadb-git-1859caf60b725f81f2ac6091eb44cb848a4a439a.tar.gz |
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.
-rw-r--r-- | sql/opt_range_mrr.cc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/sql/opt_range_mrr.cc b/sql/opt_range_mrr.cc index bff96c7d4cb..729c491a6f1 100644 --- a/sql/opt_range_mrr.cc +++ b/sql/opt_range_mrr.cc @@ -266,12 +266,28 @@ walk_up_n_right: range->end_key.flag= (cur->max_key_flag & NEAR_MAX ? HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY); range->end_key.keypart_map= make_prev_keypart_map(cur->max_key_parts); - + + KEY *key_info; + if (seq->real_keyno== MAX_KEY) + key_info= NULL; + else + key_info= &seq->param->table->key_info[seq->real_keyno]; + + /* + Conditions below: + (1) - range analysis is used for estimating condition selectivity + (2) - This is a unique key, and we have conditions for all its + user-defined key parts. + (3) - The table uses extended keys, and we have conditions for + all key parts. + */ if (!(cur->min_key_flag & ~NULL_RANGE) && !cur->max_key_flag && - (seq->real_keyno == MAX_KEY || - ((uint)key_tree->part+1 == - seq->param->table->key_info[seq->real_keyno].user_defined_key_parts && - (seq->param->table->key_info[seq->real_keyno].flags & HA_NOSAME))) && + (!key_info || // (1) + ((uint)key_tree->part+1 == key_info->user_defined_key_parts && // (2) + key_info->flags & HA_NOSAME) || // (2) + (seq->param->table->s->use_ext_keys && // (3) + (uint)key_tree->part+1 == key_info->ext_key_parts) // (3) + ) && range->start_key.length == range->end_key.length && !memcmp(seq->param->min_key,seq->param->max_key,range->start_key.length)) range->range_flag= UNIQUE_RANGE | (cur->min_key_flag & NULL_RANGE); |