Skip to content

Preserve non-clonable sources for deferred set builds - #114849

Closed
alexey-milovidov wants to merge 7 commits into
masterfrom
fix-remote-in-subquery-unready-set
Closed

alexey-milovidov wants to merge 7 commits into
masterfrom
fix-remote-in-subquery-unready-set

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

Closes: #107619
Related: #107619 (comment)

The speculative ordered-set build used for index analysis consumed non-clonable source plans before it knew whether the set was complete. If a ReadFromRemote pipeline stopped on an unavailable shard before Set::finishInsert, the deferred build had no source left and FunctionIn received a not-ready set.

Preserve non-clonable local sources by skipping the speculative index optimization and letting DelayedCreatingSetsStep perform the authoritative build. The regression test uses the deterministic five-part test_unavailable_shard reproducer from the linked issue comment and verifies that ALL_CONNECTION_TRIES_FAILED propagates normally.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix queries with an IN subquery over unavailable remote shards potentially raising the Not-ready Set is passed as the second argument logical exception instead of the underlying connection exception.

`FutureSetFromSubquery::buildOrderedSetInplace` used to consume the only source plan when `QueryPlan::clone` was not supported. If the speculative pipeline stopped before `Set::finishInsert`, the deferred build could not create the set and `FunctionIn` received a not-ready set.

Skip the speculative index optimization for non-clonable local sources and preserve the plan for `DelayedCreatingSetsStep`. Add a deterministic regression using `ReadFromRemote` with an unavailable shard.

#107619 (comment)
@clickhouse-gh

clickhouse-gh Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7af90eb]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
03302_analyzer_distributed_filter_push_down FAIL cidb
01064_incremental_streaming_from_2_src_with_feedback FAIL cidb
02859_replicated_db_name_zookeeper FAIL cidb
01700_system_zookeeper_path_in FAIL cidb
03928_materialized_cte_index FAIL cidb
03928_materialized_cte_index_2 FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 14, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 14, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Closing as already integrated: 702dd12854e9 (Preserve non-clonable sources for deferred set builds) is an ancestor of current master. The stale CI run also shows the bugfix-validation check cannot distinguish this regression from master.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

702dd12 (Preserve non-clonable sources for deferred set builds) is an ancestor of current master

No?

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 You are right. I fetched the current refs and verified that git merge-base --is-ancestor 702dd12854e9 origin/master returns nonzero; only the PR branch contains this commit. My earlier conclusion was incorrect—sorry. The PR is open again and the new CI run should proceed.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the unrelated Fast test failures in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114849&sha=aa0e8e9328e409480f5300cfd97f0a44d1145bc7&name_0=PR&name_1=Fast%20test and provide fixes in separate PRs if they are still reproducible on current master. The failures are 01700_system_zookeeper_path_in, 03302_analyzer_distributed_filter_push_down, 03928_materialized_cte_index, 02859_replicated_db_name_zookeeper, and 01064_incremental_streaming_from_2_src_with_feedback.

@groeneai

Copy link
Copy Markdown
Collaborator

These five are not unrelated: all of them are caused by this PR, and none of them reproduces on current master. So there is nothing to fix in a separate PR.

Mechanism. The new return nullptr in the NOT_IMPLEMENTED handler of FutureSetFromSubquery::buildOrderedSetInplace (PreparedSets.cpp:555-560, still present at 7af90eb) does more than preserve the source. buildOrderedSetInplace returning nullptr means "no set available for index analysis", so for every non-clonable source the set is no longer built in place at all. Before this PR the destructive fallback still produced an ordered set, so primary key analysis worked. Now the index is silently skipped. Your own comment edit documents the intent, but the removed fallback also removed the index build that these tests assert on.

Proof, both directions. I applied only that one line on top of pristine master (5c9f28ed5a2c), changing nothing else:

  • 03928_materialized_cte_index - pristine master: PASS, output matches the reference. Master + that one line: Code: 277 ... Primary key (x) is not used and setting 'force_primary_key' is set. (INDEX_NOT_USED), identical to the report.
  • 01064_incremental_streaming_from_2_src_with_feedback - pristine master: PASS. Master + that one line: Code: 158 ... max rows: 7.12 thousand, current rows: 50.00 thousand (TOO_MANY_ROWS), the same numbers as the report. That test says at line 3 that it deliberately asserts read-row counts, so the lost index shows up as reading 50k instead of 7.12k rows.

The MATERIALIZED CTE shape reaches this exactly as your comment describes: its source plan holds a DelayedMaterializingCTEsStep, which is not clonable, so it now returns nullptr instead of building the set.

01700_system_zookeeper_path_in, 02859_replicated_db_name_zookeeper and 03302_analyzer_distributed_filter_push_down are the same defect on the paths that were the whole point of the change: system.zookeeper is read through ReadFromPreparedSource and path IN (subquery) now gets no set, which is why 02859 fails with Code: 36 ... must contain condition like path = 'path' or path IN (...); 03302 reads through ReadFromRemote. I did not run those three locally, because clickhouse local has no cluster, no macros and no Keeper, so the arms would have been vacuous rather than negative.

CIDB, 30 days. Zero failures on head_ref = 'master' for all six test names (including 03928_materialized_cte_index_2, which also fails here). Every hit for 01700 and 03928_materialized_cte_index is on this PR. The handful of rows on other branches are unrelated single hits, except 03302 which has 22 on wip_cascades.

Suggestion. The two goals are separable: keep the source for the deferred build, but still return a set for index analysis. Falling through to the destructive build only when the speculative one cannot run at all would preserve the old index behaviour, and 03928 plus 01064 are good regression tests for it since both fail loudly the moment the index is dropped.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Superseded by #114983. The Fast-test failures and the review establish that skipping buildOrderedSetInplace for non-clonable sources regresses primary-key analysis. PR #114983 retains that optimization and records a destructive speculative-build failure so the deferred build reports the original exception rather than Not-ready Set; its complete CI is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-41a5)

2 participants