Skip to content

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

Merged
ti-chi-bot[bot] merged 1 commit into
pingcap:release-8.5from
YangKeao:cherry-pick-63448-release-8.5
Jun 3, 2026
Merged

parser: modify parser to support partial index (#63448)#68823
ti-chi-bot[bot] merged 1 commit into
pingcap:release-8.5from
YangKeao:cherry-pick-63448-release-8.5

Conversation

@YangKeao
Copy link
Copy Markdown
Member

@YangKeao YangKeao commented Jun 1, 2026

(cherry picked from #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 indexes with WHERE conditions in index definitions. Partial indexes can now be created and modified via CREATE TABLE, CREATE INDEX, and ALTER TABLE statements, with predicates properly preserved during SQL restoration.

Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
(cherry picked from commit 66ba465)
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/cherry-pick-not-approved size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds parser support for partial indexes, allowing WHERE predicates in index definitions. The IndexOption AST node is extended with a Condition field and restoration logic, while the parser grammar is updated to recognize WHERE clauses and merge conditions across CREATE TABLE, CREATE INDEX, and ALTER TABLE statements.

Changes

Partial Index Parsing

Layer / File(s) Summary
IndexOption Condition field and restoration
pkg/parser/ast/ddl.go
IndexOption struct adds an optional Condition field (JSON-excluded) for partial-index predicates. IsEmpty() now treats Condition != nil as non-empty. Restore() outputs the WHERE clause and restores the condition expression when present.
Parser grammar for partial indexes and validation
pkg/parser/parser.y, pkg/parser/parser_test.go
Parser grammar recognizes WHERE Expression in IndexOption productions and merges Condition values in IndexOptionList. Test cases validate partial index parsing for CREATE TABLE, CREATE INDEX, and ALTER TABLE ... ADD INDEX with predicate preservation.

Sequence Diagram(s)

The changes introduce a straightforward grammar extension without multi-component interactions warranting a sequence diagram.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 With whiskers twitching and a hop-skip-bound,
We parse the WHERE clauses, conditions found!
Partial indexes now in every query line,
From CREATE to ALTER, the grammar's divine. ✨

🚥 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 summarizes the main change: parser modifications to support partial index functionality, which matches the primary objective.
Description check ✅ Passed The description follows the template structure, includes the linked issue number (#63447), describes the changes (parser support for partial index grammar), and documents that unit tests were added.
Linked Issues check ✅ Passed The code changes fully implement the parser requirements for partial indexes: IndexOption struct supports WHERE condition, parser.y handles WHERE clause in index definitions, and unit tests verify the three SQL grammars (CREATE TABLE, CREATE INDEX, ALTER TABLE).
Out of Scope Changes check ✅ Passed All code changes are directly related to implementing partial index parser support as specified in issue #63447; no unrelated modifications are present.

✏️ 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/parser/ast/ddl.go (1)

841-848: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: Accept() must visit the Condition field.

The Accept() method does not visit the Condition field when it is non-nil. This breaks AST traversal because visitors will never see partial index predicates, which could cause failures in query optimization, validation, or transformations.

Following the pattern used elsewhere in this file (e.g., ColumnOption.Accept() at lines 684-698), the method must visit the Condition when it is not nil.

🔧 Proposed fix to visit Condition field
 // Accept implements Node Accept interface.
 func (n *IndexOption) Accept(v Visitor) (Node, bool) {
 	newNode, skipChildren := v.Enter(n)
 	if skipChildren {
 		return v.Leave(newNode)
 	}
 	n = newNode.(*IndexOption)
+	if n.Condition != nil {
+		node, ok := n.Condition.Accept(v)
+		if !ok {
+			return n, false
+		}
+		n.Condition = node.(ExprNode)
+	}
 	return v.Leave(n)
 }
🤖 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 841 - 848, The IndexOption.Accept method
currently skips visiting its Condition field; update IndexOption.Accept to
follow the ColumnOption.Accept pattern: after calling v.Enter and casting
newNode to *IndexOption, if n.Condition != nil call n.Condition.Accept(v)
(handling returned node and ok), assign the potentially replaced node back to
n.Condition, then continue to return v.Leave(n); ensure you propagate the
skip/ok semantics the same way ColumnOption.Accept does so visitors see partial
index predicates.
pkg/parser/parser.y (1)

6616-6640: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Limit WHERE to supported partial-index productions.

Putting WHERE into the shared IndexOption rule makes it legal anywhere IndexOptionList is reused, so the parser now accepts unsupported forms like PRIMARY KEY (...) WHERE .... It also accepts repeated predicates (... WHERE a > 1 WHERE b > 2) and silently keeps the last one via the merge logic. This should be threaded through only the intended index-definition productions and rejected if specified more than once.

Also applies to: 6696-6701

🤖 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 6616 - 6640, The parser currently accepts
and merges WHERE clauses from the shared IndexOption/IndexOptionList productions
(IndexOptionList, IndexOption, Condition), enabling illegal uses like PRIMARY
KEY (...) WHERE ... and repeated WHEREs; to fix this, remove handling/merging of
Condition from the shared IndexOption/IndexOptionList rule and instead thread
Condition only into the specific index-definition productions that allow partial
indexes (move the WHERE parsing and assignment out of
IndexOption/IndexOptionList into the index-definition grammar rules), and add a
check in those specific productions to reject multiple WHERE clauses (or fail
the parse) so repeated predicates are not silently overwritten; also apply the
same change to the other occurrence around the 6696-6701 region where Condition
is currently merged.
🤖 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.

Outside diff comments:
In `@pkg/parser/ast/ddl.go`:
- Around line 841-848: The IndexOption.Accept method currently skips visiting
its Condition field; update IndexOption.Accept to follow the ColumnOption.Accept
pattern: after calling v.Enter and casting newNode to *IndexOption, if
n.Condition != nil call n.Condition.Accept(v) (handling returned node and ok),
assign the potentially replaced node back to n.Condition, then continue to
return v.Leave(n); ensure you propagate the skip/ok semantics the same way
ColumnOption.Accept does so visitors see partial index predicates.

In `@pkg/parser/parser.y`:
- Around line 6616-6640: The parser currently accepts and merges WHERE clauses
from the shared IndexOption/IndexOptionList productions (IndexOptionList,
IndexOption, Condition), enabling illegal uses like PRIMARY KEY (...) WHERE ...
and repeated WHEREs; to fix this, remove handling/merging of Condition from the
shared IndexOption/IndexOptionList rule and instead thread Condition only into
the specific index-definition productions that allow partial indexes (move the
WHERE parsing and assignment out of IndexOption/IndexOptionList into the
index-definition grammar rules), and add a check in those specific productions
to reject multiple WHERE clauses (or fail the parse) so repeated predicates are
not silently overwritten; also apply the same change to the other occurrence
around the 6696-6701 region where Condition is currently merged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 50370752-5039-4ed6-827e-4f7e4d11e983

📥 Commits

Reviewing files that changed from the base of the PR and between 789c7c4 and f518d33.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release-8.5@789c7c4). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-8.5     #68823   +/-   ##
================================================
  Coverage               ?   55.8553%           
================================================
  Files                  ?       1824           
  Lines                  ?     663616           
  Branches               ?          0           
================================================
  Hits                   ?     370665           
  Misses                 ?     266074           
  Partials               ?      26877           
Flag Coverage Δ
integration 39.0564% <0.0000%> (?)
unit 65.7260% <45.4545%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 55.3108% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 56.6686% <0.0000%> (?)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 1, 2026
@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 1, 2026
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 1, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-06-01 05:20:46.580823522 +0000 UTC m=+159747.651140912: ☑️ agreed by winoros.
  • 2026-06-01 06:42:49.848897336 +0000 UTC m=+164670.919214726: ☑️ agreed by wjhuang2016.

@YangKeao
Copy link
Copy Markdown
Member Author

YangKeao commented Jun 1, 2026

/retest

@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
@YangKeao
Copy link
Copy Markdown
Member Author

YangKeao commented Jun 2, 2026

/retest

@YangKeao YangKeao added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Jun 2, 2026
Copy link
Copy Markdown
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Jun 3, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, terry1purcell, winoros, wjhuang2016, yudongusa

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 the approved label Jun 3, 2026
@YangKeao
Copy link
Copy Markdown
Member Author

YangKeao commented Jun 3, 2026

/retest

1 similar comment
@YangKeao
Copy link
Copy Markdown
Member Author

YangKeao commented Jun 3, 2026

/retest

@ti-chi-bot ti-chi-bot Bot merged commit 2fce0f9 into pingcap:release-8.5 Jun 3, 2026
20 checks passed
@ti-chi-bot
Copy link
Copy Markdown
Member

In response to a cherrypick label: base branch (release-8.5) needs to differ from target branch (release-8.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants