Repository navigation
Fix missing rows when GLOBAL IN is pushed down to a shard with a stale local replica - #126084
Conversation
…e local replica When the initiator's own replica of a shard lags beyond `max_replica_delay_for_distributed_queries`, the shard is read through `ReadFromRemote::addLazyPipe` (a `DelayedSource`). That path spliced the pushed-down filter inside the lambda with `addFilters(nullptr, ...)`, so `tryBuildAdditionalFilterAST` skipped its GLOBAL IN branch and shipped the raw `globalIn` subquery. The remote replica then evaluated the subquery against its own table and pre-filtered with a different set; the initiator's filter cannot restore the rows it dropped. The `nullptr` was chosen because the lambda runs after the sets are built, so a temporary table attached there would be empty. The fix splices at pipeline-build time instead, with the real external tables, exactly as `addPipe` does, into a copy of the shard query used only by the lambda's remote branch. The `_data_*` table is then attached to the set before it is built and sent with the query; the local fallback keeps the unmodified shard query. `conjunctsLeftOutOfRemoteQuery` keeps calling the converter with `nullptr`, which it relies on to predict the parallel replicas splice. The new integration test makes the local replica stale with `SYSTEM STOP FETCHES` and gives each node a different `ids` table. It fails on master and on 26.8.18.2 with `['1'] == ['1', '4']`. `serialize_query_plan` is pinned to 0 because the integration jobs enable it, and then the shard runs the serialized plan instead of the AST. Closes ClickHouse#120979 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The row check alone cannot tell the shard using the initiator's set from a pushdown that silently declined: the initiator's own filter produces the same rows in both cases. Pin `allow_push_predicate_ast_for_distributed_subqueries` and assert that the secondary query on the fresh replica carries `globalIn(` / `globalNotIn(`. With the setting at 0 the rows still match and the new check fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261015-152132 |
|
Workflow [PR], commit [4799c6e] Summary: ✅
AI ReviewSummaryPR #126084, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
|
cc @KochetovNicolai @nickitat, could you review this? On a shard whose local replica is stale, |
4e9c824
Backport #126084 to 26.10: Fix missing rows when `GLOBAL IN` is pushed down to a shard with a stale local replica
Closes: #120979
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed missing rows in a query over a
Distributedtable whoseGLOBAL INorGLOBAL NOT INfilter is pushed down from an outer query (for exampleSELECT x FROM (SELECT * FROM dist) WHERE x GLOBAL IN (SELECT y FROM t)) when the local replica of a shard lags behindmax_replica_delay_for_distributed_queriesand the shard is read from another replica. The other replica now receives the initiator's set instead of evaluating the subquery against its own data. Closes #120979.Description
On 26.8 (measured on the official 26.8.18.2 build),
SELECT x FROM (SELECT * FROM dist) WHERE x GLOBAL IN (SELECT y FROM ids)returns fewer rows, with no error, when the initiator's own replica of a shard lags beyondmax_replica_delay_for_distributed_queries. All other settings are at their defaults.Root cause: a stale local replica makes the shard go through the lazy
DelayedSourcepath (ReadFromRemote::addLazyPipe). That path spliced the pushed-down filter inside the lambda with no external tables, sotryBuildAdditionalFilterASTkept the rawGLOBAL INsubquery and the other replica evaluated it against its ownids. The initiator's filter can only remove rows, so the rows the shard dropped were lost. The eager path (addPipe) splices at pipeline-build time with the external tables, so the_data_*temporary table is attached to the set before the set is built and is sent with the query.Change:
addLazyPipenow splices the same way, at pipeline-build time, into a copy of the shard query used only by the lambda's remote branch; the local fallback keeps the unmodified query. The pushdown is kept: the shard now receivesglobalIn(x, _data_...)instead of the subquery.Validation: a new test in
test_delayed_replica_failovermakes the local replica stale withSYSTEM STOP FETCHESand gives each node a differentidstable; it also checks in the other replica'squery_logthat the pushed-down filter arrived. It fails on master and on 26.8.18.2 with['1'] == ['1', '4'], and passes with the fix (50 of 50 runs, plus the module 3 times with the existing test interleaved). The lazy-source andGLOBAL INstateless tests pass 10 times each with randomized settings.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126084]
Version info
26.11.1.175-master(included in26.11and later)