diff --git a/sql/sql_select.cc b/sql/sql_select.cc index dfcbc5418cd..a35f5cc2314 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -555,10 +555,18 @@ mysql_select(THD *thd,TABLE_LIST *tables,List &fields,COND *conds, /* Change DISTINCT to GROUP BY */ select_distinct= 0; no_order= !order; - if (order && skip_sort_order) - join.tmp_table_param.quick_group=0; if (all_order_fields_used) + { + if (order && skip_sort_order) + { + /* + Force MySQL to read the table in sorted order to get result in + ORDER BY order. + */ + join.tmp_table_param.quick_group=0; + } order=0; + } join.group=1; // For end_write_group } else