[MDEV-13756] Implement descending index: KEY (a DESC, b ASC) Created: 2017-09-07 Updated: 2024-01-25 Resolved: 2022-01-26 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer, Storage Engine - InnoDB |
| Fix Version/s: | 10.8.1 |
| Type: | Task | Priority: | Blocker |
| Reporter: | Marko Mäkelä | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 24 |
| Labels: | Compatibility, Oracle, Preview_10.8, SQL, optimizer-feature | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
MySQL 8.0 introduced support for descending indexes in WL#1074. This involved some changes in InnoDB and many in the optimizer. MariaDB and older versions of MySQL silently ignore the ASC/DESC attribute in KEY definitions. All index fields (KEY_PART) are sorted in ascending order. The Oracle database defines the NULLS FIRST and NULLS LAST attributes for the ORDER BY clause, but not for CREATE INDEX. The defaults are the exact opposite of InnoDB behaviour:
InnoDB in MariaDB and before MySQL 8.0 supports only ascending order, and it sorts NULLS FIRST, not NULLS LAST like the above quote suggests Oracle to do. |
| Comments |
| Comment by Tom Conlon [ 2020-09-22 ] | ||||||||||
|
Two years since MySQL supported this and no progress on this fundamental feature unfortunately. Am aware that we can use a kludge for this: Eventually Firebird (always kept close to ANSI standards, don't know if this syntax is or not) but they implemented: Be great to have something similarly implemented but if not then - in 2020 - just: Genuine thanks for all the work | ||||||||||
| Comment by ssauravy [ 2021-08-11 ] | ||||||||||
|
It was missing in MariaDB 10.6, and it is also excluded in the 10.7 plan. | ||||||||||
| Comment by Sergei Petrunia [ 2021-12-07 ] | ||||||||||
|
For those who were wondering whether MyRocks upstream supports these indexes: it doesn't:
This is latest fb-mysql-8.0,
| ||||||||||
| Comment by Elena Stepanova [ 2022-01-24 ] | ||||||||||
|
The last tested revision, preview-10.8-MDEV-13756-desc-indexes / c10e10c, has shown generally acceptable results, I think the feature can be merged into the main branch and released with 10.8.1 without a new round of tests, provided that the following issues are addressed:
There are other open bugs related to the feature, but I do not consider them blockers for the release. I expect most of them to be fixed before the GA though, so that we do not increase the amount of "known legacy issues". | ||||||||||
| Comment by Elena Stepanova [ 2022-01-26 ] | ||||||||||
|
I think the last [partially] tested revision, preview-10.8-MDEV-13756-desc-indexes / 1c4cbb946, can be pushed into the main branch and released with 10.8.1. There are a few known issues remain, but they are not deemed critical for the initial release.
Due to existing legacy issues causing wrong query results, adding descending indexes to tables or converting ascending ones into descending sometimes bring different results comparing to what they were before. It happens because the change in the execution plan can trigger an old issue or, on the contrary, circumvent an old issue so that the result becomes correct while it was wrong before. These problems are usually reproducible even after replacing the use of the descending index with slight tweaks in query/schema/data, and thus need to be dealt with out of the scope of this task. Many of such legacy issues already exist in MariaDB bug tracking system, possibly there are more to be revealed. If in doubt whether it's a known problem or not, users should report the ones that they encounter. | ||||||||||
| Comment by Philip orleans [ 2022-10-18 ] | ||||||||||
|
I need this feature for INNODB, is there any version that already has it? | ||||||||||
| Comment by Max Mether [ 2022-10-18 ] | ||||||||||
|
This was added to MariaDB Community Server 10.8. Any subsequent release series will also have the feature. | ||||||||||
| Comment by Rick James [ 2022-10-18 ] | ||||||||||
|
Be aware that `ORDER BY a DESC, b DESC` with `INDEX(a,b)` has always been supported – by scanning the index backward. I think this is already optimized: The feature missing is when `ORDER BY` has multiple columns, but not in the same direction. | ||||||||||
| Comment by Artem Russakovskii [ 2024-01-25 ] | ||||||||||
|
@Rick James, I tested on 11.0.3-MariaDB-log and 10.11.3-MariaDB-log, and as soon as I add DESC to b, it adds "using filesort" to explain and the query takes twice as much time. |