@@ -12345,8 +12362,15 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR KEYUSE *keyuse= tab->keyuse; while (keyuse->key != new_ref_key && keyuse->table == tab->table) keyuse++; + /* + We will now create the ref access method for the new key, + and we know that another key was being used until now, so + we know that key will be in the set tab->key_dependent. Therefore + we don't need to send the whole set of previous tables in the plan + to create_ref_for_key, as we would normally have to. + */ if (create_ref_for_key(tab->join, tab, keyuse, - tab->join->const_table_map)) + tab->join->key_dependent)) DBUG_RETURN(0); } else