← Back to Pull requests

SOLR-18541: CombinedQueryComponent.mergeIds gives wrong numFound, approximateTotalHits and numFoundExact #5117

Closed
unknown closed this pull request without merging on Oct 27, 2026 20:33 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 05:13 UTC
Author

🤖 AI text below 🤖 (posted on behalf of Nick Shanin)

https://issues.apache.org/jira/browse/SOLR-18541

What happens today

A partial shard with no per-query entry makes the merge throw a NullPointerException, and a partial shard's hits still reach the totals. With a score-only sort, the merge skips a partial shard only when it sent sort values. Otherwise the document loop dereferences the missing list (merge-base, line 411). Also, a partial shard's numFound and approximateTotalHits are added before the skip is tested, so a skipped shard still inflates the totals.

What this change does

A skipped shard adds nothing to the totals, and its missing hits make the merged count inexact. The skip is decided before any totals are added (head, lines 392 to 397). A partial shard with no per-query entry is skipped the same way. The approximateTotalHits fallback adds the shard's own count (head, line 407).

A shard that errored also clears numFoundExact, because its hits are missing too.

The numFound and numFoundExact rules for several sub-queries come from #5172, now on main. This branch rebases onto it and no longer clears numFoundExact for every multi-sub-query merge. A merge of two sub-queries with overlapping documents reports the distinct count.

Proof

The skip, fallback and errored-shard tests fail on main and pass here.

  • CombinedQueryComponentMergeTotalsTest 10 of 10 at head c148e7924f06160dc38ddf30d17a204bd57897a2, verified 2026-10-24. On main 79b23df58d with this test file, 7 of 10 fail: scoreOnlyPartialShardWithoutPerQueryListIsSkipped (the NullPointerException), erroredShardClearsExactness, skippedPartialShardContributesNothing, fallbackUsesEachShardsOwnCount, skippedPartialShardWithHitsClearsExactness, skippedPartialShardWithoutCountClearsExactness and skippedPartialShardWithoutHitsClearsExactness.

  • CombinedQueryComponentTest 8 of 8 and DistributedCombinedQueryComponentTest 3 of 3 pass at the same head.
  • Limits

  • A real timeAllowed exit after the first sub-query can leave a shorter per-query list. The unchecked docList.get(queryIndex) (head, line 341) then throws IndexOutOfBoundsException. This change does not touch that access.

  • A non-partial shard whose per-query entry is malformed still fails with a NullPointerException, as on main. The guard covers only partial shards.

  • QueryComponent.mergeIds has the same leak: it adds a partial shard's numFound before its skip. This branch does not change it. I can open a follow-up PR for it on request.

  • A timed-out score-only shard was not run end to end; the test builds that response by hand.
  • Changelog: changelog/unreleased/SOLR-18541-combined-query-merge-totals.yml

    AI-generated description. Nick Shanin directed the work and takes responsibility for this contribution.

    Diff: 467 lines (+350 / -117) across 5 files Reviewer: nick-boss-tech Review duration: 21079m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.46) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 467 lines diff across 5 files
    0.46
    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%
    56%
    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.368
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5117"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 19.7% · Safe to merge
    19.7%
    Repository