Skip to content

parser: modify parser to support partial index (#63448)#68830

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

parser: modify parser to support partial index (#63448)#68830
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-63448-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 #63448

What problem does this PR solve?

Issue Number: close #63447

-> #63448
#62759
#62762

Problem Summary:

What changed and how does it work?

Modify the parser to support partial index grammar

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

  • New Features
    • Added support for partial (conditional) indexes with WHERE clauses in CREATE INDEX and ALTER TABLE statements.
    • Extended index options to support PRE_SPLIT_REGIONS and SECONDARY_ENGINE_ATTRIBUTE specifications.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ 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
Member Author

@YangKeao This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 2026

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

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 ti-community-infra/tichi repository.

@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 bornchanger, yudongusa 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 extends TiDB's SQL parser to support partial indexes with WHERE conditions. The changes add AST fields to represent partial-index clauses, extend parser grammar to recognize the new syntax, and include test coverage for three index creation forms: inline table indexes, standalone CREATE INDEX, and ALTER TABLE ADD INDEX.

Changes

Partial Index Parser Support

Layer / File(s) Summary
IndexOption struct and serialization for partial indexes
pkg/parser/ast/ddl.go
IndexOption struct extended with SplitOpt, SecondaryEngineAttr, and Condition fields; field types updated from model.* to local types; IsEmpty() returns false when new fields are present; Restore() outputs PRE_SPLIT_REGIONS (in TiDB comment), SECONDARY_ENGINE_ATTRIBUTE =, and WHERE <expr> when applicable.
Parser grammar for partial index clauses
pkg/parser/parser.y
Parser grammar extended to recognize PRE_SPLIT_REGIONS, SECONDARY_ENGINE_ATTRIBUTE, and WHERE <Expression> in IndexOption productions; IndexOptionList merge logic propagates SplitOpt, SecondaryEngineAttr, and Condition across multiple index option clauses.
Partial index parsing test cases
pkg/parser/parser_test.go
New TestPartialIndex test validates parsing and restoration of partial indexes in three contexts: inline table key, standalone CREATE INDEX, and ALTER TABLE ADD INDEX with WHERE predicate.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • pingcap/tidb#68628: Adds FK index-coverage logic to handle partial-index predicates for foreign key enforcement, building on the partial index condition metadata added in this PR.

Suggested labels

size/S, ok-to-test, needs-cherry-pick-release-8.5

Suggested reviewers

  • wjhuang2016
  • winoros
  • qw4990

Poem

🐰 A partial index hop, with WHERE clauses in tow,
Parser grammar now knows the dance,
AST fields sprout and grow,
WHERE predicates get their chance,
Conditional indexing takes the floor! 🎩✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding parser support for partial indexes.
Description check ✅ Passed The description follows the template with Problem Summary (referencing issue #63447), What changed section, and completed checklist (Unit test checked).
Linked Issues check ✅ Passed The PR implements all three required grammar forms for partial indexes (CREATE TABLE, CREATE INDEX, ALTER TABLE) with parser support and unit tests.
Out of Scope Changes check ✅ Passed All changes are focused on supporting partial index parsing: AST field additions, parser grammar rules, and corresponding unit tests with no unrelated modifications.

✏️ 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: 2

🤖 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 `@pkg/parser/ast/ddl.go`:
- Around line 731-752: Remove the leftover merge-conflict markers (<<<<<<<,
=======, >>>>>>>) in the struct definition around KeyBlockSize/Tp/... and
resolve the duplicated fields by keeping the intended branch state (the updated
struct that includes KeyBlockSize, Tp (IndexType), Comment, ParserName (CIStr),
Visibility, PrimaryKeyTp, Global plus the new fields SplitOpt *SplitOption,
SecondaryEngineAttr, AddColumnarReplicaOnDemand and Condition ExprNode) so the
struct is consistent and compiles; do the same cleanup for the other conflict
regions referenced (around the other occurrences at the noted ranges) ensuring
no conflict markers remain and field types/names match the updated Index-related
types (IndexType, CIStr, PrimaryKeyType, SplitOption, ExprNode).

In `@pkg/parser/parser.y`:
- Around line 6638-6646: Remove the leftover merge conflict markers (<<<<<<<,
=======, >>>>>>>) and keep a single coherent else-if chain that merges opt2 into
opt1 (the intended actions assigning opt1.SplitOpt = opt2.SplitOpt,
opt1.SecondaryEngineAttr = opt2.SecondaryEngineAttr, opt1.Condition =
opt2.Condition as appropriate). Locate the conflicting block around the
opt1/opt2 handling (references: opt1, opt2, SplitOpt, SecondaryEngineAttr,
Condition) and delete the conflict markers and duplicate branches so the
parser.y grammar contains only the correct sequence; also apply the same
removal/fix for the later conflicting region (the other block around lines
6703-6729) to ensure the file is valid for parser generation.
🪄 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: 510be38c-d1e8-40f9-9592-ae68d71aefa9

📥 Commits

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

📒 Files selected for processing (4)
  • pkg/parser/ast/ddl.go
  • pkg/parser/parser.go
  • pkg/parser/parser.y
  • pkg/parser/parser_test.go

Comment thread pkg/parser/ast/ddl.go
Comment on lines +731 to 752
<<<<<<< HEAD
KeyBlockSize uint64
Tp model.IndexType
Comment string
ParserName model.CIStr
Visibility IndexVisibility
PrimaryKeyTp model.PrimaryKeyType
Global bool
=======
KeyBlockSize uint64
Tp IndexType
Comment string
ParserName CIStr
Visibility IndexVisibility
PrimaryKeyTp PrimaryKeyType
Global bool
SplitOpt *SplitOption `json:"-"` // SplitOption contains expr nodes, which cannot marshal for DDL job arguments.
SecondaryEngineAttr string
AddColumnarReplicaOnDemand int
Condition ExprNode `json:"-"` // Condition contains expr nodes, which cannot marshal for DDL job arguments. It's used for partial index.
>>>>>>> 7b93bcb4150 (parser: modify parser to support partial index (#63448))
}
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 | 🔴 Critical | ⚡ Quick win

Resolve leftover merge-conflict markers before merge.

Lines in this file still contain <<<<<<<, =======, >>>>>>>, which makes the parser package fail to compile and blocks validation of the partial-index changes. Please resolve the conflict and keep only the intended branch state.

Suggested cleanup (illustrative)
-<<<<<<< HEAD
-...
-=======
-...
->>>>>>> 7b93bcb4150 (parser: modify parser to support partial index (`#63448`))
+// keep only the resolved final implementation

Also applies to: 763-770, 844-892

🤖 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 `@pkg/parser/ast/ddl.go` around lines 731 - 752, Remove the leftover
merge-conflict markers (<<<<<<<, =======, >>>>>>>) in the struct definition
around KeyBlockSize/Tp/... and resolve the duplicated fields by keeping the
intended branch state (the updated struct that includes KeyBlockSize, Tp
(IndexType), Comment, ParserName (CIStr), Visibility, PrimaryKeyTp, Global plus
the new fields SplitOpt *SplitOption, SecondaryEngineAttr,
AddColumnarReplicaOnDemand and Condition ExprNode) so the struct is consistent
and compiles; do the same cleanup for the other conflict regions referenced
(around the other occurrences at the noted ranges) ensuring no conflict markers
remain and field types/names match the updated Index-related types (IndexType,
CIStr, PrimaryKeyType, SplitOption, ExprNode).

Comment thread pkg/parser/parser.y
Comment on lines +6638 to +6646
<<<<<<< HEAD
=======
} else if opt2.SplitOpt != nil {
opt1.SplitOpt = opt2.SplitOpt
} else if len(opt2.SecondaryEngineAttr) > 0 {
opt1.SecondaryEngineAttr = opt2.SecondaryEngineAttr
} else if opt2.Condition != nil {
opt1.Condition = opt2.Condition
>>>>>>> 7b93bcb4150 (parser: modify parser to support partial index (#63448))
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 | 🔴 Critical | ⚡ Quick win

Resolve unresolved merge-conflict markers in grammar

<<<<<<<, =======, >>>>>>> are still present (Line 6638 and Line 6703). This makes parser.y invalid and blocks parser generation/build. Please resolve the conflict and keep only the intended grammar/actions.

Also applies to: 6703-6729

🤖 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 `@pkg/parser/parser.y` around lines 6638 - 6646, Remove the leftover merge
conflict markers (<<<<<<<, =======, >>>>>>>) and keep a single coherent else-if
chain that merges opt2 into opt1 (the intended actions assigning opt1.SplitOpt =
opt2.SplitOpt, opt1.SecondaryEngineAttr = opt2.SecondaryEngineAttr,
opt1.Condition = opt2.Condition as appropriate). Locate the conflicting block
around the opt1/opt2 handling (references: opt1, opt2, SplitOpt,
SecondaryEngineAttr, Condition) and delete the conflict markers and duplicate
branches so the parser.y grammar contains only the correct sequence; also apply
the same removal/fix for the later conflicting region (the other block around
lines 6703-6729) to ensure the file is valid for parser generation.

@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 3c6ee3f link true /test check-dev
idc-jenkins-ci-tidb/mysql-test 3c6ee3f link true /test mysql-test
idc-jenkins-ci-tidb/check_dev_2 3c6ee3f link true /test check-dev2
idc-jenkins-ci-tidb/unit-test 3c6ee3f link true /test unit-test
idc-jenkins-ci-tidb/build 3c6ee3f 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 3c6ee3f 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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ 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