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; } }