Repository navigation
Implement clone for the query result cache steps - #130375
Conversation
Split out of #102192. With `query_cache_for_subqueries = 1` an `IN` subquery plan contains `StreamInQueryResultCacheStep` (write path) or is replaced by `ReadFromQueryResultCacheStep` (cache hit). Neither implemented `clone`, so `FutureSetFromSubquery::buildOrderedSetInplace` took the destructive fallback (see #107924), where a silent in-place build failure still leads to the "Not-ready Set is passed as the second argument" exception. - `StreamInQueryResultCacheStep::clone` gives the clone its own copy of the `QueryResultCacheWriter`. - The `QueryResultCacheWriter` copy now carries over `query_start_time`, so `query_cache_min_query_duration` is not measured from the clone point. On the successful in-place build path the copy is the only writer that is finalized. - `ReadFromQueryResultCacheStep` keeps its `SourceFromChunks` and clones them via the new `SourceFromChunks::clone`, which shares the immutable columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [1532610] Summary: ✅
AI ReviewSummaryAdds cloning for query result cache plan steps so cached Findings
Tests
Missing context / blind spots
Final VerdictStatus: |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes10 object files changed (+43.72 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units24 translation units recompiled, 174 s compile time in total, 24 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
🕵 The failures in |
…in Fast test With `use_index_for_in_with_subqueries = 1` the set for the `IN` subquery is built speculatively during primary key analysis by `FutureSetFromSubquery::buildOrderedSetInplace`. That build distributes only a clone of the set source, and `StreamInQueryResultCacheStep` has no `clone` yet (see #130375), so it fell back to running the original source locally and wrote the cache entry, making the "distributed" case report 1 instead of 0. The test is about the set source conversion of the deferred build, so disable the speculative build. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130377&sha=latest&name_0=PR&name_1=Fast%20test PR: #130377 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The only red check on |
|
🕵 The only failure on |
| -- analysis; the preserved (cloned) source lets the deferred build recover and produce the correct | ||
| -- result. The subquery matches k in [0, 10), so the outer count is 10. | ||
| SYSTEM ENABLE FAILPOINT prepared_sets_build_ordered_set_inplace_fail; | ||
| SELECT count() FROM t_qrc_in WHERE k IN (SELECT k FROM t_qrc_in WHERE k < 10); |
There was a problem hiding this comment.
[Major] The failure injection is conditional on the functionality this test is meant to guard. CreatingSetsTransform::generate checks prepared_sets_build_ordered_set_inplace_fail only when recoverable_build is true, whereas the non-clonable fallback in FutureSetFromSubquery::buildOrderedSetInplace passes false. Without the two new clone overrides, both queries therefore skip the injected failure, build their sets successfully, and satisfy the existing result and cache-hit assertions. This leaves the main recovery behavior without a regression test that detects its removal.
Please assert that a speculative attempt actually failed and a subsequent attempt rebuilt the set, for both cache paths. For the write case, QueryCacheWrittenRows can distinguish buffering the subquery once from buffering it in both attempts. The relevant case should fail when its clone override is removed.
There was a problem hiding this comment.
The bug is already fixed, but we can keep the test just in case.
| /// writer that is ever finalized - and restarting the timer there would make cache eligibility depend | ||
| /// on the plan shape: a subquery would silently stop populating the cache just because its plan became | ||
| /// clonable. | ||
| , query_start_time(other.query_start_time) |
There was a problem hiding this comment.
Amazing finding!
…l replicas The subquery query result cache is not used with plan-based parallel replicas, ClickHouse#131463. `04648` and `04652` came with ClickHouse#130375, after the other cache tests were pinned in ClickHouse#131464. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #102192
Related: #107924
Split out of #102192 (part 3 of 6).
With
query_cache_for_subqueries = 1anINsubquery plan containsStreamInQueryResultCacheStep(write path) or is replaced byReadFromQueryResultCacheStep(cache hit). Neither implementedclone, soFutureSetFromSubquery::buildOrderedSetInplacetook the destructive fallback (see #107924), where a silent in-place build failure still leads to the "Not-ready Set is passed as the second argument" exception.StreamInQueryResultCacheStep::clonegives the clone its own copy of theQueryResultCacheWriter(a shared writer would buffer the rows twice into one entry).QueryResultCacheWritercopy now carries overquery_start_time. On the successful in-place build path the copy is the only writer that is finalized, so otherwisequery_cache_min_query_durationwould be measured from the clone point.ReadFromQueryResultCacheStepkeeps itsSourceFromChunksand clones them with the newSourceFromChunks::clone, which shares the immutable columns.04648_not_ready_set_with_query_result_cache_subquery(write and read path),04652_query_result_cache_subquery_clone_min_query_duration,04653_query_result_cache_subquery_clone_skip_insert.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
INsubqueries cached withquery_cache_for_subqueriescan now recover when the speculative set build for primary key analysis stops early, instead of failing with "Not-ready Set".🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130375]
Version info
26.11.1.2304-master(included in26.11and later)