SOLR-18541: CombinedQueryComponent.mergeIds gives wrong numFound, approximateTotalHits and numFoundExact #5117
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
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.368
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5117"
general
weight: 0.35
nick-boss-tech
🤖 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'snumFoundandapproximateTotalHitsare 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
approximateTotalHitsfallback adds the shard's own count (head, line 407).A shard that errored also clears
numFoundExact, because its hits are missing too.The
numFoundandnumFoundExactrules for several sub-queries come from #5172, now on main. This branch rebases onto it and no longer clearsnumFoundExactfor 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.
CombinedQueryComponentMergeTotalsTest10 of 10 at headc148e7924f06160dc38ddf30d17a204bd57897a2, verified 2026-10-24. On main79b23df58dwith this test file, 7 of 10 fail:scoreOnlyPartialShardWithoutPerQueryListIsSkipped(theNullPointerException),erroredShardClearsExactness,skippedPartialShardContributesNothing,fallbackUsesEachShardsOwnCount,skippedPartialShardWithHitsClearsExactness,skippedPartialShardWithoutCountClearsExactnessandskippedPartialShardWithoutHitsClearsExactness.CombinedQueryComponentTest8 of 8 andDistributedCombinedQueryComponentTest3 of 3 pass at the same head.Limits
docList.get(queryIndex)(head, line 341) then throwsIndexOutOfBoundsException. This change does not touch that access.NullPointerException, as on main. The guard covers only partial shards.QueryComponent.mergeIdshas the same leak: it adds a partial shard'snumFoundbefore its skip. This branch does not change it. I can open a follow-up PR for it on request.Changelog: changelog/unreleased/SOLR-18541-combined-query-merge-totals.yml
AI-generated description. Nick Shanin directed the work and takes responsibility for this contribution.