Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-13756

Implement descending index: KEY (a DESC, b ASC)

Details

    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:

      NULLS LAST is the default for ascending order, and NULLS FIRST is the default for descending order.

      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.

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova added a comment - - edited

            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.
            Examples (not an exhaustive list):

            • fulltext search on tables with descending PK may misbehave (MDEV-27582),
            • different direction of indexes on a Spider table and an underlying table should be avoided (MDEV-27633).

            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.

            elenst Elena Stepanova added a comment - - edited 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. Examples (not an exhaustive list): fulltext search on tables with descending PK may misbehave ( MDEV-27582 ), different direction of indexes on a Spider table and an underlying table should be avoided ( MDEV-27633 ). 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.

            I need this feature for INNODB, is there any version that already has it?
            Are there plans to have it?

            philip_38 Philip orleans added a comment - I need this feature for INNODB, is there any version that already has it? Are there plans to have it?
            maxmether Max Mether added a comment -

            This was added to MariaDB Community Server 10.8. Any subsequent release series will also have the feature.

            maxmether Max Mether added a comment - This was added to MariaDB Community Server 10.8. Any subsequent release series will also have the feature.
            rjasdfiii Rick James added a comment -

            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:
            WHERE a=constant
            ORDER BY a ASC, b DESC

            The feature missing is when `ORDER BY` has multiple columns, but not in the same direction.

            rjasdfiii Rick James added a comment - 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: WHERE a=constant ORDER BY a ASC, b DESC The feature missing is when `ORDER BY` has multiple columns, but not in the same direction.

            @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.

            archon810 Artem Russakovskii added a comment - @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.

            People

              serg Sergei Golubchik
              marko Marko Mäkelä
              Votes:
              24 Vote for this issue
              Watchers:
              24 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.