Skip to content

Document descending-order index support (pingcap/tidb#2519)#22805

Draft
takaidohigasi wants to merge 2 commits intopingcap:masterfrom
takaidohigasi:feature/desc-index
Draft

Document descending-order index support (pingcap/tidb#2519)#22805
takaidohigasi wants to merge 2 commits intopingcap:masterfrom
takaidohigasi:feature/desc-index

Conversation

@takaidohigasi
Copy link
Copy Markdown
Contributor

What is changed, added or deleted? (Required)

Add user-facing documentation for the descending-order index feature
introduced in pingcap/tidb#68049 (and the corresponding TiKV change in
tikv/tikv#19558).

Three files updated:

  1. system-variables.md — new tidb_enable_descending_index entry
    documenting scope, default OFF, and the TiKV-version prerequisite.
  2. sql-statements/sql-statement-create-index.md — replace the
    existing "descending indexes are not supported (similar to MySQL 5.7)"
    note with the new conditional-support description, including the
    mixed-direction composite-index example (INDEX(a ASC, b DESC)
    satisfying ORDER BY a ASC, b DESC without a Sort).
  3. mysql-compatibility.md — qualify the existing "Descending Index"
    entry so it is no longer listed as wholly unsupported.

Which TiDB version(s) do your changes apply to? (Required)

  • master (the latest development version)

The feature is gated behind tidb_enable_descending_index (default
OFF), so the visible behaviour change is opt-in. Backporting to older
release branches is not appropriate because the feature requires a
matching TiKV release that contains tikv/tikv#19558.

What is the related PR or file link(s)?

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

🤖 Generated with Claude Code

Add user-facing documentation for the descending-order index feature
introduced in pingcap/tidb#68049 (and the corresponding TiKV change
in tikv/tikv#19558):

  * system-variables.md: new tidb_enable_descending_index entry
    documenting scope, default OFF, and the TiKV-version prerequisite.
  * sql-statements/sql-statement-create-index.md: replace the
    "descending indexes are not supported" note with the new
    conditional-support description, including the mixed-direction
    composite-index example that motivates the feature.
  * mysql-compatibility.md: qualify the existing Descending Index entry
    so it is no longer listed as wholly unsupported.

Signed-off-by: takaidohigasi <takaidohigasi@gmail.com>
@ti-chi-bot ti-chi-bot Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. contribution This PR is from a community contributor. labels Apr 25, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 25, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign icemap for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 25, 2026

Hi @takaidohigasi. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. missing-translation-status This PR does not have translation status info. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 25, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces documentation for descending index support, a new opt-in feature in TiDB v9.0.0 controlled by the tidb_enable_descending_index system variable. The changes include updates to the MySQL compatibility list, the CREATE INDEX statement documentation, and the addition of the new system variable's details. Review feedback focused on improving conciseness, ensuring consistent terminology, and adhering to style guide principles such as using the active voice and addressing the user in the second person.

Comment thread mysql-compatibility.md Outdated
+ `CREATE TABLESPACE` statement
+ "Session Tracker: Add GTIDs context to the OK packet"
+ Descending Index [#2519](https://github.com/pingcap/tidb/issues/2519)
+ Descending Index [#2519](https://github.com/pingcap/tidb/issues/2519) (supported as an opt-in feature starting from v9.0.0; controlled by the [`tidb_enable_descending_index`](/system-variables.md#tidb_enable_descending_index-new-in-v900) system variable, which defaults to `OFF`)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

This entry is a bit wordy for a list item. Following the general writing principle of avoiding unnecessary words, you can simplify the description of the feature's availability and control mechanism.

Suggested change
+ Descending Index [#2519](https://github.com/pingcap/tidb/issues/2519) (supported as an opt-in feature starting from v9.0.0; controlled by the [`tidb_enable_descending_index`](/system-variables.md#tidb_enable_descending_index-new-in-v900) system variable, which defaults to `OFF`)
+ Descending Index [#2519](https://github.com/pingcap/tidb/issues/2519) (supported since v9.0.0; controlled by the [`tidb_enable_descending_index`](/system-variables.md#tidb_enable_descending_index-new-in-v900) system variable)
References
  1. Avoid unnecessary words and repetition. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already applied verbatim — see commit d9a65a687 ("Apply gemini-code-assist style suggestions on the desc-index docs"). The file content on this PR already matches your suggestion.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thank you for the update. Since the change has already been applied in commit d9a65a687, no further action is needed on this thread.


* TiDB accepts index types such as `HASH`, `BTREE` and `RTREE` in syntax for compatibility with MySQL, but ignores them.
* Descending indexes are not supported (similar to MySQL 5.7).
* Descending-order indexes are supported when the [`tidb_enable_descending_index`](/system-variables.md#tidb_enable_descending_index-new-in-v900) system variable is set to `ON` (default `OFF`). When the variable is `OFF`, the `DESC` keyword on individual index columns is parsed but ignored, matching MySQL 5.7 behavior. When `ON`, columns marked `DESC` are stored in descending order, allowing composite indexes such as `INDEX(a ASC, b DESC)` to satisfy `ORDER BY a ASC, b DESC` with a single forward index scan and no additional `Sort` operator. This brings TiDB closer to MySQL 8.0 compatibility for descending indexes; expression and `FULLTEXT` indexes do not support `DESC`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

To maintain consistency with standard MySQL terminology and improve readability, consider using "Descending indexes" and splitting the long final sentence. This also clarifies the limitations for expression and FULLTEXT indexes.

Suggested change
* Descending-order indexes are supported when the [`tidb_enable_descending_index`](/system-variables.md#tidb_enable_descending_index-new-in-v900) system variable is set to `ON` (default `OFF`). When the variable is `OFF`, the `DESC` keyword on individual index columns is parsed but ignored, matching MySQL 5.7 behavior. When `ON`, columns marked `DESC` are stored in descending order, allowing composite indexes such as `INDEX(a ASC, b DESC)` to satisfy `ORDER BY a ASC, b DESC` with a single forward index scan and no additional `Sort` operator. This brings TiDB closer to MySQL 8.0 compatibility for descending indexes; expression and `FULLTEXT` indexes do not support `DESC`.
* Descending indexes are supported when the [`tidb_enable_descending_index`](/system-variables.md#tidb_enable_descending_index-new-in-v900) system variable is set to `ON` (default `OFF`). When this variable is `OFF`, the `DESC` keyword on individual index columns is parsed but ignored, matching MySQL 5.7 behavior. When `ON`, columns marked `DESC` are stored in descending order. This allows composite indexes such as `INDEX(a ASC, b DESC)` to satisfy `ORDER BY a ASC, b DESC` with a single forward index scan and no additional `Sort` operator. This brings TiDB closer to MySQL 8.0 compatibility for descending indexes. Expression and `FULLTEXT` indexes do not support `DESC`.
References
  1. Use consistent terminology. (link)
  2. Avoid unnecessary words and repetition. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already applied verbatim — see commit d9a65a687. "Descending indexes" terminology and the split sentences (FULLTEXT exclusion on its own line) are in.

Comment thread system-variables.md Outdated
Comment on lines +2175 to +2187
### tidb_enable_descending_index <span class="version-mark">New in v9.0.0</span>

> **Note:**
>
> Setting this variable to `ON` requires that every TiKV store in the cluster supports descending-order index keys. TiDB rejects `CREATE INDEX` and `CREATE TABLE` statements that would persist a descending column when any store reports a TiKV version below the minimum required by this feature; upgrade TiKV before enabling this variable.

- Scope: GLOBAL
- Persists to cluster: Yes
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
- Type: Boolean
- Default value: `OFF`
- This variable controls whether the `DESC` keyword on individual columns of `CREATE INDEX` and `CREATE TABLE` statements is honored. When set to `OFF` (the default), TiDB parses the `DESC` keyword for compatibility with MySQL 5.7 but stores all index columns in ascending order. When set to `ON`, columns marked `DESC` are stored in descending order, allowing composite indexes such as `INDEX(a ASC, b DESC)` to satisfy `ORDER BY a ASC, b DESC` directly without an additional `Sort` operator.
- The variable is evaluated at DDL time only. Toggling it after creating descending indexes does not change those indexes; subsequent `CREATE INDEX` statements with `DESC` are governed by the variable's current value.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The description of this system variable can be improved by using active voice and addressing the user in the second person, as per the general writing principles. Additionally, removing unnecessary words like "the" in "(the default)" enhances conciseness.

Suggested change
### tidb_enable_descending_index <span class="version-mark">New in v9.0.0</span>
> **Note:**
>
> Setting this variable to `ON` requires that every TiKV store in the cluster supports descending-order index keys. TiDB rejects `CREATE INDEX` and `CREATE TABLE` statements that would persist a descending column when any store reports a TiKV version below the minimum required by this feature; upgrade TiKV before enabling this variable.
- Scope: GLOBAL
- Persists to cluster: Yes
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
- Type: Boolean
- Default value: `OFF`
- This variable controls whether the `DESC` keyword on individual columns of `CREATE INDEX` and `CREATE TABLE` statements is honored. When set to `OFF` (the default), TiDB parses the `DESC` keyword for compatibility with MySQL 5.7 but stores all index columns in ascending order. When set to `ON`, columns marked `DESC` are stored in descending order, allowing composite indexes such as `INDEX(a ASC, b DESC)` to satisfy `ORDER BY a ASC, b DESC` directly without an additional `Sort` operator.
- The variable is evaluated at DDL time only. Toggling it after creating descending indexes does not change those indexes; subsequent `CREATE INDEX` statements with `DESC` are governed by the variable's current value.
### tidb_enable_descending_index <span class="version-mark">New in v9.0.0</span>
> **Note:**
>
> Setting this variable to `ON` requires every TiKV store in the cluster to support descending-order index keys. TiDB rejects `CREATE INDEX` and `CREATE TABLE` statements that persist a descending column if any store reports a TiKV version below the minimum required version. Upgrade TiKV before you enable this variable.
- Scope: GLOBAL
- Persists to cluster: Yes
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
- Type: Boolean
- Default value: `OFF`
- This variable controls whether TiDB honors the `DESC` keyword on individual columns in `CREATE INDEX` and `CREATE TABLE` statements. When this variable is set to `OFF` (default), TiDB parses the `DESC` keyword for compatibility with MySQL 5.7 but stores all index columns in ascending order. When set to `ON`, columns marked `DESC` are stored in descending order, which allows composite indexes such as `INDEX(a ASC, b DESC)` to satisfy `ORDER BY a ASC, b DESC` directly without an additional `Sort` operator.
- TiDB evaluates this variable only at DDL time. Toggling it after you create descending indexes does not change those indexes. Subsequent `CREATE INDEX` statements with `DESC` use the current value of this variable.
References
  1. Passive voice overuse. (link)
  2. Write in second person ("you") when addressing users. (link)
  3. Avoid unnecessary words and repetition. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already applied verbatim — see commit d9a65a687. Active voice, second person, and "(default)" instead of "(the default)" are in.

Three low-priority style fixes from the bot review on
pingcap#22805, all matching the docs styleguide:

  * mysql-compatibility.md: trim wordiness on the descending-index
    bullet ("supported as an opt-in feature starting from" -> "supported
    since"; drop the redundant default-value parenthetical).
  * sql-statement-create-index.md: use "Descending indexes" instead of
    "Descending-order indexes" for consistent terminology, and split
    the long final sentence so the FULLTEXT exclusion stands on its
    own line.
  * system-variables.md: rewrite the description in active voice and
    second person, drop "(the default)" in favour of "(default)", and
    split the toggle-semantics paragraph into two sentences.

No content changes - the technical claims and links are identical.

Signed-off-by: takaidohigasi <takaidohigasi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. missing-translation-status This PR does not have translation status info. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant