[SPARK-61002][SQL] CBO estimates an equi-join as empty when a join key has no min/max #60168
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 319 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.345
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #60168"
general
weight: 0.35
LuciferYang
What changes were proposed in this pull request?
With CBO enabled,
JoinEstimationestimates an equi-join as empty when a key has distinct and null counts but no min/max.ValueIntervalturns a missing min or max into aNullValueInterval, which is meant for a column holding only nulls and intersects nothing.This PR gives such a key an unknown range, as for a string key, so the join is estimated by distinct counts. Related changes:
ValueInterval.isIntersectedchecksNullValueIntervalfirst.computeByHistogramtrims both to the intersected min/max.Why are the changes needed?
A 0-row estimate lets the planner broadcast that side of a later join however large it is. SPARK-56485 fixed the same problem in
FilterEstimation.Such statistics come from:
UnionEstimation, which keeps the distinct and null counts of every column but min/max only for some types. For example, with all three tables analyzed andka boolean column,(SELECT FROM a1 UNION ALL SELECT FROM a2) u JOIN b ON u.k = b.kwas estimated at 0 rows and returns 500000.Does this PR introduce _any_ user-facing change?
With CBO enabled, these joins get a non-zero row estimate, and a join on a STRING or BINARY key holding only nulls gets a 0-row one, so the chosen join strategy or order can change. Query results do not change.
How was this patch tested?
New tests in
JoinEstimationSuite:Union;Each of them fails without this change.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5