summaryrefslogtreecommitdiff
path: root/sql/key.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-11-24 16:50:21 +0100
committerSergei Golubchik <serg@mariadb.org>2022-01-26 18:43:05 +0100
commita4cac0e07ad7f0909be3f66676e800e20c6b9fa8 (patch)
treea9f27dcb01c5e42ee2ea924d1a66899dbcce4545 /sql/key.cc
parent358921ce32203a9a8dd277a5ba7ac177c9e79e53 (diff)
downloadmariadb-git-a4cac0e07ad7f0909be3f66676e800e20c6b9fa8.tar.gz
MDEV-26938 Support descending indexes internally in InnoDB (server part)
* preserve DESC index property in the parser * store it in the frm (only for HA_KEY_ALG_BTREE) * read it from the frm * show it in SHOW CREATE * skip DESC indexes in opt_range.cc and opt_sum.cc * ORDER BY test This includes a fix of MDEV-27432.
Diffstat (limited to 'sql/key.cc')
-rw-r--r--sql/key.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/sql/key.cc b/sql/key.cc
index f2cebfe6d82..bda028a5ab7 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
- Copyright (c) 2018, 2020, MariaDB
+ Copyright (c) 2018, 2021, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -573,6 +573,9 @@ int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec)
/* loop over every key part */
do
{
+ const int GREATER= key_part->key_part_flag & HA_REVERSE_SORT ? -1 : +1;
+ const int LESS= -GREATER;
+
field= key_part->field;
if (key_part->null_bit)
@@ -593,12 +596,12 @@ int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec)
; /* Fall through, no NULL fields */
else
{
- DBUG_RETURN(+1);
+ DBUG_RETURN(GREATER);
}
}
else if (!sec_is_null)
{
- DBUG_RETURN(-1);
+ DBUG_RETURN(LESS);
}
else
goto next_loop; /* Both were NULL */
@@ -612,7 +615,7 @@ int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec)
*/
if ((result= field->cmp_prefix(field->ptr+first_diff, field->ptr+sec_diff,
key_part->length)))
- DBUG_RETURN(result);
+ DBUG_RETURN(result * GREATER);
next_loop:
key_part++;
key_part_num++;