Rechercher dans le manuel MySQL
8.3.13 Descending Indexes
MySQL supports descending indexes: DESC
in an
index definition is no longer ignored but causes storage of key
values in descending order. Previously, indexes could be scanned
in reverse order but at a performance penalty. A descending
index can be scanned in forward order, which is more efficient.
Descending indexes also make it possible for the optimizer to
use multiple-column indexes when the most efficient scan order
mixes ascending order for some columns and descending order for
others.
Consider the following table definition, which contains two columns and four two-column index definitions for the various combinations of ascending and descending indexes on the columns:
- );
The table definition results in four distinct indexes. The
optimizer can perform a forward index scan for each of the
ORDER BY
clauses and need not use a
filesort
operation:
Use of descending indexes is subject to these conditions:
Descending indexes are supported only for the
InnoDB
storage engine, with these limitations:Change buffering is not supported for a secondary index if the index contains a descending index key column or if the primary key includes a descending index column.
The
InnoDB
SQL parser does not use descending indexes. ForInnoDB
full-text search, this means that the index required on theFTS_DOC_ID
column of the indexed table cannot be defined as a descending index. For more information, see Section 15.6.2.4, “InnoDB FULLTEXT Indexes”.
Descending indexes are supported for all data types for which ascending indexes are available.
Descending indexes are supported for ordinary (nongenerated) and generated columns (both
VIRTUAL
andSTORED
).DISTINCT
can use any index containing matching columns, including descending key parts.Indexes that have descending key parts are not used for
MIN()
/MAX()
optimization of queries that invoke aggregate functions but do not have aGROUP BY
clause.Descending indexes are supported for
BTREE
but notHASH
indexes. Descending indexes are not supported forFULLTEXT
orSPATIAL
indexes.Explicitly specified
ASC
andDESC
designators forHASH
,FULLTEXT
, andSPATIAL
indexes results in an error.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-descending-indexes.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.