diff options
author | Igor Babaev <igor@askmonty.org> | 2012-11-01 14:54:33 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2012-11-01 14:54:33 -0700 |
commit | 7714739b2d6a50c4ca69421c0e19a9e08ff3b5c7 (patch) | |
tree | ad8a87f9312075ed3f90255f9d7916055cd56d28 /sql | |
parent | 9b6fe965033aab5eb20a4f2eefa482534b15c424 (diff) | |
download | mariadb-git-7714739b2d6a50c4ca69421c0e19a9e08ff3b5c7.tar.gz |
Fixed bug mdev-585 (LP bug #637962)
If, when executing a query with ORDER BY col LIMIT n, the optimizer chose
an index-merge scan to access the table containing col while there existed
an index defined over col then optimizer did not consider the possibility
of using an alternative range scan by this index to avoid filesort. This
could cause a performance degradation if the optimizer flag index_merge was
set up to 'on'.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_select.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 438cec61c6d..122c19ee73d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -18079,15 +18079,18 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit_arg, */ if (quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE || - quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_INTERSECT || + quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_INTERSECT || quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION || quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT) - goto use_filesort; - ref_key= select->quick->index; - ref_key_parts= select->quick->used_key_parts; + ref_key= MAX_KEY; + else + { + ref_key= select->quick->index; + ref_key_parts= select->quick->used_key_parts; + } } - if (ref_key >= 0) + if (ref_key >= 0 && ref_key != MAX_KEY) { /* We come here when there is a REF key. @@ -18229,7 +18232,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit_arg, else keys= usable_keys; - if (ref_key >= 0 && table->covering_keys.is_set(ref_key)) + if (ref_key >= 0 && ref_key != MAX_KEY && + table->covering_keys.is_set(ref_key)) ref_key_quick_rows= table->quick_rows[ref_key]; read_time= join->best_positions[tablenr].read_time; |