Skip to content

index: add document for partial index (#21903)#22991

Open
YangKeao wants to merge 1 commit into
pingcap:release-8.5from
YangKeao:cherry-pick-21903-release-8.5
Open

index: add document for partial index (#21903)#22991
YangKeao wants to merge 1 commit into
pingcap:release-8.5from
YangKeao:cherry-pick-21903-release-8.5

Conversation

@YangKeao
Copy link
Copy Markdown
Member

@YangKeao YangKeao commented Jun 2, 2026

Pick from #21903

First-time contributors' checklist

What is changed, added or deleted? (Required)

  1. Add the document for partial index.

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

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

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

Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>

(cherry picked from commit 355e3e4)
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 2, 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 tangenta 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 ti-chi-bot Bot added missing-translation-status This PR does not have translation status info. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 2, 2026
@YangKeao YangKeao requested review from Oreoxmt and winoros June 2, 2026 04:03
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 the "Partial indexes" feature in TiDB, including creation syntax, usage examples, use cases, limitations, and performance benefits. The reviewer's feedback focuses on aligning the text with the documentation style guide by addressing passive voice, removing contractions, using second-person perspective, correcting minor grammatical errors, and ensuring consistent capitalization of SQL keywords in examples. All review comments are valid and provide actionable improvements.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

3 rows in set (0.00 sec)
```

If the predicates in query don't meet the index definition, the index will not be chosen even with hint:
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.

medium

Rewrite to avoid contractions ("don't"), passive voice ("will not be chosen"), and grammatical issues ("in query", "with hint").

Suggested change
If the predicates in query don't meet the index definition, the index will not be chosen even with hint:
If the predicates in a query do not match the index definition, TiDB does not choose the index, even if you use a hint:
References
  1. Avoid passive voice overuse. (link)

Partial indexes offer several advantages:

1. **Reduced storage**: Only rows matching the predicate are indexed, saving storage space
2. **Faster DML**: It'll be faster to maintain the index of a subset of data during INSERT, UPDATE, and DELETE operations
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.

medium

Avoid contractions ("It'll"), use active voice, and format SQL keywords (INSERT, UPDATE, DELETE) with backticks as required by the style guide.

Suggested change
2. **Faster DML**: It'll be faster to maintain the index of a subset of data during INSERT, UPDATE, and DELETE operations
2. **Faster DML**: Maintaining a partial index is faster during `INSERT`, `UPDATE`, and `DELETE` operations because TiDB only updates the index for a subset of data
References
  1. Avoid passive voice overuse and use backticks for code snippets/command names. (link)


Partial indexes offer several advantages:

1. **Reduced storage**: Only rows matching the predicate are indexed, saving storage space
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.

medium

Rewrite in the active voice to improve readability.

Suggested change
1. **Reduced storage**: Only rows matching the predicate are indexed, saving storage space
1. **Reduced storage**: TiDB indexes only the rows that match the predicate, which saves storage space
References
  1. Avoid passive voice overuse. (link)

- The `WHERE` clause in partial indexes supports basic comparison operators (`=`, `!=`, `<`, `<=`, `>`, `>=`) and `IN` predicates with constant values
- The types of the column and constant value should be the same
- The predicate can only reference columns from the same table
- Partial indexes cannot be used on expression indexes
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.

medium

Rewrite in the active voice using the second person ("you") to align with the technical writing style guide.

Suggested change
- Partial indexes cannot be used on expression indexes
- You cannot create a partial index on an expression index
References
  1. Avoid passive voice overuse and write in second person ('you') when addressing users. (link)


- The `WHERE` clause in partial indexes supports basic comparison operators (`=`, `!=`, `<`, `<=`, `>`, `>=`) and `IN` predicates with constant values
- The types of the column and constant value should be the same
- The predicate can only reference columns from the same table
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.

medium

Use "must" instead of "can" to specify a strict requirement, and place "only" precisely before the phrase it modifies.

Suggested change
- The predicate can only reference columns from the same table
- The predicate must reference only columns from the same table

+-------------------------------+----------+-----------+-------------------------------------------+---------------------------------+
4 rows in set (0.00 sec)

mysql> explain SELECT * FROM users WHERE score > 10000 ORDER BY created_at;
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

Use uppercase EXPLAIN to maintain consistency with other examples in this document.

Suggested change
mysql> explain SELECT * FROM users WHERE score > 10000 ORDER BY created_at;
mysql> EXPLAIN SELECT * FROM users WHERE score > 10000 ORDER BY created_at;

+-------------------------------+---------+-----------+-------------------------------------------+-------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> explain SELECT * FROM users WHERE status = 'active' ORDER BY name;
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

Use uppercase EXPLAIN to maintain consistency with other examples in this document.

Suggested change
mysql> explain SELECT * FROM users WHERE status = 'active' ORDER BY name;
mysql> EXPLAIN SELECT * FROM users WHERE status = 'active' ORDER BY name;

ALTER TABLE t1 ADD INDEX idx2 (c1, c2) WHERE c3 = 'abc';
```

Or specify the partial index when creating the table:
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

Use the second person ("you") to address users, as recommended by the technical writing style guide.

Suggested change
Or specify the partial index when creating the table:
Or you can specify the partial index when creating the table:
References
  1. Write in second person ('you') when addressing users. (link)

```

Then the following queries can use the partial index:

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

Avoid unnecessary words like "Then" and use the plural "partial indexes" since the queries in the example use different partial indexes.

Suggested change
The following queries can use the partial indexes:
References
  1. Avoid unnecessary words and repetition. (link)

CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
status varchar(20),
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

Use uppercase VARCHAR(20) to maintain consistency with other SQL data types in the example.

Suggested change
status varchar(20),
status VARCHAR(20),

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 2, 2026

@yudongusa: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

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.

github-actions Bot pushed a commit to doc-claw-bot/pingcap-docsite-preview that referenced this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-translation-status This PR does not have translation status info. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants