revision-id: 3027d0d7262159cca2de62d5d415825a7b4e485e (mariadb-10.6.1-260-g3027d0d7262) parent(s): 3a2eadbcf938f3dd1548e57a381d773b0e24c97a author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2021-12-22 17:19:48 +0300 message: MDEV-26996: Reverse-ordered indexes: improve print-out When printing a range into optimizer trace, print DESC for columns that are reverse-ordered, for example: "(4) <= (key1 DESC) <= (2)" --- mysql-test/main/desc_index_range.result | 14 +++++++------- sql/opt_range.cc | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/desc_index_range.result b/mysql-test/main/desc_index_range.result index feec5dc1720..244659e3f48 100644 --- a/mysql-test/main/desc_index_range.result +++ b/mysql-test/main/desc_index_range.result @@ -13,9 +13,9 @@ json_detailed(json_extract(trace, '$**.range_access_plan.ranges')) [ [ - "(6) <= (a) <= (6)", - "(4) <= (a) <= (4)", - "(2) <= (a) <= (2)" + "(6) <= (a DESC) <= (6)", + "(4) <= (a DESC) <= (4)", + "(2) <= (a DESC) <= (2)" ] ] set optimizer_trace=default; @@ -57,7 +57,7 @@ json_detailed(json_extract(trace, '$**.range_access_plan.ranges')) [ [ - "(8,50) <= (a,b)" + "(8,50) <= (a,b DESC)" ] ] select * from t1 force index(ab) where a>=8 and b<=50; @@ -104,7 +104,7 @@ json_detailed(json_extract(trace, '$**.range_access_plan.ranges')) [ [ - "(2,80) <= (a,b) <= (4,50)" + "(2,80) <= (a,b DESC) <= (4,50)" ] ] select * from t1 where a between 2 and 4 and b between 50 and 80; @@ -138,7 +138,7 @@ json_detailed(json_extract(trace, '$**.range_access_plan.ranges')) [ [ - "(4) <= (a) <= (2)" + "(4) <= (a DESC) <= (2)" ] ] explain @@ -151,7 +151,7 @@ json_detailed(json_extract(trace, '$**.range_access_plan.ranges')) [ [ - "(4,80) <= (a,b) <= (2,50)" + "(4,80) <= (a DESC,b DESC) <= (2,50)" ] ] drop table t2; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index bbb7b3d87fa..7b70dca86a6 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -16634,6 +16634,8 @@ void print_keyparts_name(String *out, const KEY_PART_INFO *key_part, else out->append(STRING_WITH_LEN(",")); out->append(key_part->field->field_name); + if (key_part->key_part_flag & HA_REVERSE_SORT) + out->append(STRING_WITH_LEN(" DESC")); } else break;