HA_CLUSTERED_INDEX This patch introduces a index flag, that will it possible to have optimizer consider other indexes than primary key as clustered see also: http://bugs.mysql.com/45458 --- sql/handler.h | 8 +++++++- sql/sql_select.cc | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) Index: 70-spj/sql/handler.h =================================================================== --- 70-spj.orig/sql/handler.h 2010-03-03 11:46:05.000000000 +0100 +++ 70-spj/sql/handler.h 2010-03-03 11:46:37.000000000 +0100 @@ -232,7 +232,13 @@ typedef Bitmap HA_AL Index scan will not return records in rowid order. Not guaranteed to be set for unordered (e.g. HASH) indexes. */ -#define HA_KEY_SCAN_NOT_ROR 128 +#define HA_KEY_SCAN_NOT_ROR 128 + +/* + no IO if read data when scan index + i.e index is covering +*/ +#define HA_CLUSTERED_INDEX 256 /* operations for disable/enable indexes */ #define HA_KEY_SWITCH_NONUNIQ 0 Index: 70-spj/sql/sql_select.cc =================================================================== --- 70-spj.orig/sql/sql_select.cc 2010-03-03 11:46:05.000000000 +0100 +++ 70-spj/sql/sql_select.cc 2010-03-03 11:46:13.000000000 +0100 @@ -13478,7 +13478,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR bool is_covering= table->covering_keys.is_set(nr) || (nr == table->s->primary_key && - table->file->primary_key_is_clustered()); + table->file->primary_key_is_clustered()) || + test(table->file->index_flags(nr, 0, 0) & HA_CLUSTERED_INDEX); /* Don't use an index scan with ORDER BY without limit.