Skip to content

docs: fix schema_unused_indexes source table and restart-scope wording - #23891

Open
yahonda wants to merge 2 commits into
pingcap:release-8.5from
yahonda:fix-schema-unused-indexes-wording
Open

yahonda wants to merge 2 commits into
pingcap:release-8.5from
yahonda:fix-schema-unused-indexes-wording

Conversation

@yahonda

@yahonda yahonda commented Sep 16, 2026

Copy link
Copy Markdown
Member

What is changed, added or deleted? (Required)

best-practices/index-management-best-practices.md's "How schema_unused_indexes works" section said the view is derived from TIDB_INDEX_USAGE and filters out indexes with zero activity "since the last TiDB restart" (implying a single cluster-wide restart).

The actual view definition (see sys-schema/sys-schema-unused-indexes.md) is:

CREATE OR REPLACE VIEW sys.schema_unused_indexes AS
  SELECT
    table_schema as object_schema,
    table_name as object_name,
    index_name
  FROM information_schema.cluster_tidb_index_usage
  WHERE ...
  GROUP BY table_schema, table_name, index_name
  HAVING
    sum(last_access_time) is null;

This reads from CLUSTER_TIDB_INDEX_USAGE (which aggregates usage across all TiDB instances), not from the single-instance TIDB_INDEX_USAGE. It flags an index as unused only when none of the cluster's instances have recorded access since that instance's own last restart — not a single cluster-wide restart event.

Found while reviewing the Japanese translation of this file (which faithfully mirrored the inaccurate EN wording) — flagged by a CodeRabbit review on the JA PR, verified against the real view definition before filing this fix.

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

  • master (the latest development version)
  • v8.5 (TiDB 8.5 versions)
  • v8.4 (TiDB 8.4 versions)
  • v8.3 (TiDB 8.3 versions)
  • v8.2 (TiDB 8.2 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)

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

AI agent involvement

  • The changes in this PR were primarily made by an AI agent on behalf of the PR author.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved unused-index reporting to consider index activity across all TiDB instances.
    • Indexes are now identified as unused only when they have not been accessed since the relevant instance restarts.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: cc96a4c1-6348-4c0c-943c-b642280d4c2a

📥 Commits

Reviewing files that changed from the base of the PR and between 492280b and 2f8ab70.

📒 Files selected for processing (1)
  • best-practices/index-management-best-practices.md
📝 Walkthrough

Walkthrough

The documentation updates schema_unused_indexes to use CLUSTER_TIDB_INDEX_USAGE. It now identifies indexes with no access on any TiDB instance since each instance’s last restart.

Changes

Index usage documentation

Layer / File(s) Summary
Update unused-index detection
best-practices/index-management-best-practices.md
The documented query uses cluster-wide index usage data instead of per-instance data. It checks for indexes with no access across TiDB instances since their respective restarts.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Other

Merge Risk: 🔵 Low · up to 49228

The section gives conflicting restart scopes, which can lead readers to misunderstand when an index is considered unused. Align the nearby wording before merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the documentation fix: correcting the source table and restart-scope wording for schema_unused_indexes.
Description check ✅ Passed The description explains the documentation change, affected TiDB version, reference link, AI involvement, and applicable change categories. It provides the required information and is aligned with the…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ti-chi-bot

ti-chi-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

[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 lilin90 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 16, 2026
The sys.schema_unused_indexes view (see sys-schema/sys-schema-unused-indexes.md)
is defined as SELECT ... FROM information_schema.cluster_tidb_index_usage
... GROUP BY ... HAVING sum(last_access_time) is null, i.e. it is derived
from CLUSTER_TIDB_INDEX_USAGE (which aggregates usage across all TiDB
instances), not from the single-instance TIDB_INDEX_USAGE. It also flags
an index only once none of the cluster's instances have recorded access
since their own last restart, not a single cluster-wide restart event.

Found while reviewing the Japanese translation of this file, which
faithfully mirrored the inaccurate EN wording.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@yahonda
yahonda force-pushed the fix-schema-unused-indexes-wording branch from 3a21f13 to 492280b Compare September 18, 2026 08:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: d80c7505-ee78-4368-ac73-df6bd4bab750

📥 Commits

Reviewing files that changed from the base of the PR and between 9c5b903 and 492280b.

📒 Files selected for processing (1)
  • best-practices/index-management-best-practices.md

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread best-practices/index-management-best-practices.md
…indexes

CLUSTER_TIDB_INDEX_USAGE aggregates across all TiDB instances, and an
index counts as unused only when no instance has recorded access since
that instance's own last restart, not since a single cluster-wide
restart. Align the intro sentence and considerations heading with the
per-instance wording already used elsewhere in this section.

Found by CodeRabbit review on PR pingcap#23891.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant