From 18dbeae1b86f1b6c0c29acd02e7e0dfbca91181c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 15 Jan 2025 07:31:33 +0200 Subject: [PATCH] MDEV-35849: index records in a wrong order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit page_cur_dtuple_cmp(): Take DESC index fields into account also when comparing a NULL value in a ROW_FORMAT≠REDUNDANT record. Thanks to Elena Stepanova for finding this bug. --- mysql-test/suite/innodb/r/innodb-index.result | 10 ++++++++++ mysql-test/suite/innodb/t/innodb-index.test | 11 +++++++++++ storage/innobase/page/page0cur.cc | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/innodb-index.result b/mysql-test/suite/innodb/r/innodb-index.result index 98f711b314a..27733c5165d 100644 --- a/mysql-test/suite/innodb/r/innodb-index.result +++ b/mysql-test/suite/innodb/r/innodb-index.result @@ -1996,4 +1996,14 @@ a c DROP TABLE t1; # End of 10.8 tests +# +# MDEV-35849: index records in a wrong order +# +CREATE TABLE t (pk INT PRIMARY KEY, a VARCHAR(1), KEY (a DESC)) ENGINE=InnoDB; +INSERT INTO t VALUES (1,NULL),(2,'x'); +CHECK TABLE t; +Table Op Msg_type Msg_text +test.t check status OK +DROP TABLE t; +# End of 11.8 tests ALTER DATABASE test CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci; diff --git a/mysql-test/suite/innodb/t/innodb-index.test b/mysql-test/suite/innodb/t/innodb-index.test index eb5a2c33738..c70352a49f3 100644 --- a/mysql-test/suite/innodb/t/innodb-index.test +++ b/mysql-test/suite/innodb/t/innodb-index.test @@ -1229,6 +1229,17 @@ DROP TABLE t1; --echo # End of 10.8 tests +--echo # +--echo # MDEV-35849: index records in a wrong order +--echo # + +CREATE TABLE t (pk INT PRIMARY KEY, a VARCHAR(1), KEY (a DESC)) ENGINE=InnoDB; +INSERT INTO t VALUES (1,NULL),(2,'x'); +CHECK TABLE t; +DROP TABLE t; + +--echo # End of 11.8 tests + --disable_query_log call mtr.add_suppression("InnoDB: Tablespace .* was not found at .*t[12].ibd."); diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc index 00e29caeeb7..d1d11b50de8 100644 --- a/storage/innobase/page/page0cur.cc +++ b/storage/innobase/page/page0cur.cc @@ -606,7 +606,7 @@ static int page_cur_dtuple_cmp(const dtuple_t &dtuple, const rec_t *rec, { if (i < cur_field || dtuple.fields[i].len == UNIV_SQL_NULL) continue; - ret= 1; + ret= field->descending ? -1 : 1; break; } }