diff -ur orig-mysql-8.0.35/sql/sql_optimizer.cc mysql-8.0.35/sql/sql_optimizer.cc --- orig-mysql-8.0.35/sql/sql_optimizer.cc 2023-10-12 07:45:01 +++ mysql-8.0.35/sql/sql_optimizer.cc 2024-01-23 13:43:31 @@ -2440,9 +2440,10 @@ (is_group_by ? table->force_index_group : table->force_index_order); // Find an ordering index alternative over the chosen plan iff - // prefer_ordering_index switch is on. This switch is overridden only when - // force index for order/group is specified. + // prefer_ordering_index switch is on, or query will table scan (JT_ALL) + // because there's no key to look up or scan, or force index is specified. if (thd->optimizer_switch_flag(OPTIMIZER_SWITCH_PREFER_ORDERING_INDEX) || + tab->type() == JT_ALL || is_force_index) test_if_cheaper_ordering(tab, &order, table, usable_keys, ref_key_hint, select_limit, &best_key, &best_key_direction,