← Back to Pull requests

[SPARK-61002][SQL] CBO estimates an equi-join as empty when a join key has no min/max #60168

Closed
unknown closed this pull request without merging on Nov 14, 2026 18:42 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 08:04 UTC
Author

What changes were proposed in this pull request?

With CBO enabled, JoinEstimation estimates an equi-join as empty when a key has distinct and null counts but no min/max. ValueInterval turns a missing min or max into a NullValueInterval, 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:

  • A key with no distinct values holds only nulls, STRING and BINARY keys included, and makes the join empty, also against a key whose range is unknown: ValueInterval.isIntersected checks NullValueInterval first.

  • When only one key has min/max, the joined keys take its range. The histogram of the other key may not cover that range, so it is not passed on.

  • Histograms are used only when both keys have min/max, because computeByHistogram trims 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:

  • a DSv2 source that reports distinct and null counts but no min/max;

  • 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 and k a boolean column, (SELECT FROM a1 UNION ALL SELECT FROM a2) u JOIN b ON u.k = b.k was 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:

  • a key with distinct and null counts but no min/max is estimated by distinct counts, and the joined keys take the other key's range, also in outer joins;

  • two such keys, with and without histograms;

  • keys with histograms are estimated by them only if both have min/max;

  • a key without min/max drops its histogram, so filters on it above the join use the joined min/max;

  • a boolean key coming out of a Union;

  • an INT or STRING key holding only nulls makes the join empty against a key without min/max, on either side, even if a source reports its min/max.
  • Each of them fails without this change.

    Was this patch authored or co-authored using generative AI tooling?

    Generated-by: Claude Opus 5.5

    Diff: 319 lines (+239 / -80) across 3 files Reviewer: LuciferYang Review duration: 12158m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%
    Repository