parser: support NDVRATE analyze syntax#67608
Conversation
|
@0xPoe I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details. ⏳ This process typically takes 10-30 minutes depending on the complexity of the changes. ℹ️ Learn more details on Pantheon AI. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
/retest |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #67608 +/- ##
================================================
+ Coverage 77.5839% 78.2706% +0.6867%
================================================
Files 1981 1974 -7
Lines 547950 549836 +1886
================================================
+ Hits 425121 430360 +5239
+ Misses 122019 119040 -2979
+ Partials 810 436 -374
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/parser/misc.go (1)
729-729: Token map entry is out of alphabetical order.The comment at line 157 says "Please try to keep the map in alphabetical order." The entry
"NDVRATE"is currently placed after"S3", but it should be in the N-section (around lines 574-599, near entries like"NAMES","NATIONAL","NATURAL", etc.).📝 Suggested placement
Move the entry from line 729 to the N-section, between
"NTH_VALUE"and"NTILE"entries (or nearby based on exact alphabetical position).NDVRATEshould come after"NCHAR"and before"NEVER"alphabetically."NCHAR": ncharType, + "NDVRATE": ndvRate, "NEVER": never,And remove from current location:
"S3": s3, - "NDVRATE": ndvRate, "SAMPLES": samples,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/parser/misc.go` at line 729, The token map entry "NDVRATE": ndvRate is out of alphabetical order; open the token map in pkg/parser/misc.go (the map literal containing entries like "S3", "NAMES", "NATIONAL", "NTH_VALUE", "NTILE", etc.), remove the "NDVRATE": ndvRate entry from its current S-section placement and insert it into the N-section in the correct alphabetical position (e.g., after "NTH_VALUE"/"NCHAR" and before "NTILE"/"NEVER") so the entire map remains alphabetically ordered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/parser/ast/stats.go`:
- Line 61: The new AnalyzeOptNDVRate token is added to the parser but not wired
into planning/execution; update the analyzeOptionLimit map to include
AnalyzeOptNDVRate with appropriate bounds, add a default value in
analyzeOptionDefaultV2 for NDVRATE, extend handleAnalyzeOptions to recognize and
validate NDVRATE (use the same validation flow as other numeric analyze
options), and modify the executor code that persists/loads statistics metadata
to store and retrieve the NDVRATE value so it flows from parser → planbuilder →
executor; if this PR intentionally only changes the parser, add an explicit
comment in the PR description and open a follow-up issue linking
AnalyzeOptNDVRate to the missing changes instead of implementing them now.
---
Nitpick comments:
In `@pkg/parser/misc.go`:
- Line 729: The token map entry "NDVRATE": ndvRate is out of alphabetical order;
open the token map in pkg/parser/misc.go (the map literal containing entries
like "S3", "NAMES", "NATIONAL", "NTH_VALUE", "NTILE", etc.), remove the
"NDVRATE": ndvRate entry from its current S-section placement and insert it into
the N-section in the correct alphabetical position (e.g., after
"NTH_VALUE"/"NCHAR" and before "NTILE"/"NEVER") so the entire map remains
alphabetically ordered.
🪄 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: c4a4ca6b-b461-4498-befc-9eb3adf094b7
📒 Files selected for processing (7)
pkg/parser/ast/stats.gopkg/parser/keywords.gopkg/parser/keywords_test.gopkg/parser/misc.gopkg/parser/parser.gopkg/parser/parser.ypkg/parser/parser_test.go
0xPoe
left a comment
There was a problem hiding this comment.
🔢 Self-check (PR reviewed by myself and ready for feedback)
-
Code compiles successfully
-
Unit tests added
-
No AI-generated elegant nonsense in PR.
-
Bazel files updated
-
Comments added where necessary
-
PR title and description updated
-
Documentation PR created (or confirmed not needed)
-
PR size is reasonable
There was a problem hiding this comment.
Pull request overview
This PR extends TiDB’s SQL parser to recognize a new NDVRATE analyze option within ANALYZE TABLE ... WITH ..., enabling syntax like ANALYZE TABLE t WITH 0.05 NDVRATE 0.00001 SAMPLERATE and ensuring canonical restoration output.
Changes:
- Added
NDVRATEas a parser keyword/token and wired it into the lexer keyword map. - Extended the
ANALYZE ... WITHoption grammar and AST option enum/string mapping to supportNDVRATE. - Added parser test cases covering
NDVRATEalone and combined withSAMPLERATE.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/parser/parser.y | Adds NDVRATE token/keyword and grammar support for NDVRATE analyze options (including whitespace-separated option lists). |
| pkg/parser/parser_test.go | Adds parsing/restoration test coverage for NDVRATE analyze options. |
| pkg/parser/misc.go | Registers NDVRATE in the lexer token map. |
| pkg/parser/keywords.go | Adds NDVRATE to the keyword list (non-reserved, TiDB section). |
| pkg/parser/keywords_test.go | Updates expected keyword count after adding NDVRATE. |
| pkg/parser/ast/stats.go | Adds AnalyzeOptNDVRate and maps it to the NDVRATE restore string. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
[LGTM Timeline notifier]Timeline:
|
a9bd43c to
1b4aa53
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Benjamin2037, henrybw, terry1purcell The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
4 similar comments
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
13 similar comments
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
What problem does this PR solve?
Issue Number: ref #67449
Problem Summary:
Add parser support for
NDVRATEinANALYZE TABLE ... WITH ...syntax.What changed and how does it work?
NDVRATEas an analyze option token and AST enum.ANALYZE TABLE t WITH 0.05 NDVRATE 0.00001 SAMPLERATEparses and restores canonically.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit
WITH 0.05 NDVRATEand combinations such asWITH 0.05 NDVRATE, 0.00001 SAMPLERATE.