diff options
author | Evgeny Potemkin <epotemkin@mysql.com> | 2010-02-26 14:17:00 +0300 |
---|---|---|
committer | Evgeny Potemkin <epotemkin@mysql.com> | 2010-02-26 14:17:00 +0300 |
commit | 2d4db52edac1488c9481b303095229b424288e64 (patch) | |
tree | 8e8c815051a10af4460b26ee78b72d4e315c0642 /sql/sql_select.cc | |
parent | 6f78ef71d485fb3968355941860d012fc17a9c59 (diff) | |
download | mariadb-git-2d4db52edac1488c9481b303095229b424288e64.tar.gz |
Bug#50843: Filesort used instead of clustered index led to
performance degradation.
Filesort + join cache combination is preferred to full index scan because it
is usually faster. But it's not the case when the index is clustered one.
Now test_if_skip_sort_order function prefers filesort only if index isn't
clustered.
mysql-test/r/innodb_mysql.result:
Added a test case for the bug#50843.
mysql-test/t/innodb_mysql.test:
Added a test case for the bug#50843.
sql/sql_select.cc:
Bug#50843: Filesort used instead of clustered index led to
performance degradation.
Now test_if_skip_sort_order function prefers filesort only if index isn't
clustered.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 52f9aae7a0c..c4fac5b50ef 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13304,12 +13304,6 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, */ if (select_limit >= table_records) { - /* - filesort() and join cache are usually faster than reading in - index order and not using join cache - */ - if (tab->type == JT_ALL && tab->join->tables > tab->join->const_tables + 1) - DBUG_RETURN(0); keys= *table->file->keys_to_use_for_scanning(); keys.merge(table->covering_keys); @@ -13459,6 +13453,19 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, } } } + + /* + filesort() and join cache are usually faster than reading in + index order and not using join cache, except in case that chosen + index is clustered primary key. + */ + if ((select_limit >= table_records) && + (tab->type == JT_ALL && + tab->join->tables > tab->join->const_tables + 1) && + ((unsigned) best_key != table->s->primary_key || + !table->file->primary_key_is_clustered())) + DBUG_RETURN(0); + if (best_key >= 0) { bool quick_created= FALSE; |