Skip to content

parser: support NDVRATE analyze syntax#67608

Merged
ti-chi-bot[bot] merged 2 commits intopingcap:masterfrom
0xPoe:parser-ndvrate-syntax
Apr 11, 2026
Merged

parser: support NDVRATE analyze syntax#67608
ti-chi-bot[bot] merged 2 commits intopingcap:masterfrom
0xPoe:parser-ndvrate-syntax

Conversation

@0xPoe
Copy link
Copy Markdown
Member

@0xPoe 0xPoe commented Apr 8, 2026

What problem does this PR solve?

Issue Number: ref #67449

Problem Summary:
Add parser support for NDVRATE in ANALYZE TABLE ... WITH ... syntax.

What changed and how does it work?

  • Add NDVRATE as an analyze option token and AST enum.
  • Extend the analyze option grammar so ANALYZE TABLE t WITH 0.05 NDVRATE 0.00001 SAMPLERATE parses and restores canonically.
  • Regenerate parser artifacts and add parser tests.

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 the NDVRATE option in ANALYZE TABLE ... WITH, allowing statements like WITH 0.05 NDVRATE and combinations such as WITH 0.05 NDVRATE, 0.00001 SAMPLERATE.
  • Tests
    • Parser/restore tests updated to cover NDVRATE parsing and restoration.

@ti-chi-bot ti-chi-bot Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Apr 8, 2026
@pantheon-ai
Copy link
Copy Markdown

pantheon-ai Bot commented Apr 8, 2026

@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.

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 8, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 70b53e9b-de89-40e4-a12e-0508bcecb139

📥 Commits

Reviewing files that changed from the base of the PR and between a9bd43c and 1b4aa53.

📒 Files selected for processing (7)
  • pkg/parser/ast/stats.go
  • pkg/parser/keywords.go
  • pkg/parser/keywords_test.go
  • pkg/parser/misc.go
  • pkg/parser/parser.go
  • pkg/parser/parser.y
  • pkg/parser/parser_test.go
✅ Files skipped from review due to trivial changes (4)
  • pkg/parser/misc.go
  • pkg/parser/keywords.go
  • pkg/parser/keywords_test.go
  • pkg/parser/parser_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/parser/parser.y

📝 Walkthrough

Walkthrough

Adds a new NDVRATE analyze option to the SQL parser: introduces a keyword token, maps it in the lexer, extends parser grammar to accept NDVRATE in ANALYZE TABLE ... WITH ..., updates AST enum/string, and adds parser tests.

Changes

Cohort / File(s) Summary
AST / Analyze options
pkg/parser/ast/stats.go
Added exported enum AnalyzeOptNDVRate and registered "NDVRATE" in AnalyzeOptionString.
Keyword registry & tests
pkg/parser/keywords.go, pkg/parser/keywords_test.go
Added NDVRATE to Keywords and updated keywords length assertion (677 → 678).
Tokenizer mapping
pkg/parser/misc.go
Mapped "NDVRATE" to token ndvRate in tokenMap.
Parser grammar & tests
pkg/parser/parser.y, pkg/parser/parser_test.go
Added NDVRATE to TiDB keywords, extended AnalyzeOptionList to allow non-comma appends, and implemented rule parsing NumLiteral "NDVRATE"; added tests asserting parsing/restoration of NDVRATE cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size/L, ok-to-test

Suggested reviewers

  • AilinKid
  • guo-shaoge

Poem

🐇 I hopped through tokens, soft and light,
NDVRATE nested snug and bright.
Numbers dance where parsers play,
Tables learned a new-fit way,
Hooray — the stats will now take flight! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding parser support for NDVRATE in the ANALYZE syntax, which aligns with the comprehensive changes across parser files.
Description check ✅ Passed The description includes required sections: issue reference (ref #67449), problem summary, what changed and how, completed test checklist, affected areas, and release note. All mandatory information is present and well-documented.

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

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

@0xPoe
Copy link
Copy Markdown
Member Author

0xPoe commented Apr 8, 2026

/retest

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.2706%. Comparing base (de09871) to head (1b4aa53).
⚠️ Report is 12 commits behind head on master.

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     
Flag Coverage Δ
integration 43.7686% <ø> (+9.4289%) ⬆️
unit 76.8032% <ø> (+0.4699%) ⬆️

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

Components Coverage Δ
dumpling 61.5065% <ø> (+0.0901%) ⬆️
parser ∅ <ø> (∅)
br 49.9100% <ø> (-10.5212%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

🧹 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). NDVRATE should 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

📥 Commits

Reviewing files that changed from the base of the PR and between 078b070 and a9bd43c.

📒 Files selected for processing (7)
  • pkg/parser/ast/stats.go
  • pkg/parser/keywords.go
  • pkg/parser/keywords_test.go
  • pkg/parser/misc.go
  • pkg/parser/parser.go
  • pkg/parser/parser.y
  • pkg/parser/parser_test.go

Comment thread pkg/parser/ast/stats.go
Copy link
Copy Markdown
Member Author

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

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

🔢 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

/cc @terry1purcell @henrybw

@ti-chi-bot ti-chi-bot Bot requested review from henrybw and terry1purcell April 8, 2026 11:45
@terry1purcell terry1purcell requested a review from Copilot April 8, 2026 17:28
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 8, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 NDVRATE as a parser keyword/token and wired it into the lexer keyword map.
  • Extended the ANALYZE ... WITH option grammar and AST option enum/string mapping to support NDVRATE.
  • Added parser test cases covering NDVRATE alone and combined with SAMPLERATE.

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.

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

ti-chi-bot Bot commented Apr 9, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-04-08 17:29:45.847490566 +0000 UTC m=+977391.052850613: ☑️ agreed by terry1purcell.
  • 2026-04-09 00:50:33.721266703 +0000 UTC m=+1003838.926626760: ☑️ agreed by henrybw.

@0xPoe 0xPoe force-pushed the parser-ndvrate-syntax branch from a9bd43c to 1b4aa53 Compare April 9, 2026 08:05
Copy link
Copy Markdown
Collaborator

@Benjamin2037 Benjamin2037 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 Apr 10, 2026

[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

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 Apr 10, 2026
@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

4 similar comments
@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

13 similar comments
@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 10, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@0xTars
Copy link
Copy Markdown

0xTars commented Apr 11, 2026

/retest

@ti-chi-bot ti-chi-bot Bot merged commit 40020bf into pingcap:master Apr 11, 2026
35 checks passed
premal pushed a commit to premal/tidb that referenced this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm 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.

6 participants