Skip to content

Commit

Permalink
MDEV-26996 Reverse-ordered indexes: improve print-out
Browse files Browse the repository at this point in the history
When printing a range into optimizer trace, print DESC for columns
that are reverse-ordered, for example:

   "(4) <= (key1 DESC) <= (2)"
  • Loading branch information
spetrunia authored and vuvova committed Jan 26, 2022
1 parent d6c6f79 commit 96bdda6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mysql-test/main/desc_index_range.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -138,7 +138,7 @@ json_detailed(json_extract(trace, '$**.range_access_plan.ranges'))
[

[
"(4) <= (a) <= (2)"
"(4) <= (a DESC) <= (2)"
]
]
explain
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16637,6 +16637,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;
Expand Down

0 comments on commit 96bdda6

Please sign in to comment.