diff options
author | igor@olga.mysql.com <> | 2008-04-22 21:49:39 -0700 |
---|---|---|
committer | igor@olga.mysql.com <> | 2008-04-22 21:49:39 -0700 |
commit | b210e5df6de43338607fd28d9b1c71298033723d (patch) | |
tree | 72c60957d1dc2d847b35a3bf5b3098b255c5ea2b /sql/sql_select.cc | |
parent | 013fd236755ec402a988eaa70392e0a08c169ac0 (diff) | |
download | mariadb-git-b210e5df6de43338607fd28d9b1c71298033723d.tar.gz |
Fixed bug#35844.
The function test_if_skip_sort_order ignored any covering index used for ref
access of a table in a query with ORDER BY if this index was incompatible
with the ORDER BY list and there was another covering index compatible with
this list.
As a result sub-optimal execution plans were chosen for some queries with
ORDER BY clause.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 164edacc932..c01aaa18751 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12966,6 +12966,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, uint tablenr= tab - join->join_tab; ha_rows table_records= table->file->stats.records; bool group= join->group && order == join->group_list; + ha_rows ref_key_quick_rows= HA_POS_ERROR; LINT_INIT(best_key_parts); LINT_INIT(best_key_direction); LINT_INIT(best_records); @@ -12999,6 +13000,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, else keys= usable_keys; + if (ref_key >= 0 && table->covering_keys.is_set(ref_key)) + ref_key_quick_rows= table->quick_rows[ref_key]; + read_time= join->best_positions[tablenr].read_time; for (uint i= tablenr+1; i < join->tables; i++) fanout*= join->best_positions[i].records_read; // fanout is always >= 1 @@ -13093,7 +13097,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, index_scan_time < read_time) { ha_rows quick_records= table_records; - if (is_best_covering && !is_covering) + if (is_best_covering && !is_covering || + is_covering && ref_key_quick_rows < select_limit) continue; if (table->quick_keys.is_set(nr)) quick_records= table->quick_rows[nr]; |