Repository navigation
fix(plan): sanitize non-finite plan stats (cherry-pick #24672) - #24682
Merged
XuPeng-SH merged 2 commits intoMay 28, 2026
Merged
Conversation
- [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring issue matrixorigin#24520 Cherry-pick PR matrixorigin#24643 to 4.0-dev. This PR prevents non-finite planner statistics from leaking into plan JSON and cost estimation paths by: - guarding stats ratio calculations against division by zero and non-finite results; - sanitizing non-finite float values before plan JSON marshaling; - clamping expression and join selectivity to the valid [0, 1] range; - clamping ANTI JOIN right-side selectivity before computing output rows; - adding regression coverage for zero stats, year(...) equality selectivity, NOT/JOIN propagation, ANTI JOIN, and JSON marshal sanitization. --------- Co-authored-by: XuPeng-SH <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
…py PhyPlan before sanitize - estimateExprSelectivity: clamp the cached and prefix_eq early returns so a non-finite cached value or a small-table (TableCnt<100) prefix_eq cannot leak selectivity > 1 past the final clamp. - calcSelectivityByMinMax/ForDecimal: a zero-width range (max==min) with a non-matching bound divides 0/0 -> NaN; return the low selectivity instead of leaking NaN that the caller would clamp to full-table selectivity. - marshalPlanHandler: deep-copy PhyPlan before Marshal so the in-place non-finite sanitizer cannot mutate the caller's live physical plan through the shared OperatorStats.BackgroundQueries (*plan.Query) pointers. - tests: assert plan JSON is parseable/non-empty with non-finite stats replaced, that Marshal does not mutate a shared PhyPlan, plus prefix_eq small-table, zero-width range, and concrete ANTI JOIN outcnt coverage. Co-Authored-By: Claude Opus 4.7 <[email protected]>
XuPeng-SH
approved these changes
May 28, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24520
What this PR does / why we need it:
Cherry-pick PR #24672 to 3.0-dev.
3.0-dev is affected by the same defect: optimizer stats can produce non-finite (
+Inf/NaN) selectivity via unchecked divisions inpkg/sql/plan/stats.go, which then breaks plan JSON marshaling on CN (serialize plan to json error: json: unsupported value: +Inf) and drops client connections under load.This PR prevents non-finite planner statistics from leaking into plan JSON and cost estimation paths by:
Conflicts were resolved to match 3.0-dev (e.g.
w.Statsaccessor naming,pb/planimport alias, and dropping the FUNCTION_SCAN IndexReaderParam path absent in 3.0-dev).