Skip to content

ddl: fix alter index visibility suffix collision#70056

Open
idle-lab wants to merge 1 commit into
pingcap:masterfrom
idle-lab:fix/alter-index-visibility-suffix-collision
Open

ddl: fix alter index visibility suffix collision#70056
idle-lab wants to merge 1 commit into
pingcap:masterfrom
idle-lab:fix/alter-index-visibility-suffix-collision

Conversation

@idle-lab

@idle-lab idle-lab commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #70049

Problem Summary:

ALTER TABLE ... ALTER INDEX ... VISIBLE/INVISIBLE could incorrectly change the visibility of other indexes whose names shared the same underscore-delimited prefix. For example, altering idx_k also affected idx_k_copy, because normal indexes were incorrectly treated as temporary indexes created during a column change.

What changed and how does it work?

The visibility update now matches an index by its original name only when it is an actual temporary changing index. It checks both IsChanging() and isTempIndex() before comparing the original index name.

Regression tests cover:

  • Changing an index to INVISIBLE.
  • Changing an index to VISIBLE.
  • Numeric and non-numeric underscore suffixes, such as idx_k_1 and idx_k_copy.

These similarly named indexes now retain their original visibility

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Summary by CodeRabbit

  • Bug Fixes
    • Fixed index visibility changes for indexes with underscore-delimited names.
    • Improved visibility updates while indexes are being renamed or modified.
    • Added regression coverage to ensure only the targeted index is marked visible or invisible.

@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed labels Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 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 benjamin2037 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 contribution This PR is from a community contributor. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

Hi @idle-lab. 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.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d6b21044-cf00-4eee-ba14-944bcffb8bd9

📥 Commits

Reviewing files that changed from the base of the PR and between 231dad5 and 96e56c7.

📒 Files selected for processing (2)
  • pkg/ddl/db_change_test.go
  • pkg/ddl/index.go

📝 Walkthrough

Walkthrough

setIndexVisibility now avoids treating ordinary underscore-suffixed indexes as temporary indexes, and TestParallelAlterIndex adds regression coverage confirming only the named index changes visibility.

Changes

Index visibility behavior

Layer / File(s) Summary
Visibility matching and regression coverage
pkg/ddl/index.go, pkg/ddl/db_change_test.go
Visibility updates require a changing temporary index before comparing its origin name, while regression tests verify suffixed ordinary indexes remain unaffected.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: lcwangchao

Poem

A rabbit checked the index row,
And watched the named one hide below.
Its suffix friend stayed bright and clear,
No stray visibility changes here.
Hop, hop—issue fixed with cheer!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: fixing ALTER INDEX visibility handling for suffix collisions.
Description check ✅ Passed The description includes the issue number, problem summary, implementation details, tests, and release note placeholder, matching the template well.
Linked Issues check ✅ Passed The code and regression tests address issue #70049 by preventing unrelated suffix-matched indexes from being treated as changing indexes.
Out of Scope Changes check ✅ Passed The changes are scoped to the reported ALTER INDEX visibility bug and its regression tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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/needs-triage-completed needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. release-note-none Denotes a PR that doesn't merit a release note. 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.

ddl: ALTER INDEX incorrectly changes another index's visibility after stripping its final underscore-delimited suffix

1 participant