Skip to content

br: compatible with and add integration test for partial index (#64434)#68829

Open
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-64434-to-release-8.5
Open

br: compatible with and add integration test for partial index (#64434)#68829
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-64434-to-release-8.5

Conversation

@ti-chi-bot
Copy link
Copy Markdown
Member

@ti-chi-bot ti-chi-bot commented Jun 1, 2026

This is an automated cherry-pick of #64434

What problem does this PR solve?

Issue Number: ref #62664

Problem Summary:
To be compatible with partial index for repairing ingest index after log restore

What changed and how does it work?

recognize the IndexInfo.ConditionExprString

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

Release Notes

  • New Features

    • Added support for restoring and preserving partial indexes with conditional WHERE expressions during database point-in-time recovery operations.
  • Tests

    • Added comprehensive test cases validating the creation, restoration, and query functionality of partial indexes with various filter conditions and index types.

Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
@ti-chi-bot ti-chi-bot added 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. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Jun 1, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 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 3pointer 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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds support for partial indexes (indexes with WHERE conditions) to the TiDB backup/restore ingest repair flow. The implementation conditionally appends WHERE clauses to generated ALTER TABLE DDL, and comprehensive test cases validate correct creation and query behavior across index metadata and data lookups.

Changes

Partial Index Condition Support

Layer / File(s) Summary
Partial index condition SQL generation
br/pkg/restore/log_client/client.go
generateRepairIngestIndexSQLs conditionally appends a WHERE clause to the generated ALTER TABLE ... ADD INDEX/KEY DDL when info.IndexInfo.ConditionExprString is non-empty.
Partial index test data, DDL, and verification
br/tests/br_pitr/prepare_data/ingest_repair.sql, br/tests/br_pitr/incremental_data/ingest_repair.sql, br/tests/br_pitr/check/check_ingest_repair.sh
Test table test.pairs20 is created with sample rows, partial indexes are defined with WHERE id > 5 predicates, and verification queries confirm correct index metadata visibility and query-driven index usage behavior.

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

cherry-pick-approved, ok-to-test

Suggested reviewers

  • winoros
  • Leavrth
  • wjhuang2016

🐰 A rabbit hops through the code so fine,
Partial indexes now align,
WHERE conditions stored with care,
Test data proves they're working fair! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding compatibility for partial indexes in the backup restore (br) module and including an integration test.
Description check ✅ Passed The description includes the required Issue Number reference (ref #62664), a problem summary explaining the need for partial index compatibility, and specifies what changed (recognizing IndexInfo.ConditionExprString). Integration test validation is marked as included.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@br/tests/br_pitr/check/check_ingest_repair.sh`:
- Around line 143-145: The current assertion in check_ingest_repair.sh queries
INFORMATION_SCHEMA.TIDB_INDEXES using an allocation-dependent INDEX_ID > 2 which
is flaky; update the SQL used by run_sql to assert partial-index rows by stable
index identifiers (INDEX_NAME) and PREDICATE instead of INDEX_ID, e.g. filter
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='pairs20' AND INDEX_NAME IN
('<partial_idx_name1>','<partial_idx_name2>') AND PREDICATE = '`id` > 5' (or use
a single INDEX_NAME = '<name>' if only one), then adjust the expected RESCNT
accordingly so the check is deterministic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bffc2494-a8a2-4f70-a397-8e18c93ecf8d

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf028c and a9036b1.

📒 Files selected for processing (4)
  • br/pkg/restore/log_client/client.go
  • br/tests/br_pitr/check/check_ingest_repair.sh
  • br/tests/br_pitr/incremental_data/ingest_repair.sql
  • br/tests/br_pitr/prepare_data/ingest_repair.sql

Comment on lines +143 to +145
## check table test.pairs20
run_sql "SELECT COUNT(*) AS RESCNT FROM INFORMATION_SCHEMA.TIDB_INDEXES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'pairs20' AND INDEX_ID > 2 AND PREDICATE = '\`id\` > 5'"
check_contains "RESCNT: 2"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Make the partial-index metadata assertion deterministic.

Line 144’s INDEX_ID > 2 is allocation-dependent and can make this check flaky. Assert by key names instead.

Suggested fix
-run_sql "SELECT COUNT(*) AS RESCNT FROM INFORMATION_SCHEMA.TIDB_INDEXES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'pairs20' AND INDEX_ID > 2 AND PREDICATE = '\`id\` > 5'"
+run_sql "SELECT COUNT(*) AS RESCNT FROM INFORMATION_SCHEMA.TIDB_INDEXES WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'pairs20' AND KEY_NAME IN ('i1','i2') AND PREDICATE = '\`id\` > 5'"
 check_contains "RESCNT: 2"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@br/tests/br_pitr/check/check_ingest_repair.sh` around lines 143 - 145, The
current assertion in check_ingest_repair.sh queries
INFORMATION_SCHEMA.TIDB_INDEXES using an allocation-dependent INDEX_ID > 2 which
is flaky; update the SQL used by run_sql to assert partial-index rows by stable
index identifiers (INDEX_NAME) and PREDICATE instead of INDEX_ID, e.g. filter
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='pairs20' AND INDEX_NAME IN
('<partial_idx_name1>','<partial_idx_name2>') AND PREDICATE = '`id` > 5' (or use
a single INDEX_NAME = '<name>' if only one), then adjust the expected RESCNT
accordingly so the check is deterministic.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 2026

@ti-chi-bot: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/check_dev_2 a9036b1 link true /test check-dev2
pull-br-integration-test a9036b1 link true /test pull-br-integration-test
idc-jenkins-ci-tidb/check_dev a9036b1 link true /test check-dev
idc-jenkins-ci-tidb/unit-test a9036b1 link true /test unit-test
idc-jenkins-ci-tidb/mysql-test a9036b1 link true /test mysql-test
idc-jenkins-ci-tidb/build a9036b1 link true /test build

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@tiprow
Copy link
Copy Markdown

tiprow Bot commented Jun 1, 2026

@ti-chi-bot: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow_for_release a9036b1 link true /test fast_test_tiprow_for_release

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot Bot added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-approved Cherry pick PR approved by release team. 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. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants