=== modified file 'sql/handler.h'
--- sql/handler.h	2014-03-26 10:32:59 +0000
+++ sql/handler.h	2014-03-26 10:32:59 +0000
@@ -261,6 +261,7 @@
 */
 #define HA_KEY_SCAN_NOT_ROR     128 
 #define HA_DO_INDEX_COND_PUSHDOWN  256 /* Supports Index Condition Pushdown */
+#define HA_CLUSTERED_INDEX      512     /* Data is clustered on this key */
 
 
 

=== modified file 'sql/sql_planner.cc'
--- sql/sql_planner.cc	2013-12-05 17:23:10 +0000
+++ sql/sql_planner.cc	2014-03-26 10:32:59 +0000
@@ -648,7 +648,8 @@
             /* Limit the number of matched rows */
             tmp= records;
             set_if_smaller(tmp, (double) thd->variables.max_seeks_for_key);
-            if (table->covering_keys.is_set(key))
+            if (table->covering_keys.is_set(key)
+                || (table->file->index_flags(key, 0, 0) & HA_CLUSTERED_INDEX))
             {
               /* we can use only index tree */
               tmp= record_count * table->file->index_only_read_time(key, tmp);
@@ -823,7 +824,8 @@
 
             /* Limit the number of matched rows */
             set_if_smaller(tmp, (double) thd->variables.max_seeks_for_key);
-            if (table->covering_keys.is_set(key))
+            if (table->covering_keys.is_set(key)
+                || (table->file->index_flags(key, 0, 0) & HA_CLUSTERED_INDEX))
             {
               /* we can use only index tree */
               tmp= record_count * table->file->index_only_read_time(key, tmp);

=== modified file 'sql/sql_select.cc'
--- sql/sql_select.cc	2014-02-17 11:12:40 +0000
+++ sql/sql_select.cc	2014-03-26 10:32:59 +0000
@@ -2910,7 +2910,28 @@
 	    tab->read_first_record= join_read_first;
             tab->type=JT_INDEX_SCAN;      // Read with index_first / index_next
 	  }
-	}
+          else if (!(tab->select && tab->select->quick))
+          {
+            DBUG_ASSERT(table->covering_keys.is_clear_all());
+            if (!tab->do_loosescan())
+            {
+              key_map clustering_keys;
+              for (uint i= 0; i < table->s->keys; i++)
+              {
+                if (tab->keys.is_set(i)
+                    && table->file->index_flags(i, 0, 0) & HA_CLUSTERED_INDEX)
+                  clustering_keys.set_bit(i);
+              }
+              uint index= find_shortest_key(table, &clustering_keys);
+              if (index != MAX_KEY)
+              {
+                tab->index= index;
+                tab->read_first_record= join_read_first;
+                tab->type= JT_INDEX_SCAN;
+              }
+            }
+          }
+        }
         if (tab->select && tab->select->quick &&
             tab->select->quick->index != MAX_KEY && ! tab->table->key_read)
           push_index_cond(tab, tab->select->quick->index, icp_other_tables_ok,
@@ -3644,13 +3665,14 @@
   {
     /*
      If the primary key is clustered and found shorter key covers all table
-     fields then primary key scan normally would be faster because amount of
-     data to scan is the same but PK is clustered.
+     fields and is not clustering then primary key scan normally would be
+     faster because amount of data to scan is the same but PK is clustered.
      It's safe to compare key parts with table fields since duplicate key
      parts aren't allowed.
      */
     if (best == MAX_KEY ||
-        table->key_info[best].user_defined_key_parts >= table->s->fields)
+        ((table->key_info[best].user_defined_key_parts >= table->s->fields)
+         && !(table->file->index_flags(best, 0, 0) & HA_CLUSTERED_INDEX)))
       best= usable_clustered_pk;
   }
   return best;
@@ -4101,7 +4123,9 @@
         (tab->type == JT_ALL &&
          tab->join->primary_tables > tab->join->const_tables + 1) &&
          ((unsigned) best_key != table->s->primary_key ||
-          !table->file->primary_key_is_clustered()))
+          !table->file->primary_key_is_clustered()) &&
+        !(best_key >= 0
+          && (table->file->index_flags(best_key, 0, 0) & HA_CLUSTERED_INDEX)))
     {
       can_skip_sorting= false;
       goto fix_ICP;
@@ -5529,7 +5553,9 @@
 
       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()) ||
+                        (table->file->index_flags(nr, 0, 0)
+                         & HA_CLUSTERED_INDEX);
       
       /* 
         Don't use an index scan with ORDER BY without limit.

