From 9b6d2ad7458e23b70a608aa7da852024c85a3adc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 6 Jan 2022 18:12:37 +0100 Subject: [PATCH] ORDER BY index traversal direction in the optimizer trace --- mysql-test/main/opt_trace.result | 2 ++ sql/sql_select.cc | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 0d16f47dc8f..226ab266789 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -2176,6 +2176,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { { "index": "a_a", "can_resolve_order": true, + "direction": 1, "updated_limit": 47, "index_scan_time": 47, "usable": false, @@ -2184,6 +2185,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { { "index": "a_c", "can_resolve_order": true, + "direction": 1, "updated_limit": 47, "range_scan_time": 4.331020747, "index_scan_time": 4.331020747, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 56cb4ce8042..bbe25a2de4e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -232,9 +232,7 @@ static bool test_if_cheaper_ordering(const JOIN_TAB *tab, ha_rows *new_select_limit, uint *new_used_key_parts= NULL, uint *saved_best_key_parts= NULL); -static int test_if_order_by_key(JOIN *join, - ORDER *order, TABLE *table, uint idx, - uint *used_key_parts); +static int test_if_order_by_key(JOIN *, ORDER *, TABLE *, uint, uint *); static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order, ha_rows select_limit, bool no_changes, const key_map *map); @@ -28967,6 +28965,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table, DBUG_ASSERT (ref_key != (int) nr); possible_key.add("can_resolve_order", true); + possible_key.add("direction", direction); bool is_covering= (table->covering_keys.is_set(nr) || (table->file->index_flags(nr, 0, 1) & HA_CLUSTERED_INDEX));