Skip to content

Fix flaky 04401_distributed_with_fill_const_to_scalar under distributed plan - #110060

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-04401-distributed-with-fill-prefer-localhost-replica
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-04401-distributed-with-fill-prefer-localhost-replica

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #109938

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

04401_distributed_with_fill_const_to_scalar (added by #109938) is flaky on the distributed-plan CI job: 31/31 FAIL with randomized --prefer_localhost_replica 0, 65/65 PASS without it. ~5% master fail rate, seen across ~16 unrelated PRs on 2026-07-10.

Root cause (deterministic repro isolated locally): the distributed-plan job sets serialize_query_plan = 1 globally. With prefer_localhost_replica = 0, the localhost shard is sent through the serialized query-plan path, which deliberately rejects WITH FILL sort descriptions in serializeSortDescription (src/Core/SortDescription.cpp):

Code: 48. DB::Exception: WITH FILL is not supported in serialized sort description: While executing Remote. (NOT_IMPLEMENTED)

That query-plan-serialization limitation is orthogonal to what this test covers: the legacy AST-rewrite path where ReplaceLongConstWithScalarVisitor turns WITH FILL constants into __getScalar nodes (the bug #109938 fixed in buildQueryTreeForShard).

Fix: pin SET serialize_query_plan = 0 in the test (same approach as 02947_parallel_replicas_remote). This avoids the unimplemented plan-serialization path while keeping the genuinely-remote AST-send path exercised under prefer_localhost_replica = 0, so the test still guards the #109938 regression.

Verified locally (debug, global serialize_query_plan=1 + prefer_localhost_replica=0):

  • Original test: FAILS deterministically (Code 48).
  • With fix: PASSES, output matches the reference.

CI report of the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109741&sha=0e350e0a094e&name_0=PR&name_1=Stateless%20tests%20(amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel)

…ed plan

The test failed with NOT_IMPLEMENTED (WITH FILL is not supported in
serialized sort description) on the distributed-plan CI job, where
serialize_query_plan=1 is enabled globally and randomized
prefer_localhost_replica=0 sends the localhost shard through the
serialized query-plan path.

Query-plan serialization deliberately rejects WITH FILL sort
descriptions (serializeSortDescription). That limitation is orthogonal
to the AST-rewrite path this test covers (ReplaceLongConstWithScalarVisitor
turning WITH FILL constants into __getScalar nodes, fixed in ClickHouse#109938).
Pin serialize_query_plan = 0 in the test so the genuinely-remote
AST-send path stays exercised under prefer_localhost_replica=0 while
the unimplemented plan-serialization path is avoided.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. serialize_query_plan=1 (global, from distributed_plan.xml) + prefer_localhost_replica=0 → 100% Code 48. Isolated locally; CI's own diagnosis: 35/35 FAIL with --prefer_localhost_replica 0, 62/62 PASS without.
b Root cause explained? serialize_query_plan=1 sends the localhost shard through query-plan serialization; prefer_localhost_replica=0 forces the localhost replica through that remote path instead of in-process. serializeSortDescription (src/Core/SortDescription.cpp:311) deliberately throws NOT_IMPLEMENTED for WITH FILL. This limitation is orthogonal to the AST-rewrite path (#109938) the test guards.
c Fix matches root cause? Yes. Pin serialize_query_plan = 0 — disables exactly the unimplemented plan-serialization path, nothing else.
d Test intent preserved / new tests added? Yes. With prefer_localhost_replica=0 the query is still sent genuinely-remote via the AST path (buildQueryTreeForShard / ReplaceLongConstWithScalarVisitor), so the #109938 regression is still exercised. Output unchanged, matches reference. Not a source bug → no new test.
e Both directions demonstrated? Yes. Under global serialize_query_plan=1 + prefer_localhost_replica=0: original test FAILS (Code 48); with the pinned setting the full test file PASSES and matches the reference.
f Fix is general across code paths? N/A (flaky test setting fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (flaky test setting fix, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (flaky test setting fix, not a code bug).
i Invariants and contracts preserved? N/A (flaky test setting fix, not a code bug).

Session id: cron:clickhouse-worker-slot-3:20260710-210900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @vdimir — could you review this? Test-only follow-up to #109938: 04401_distributed_with_fill_const_to_scalar is flaky on the distributed-plan job because serialize_query_plan=1 + prefer_localhost_replica=0 routes the localhost shard through query-plan serialization, which rejects WITH FILL (NOT_IMPLEMENTED) — orthogonal to the AST path the test guards. Pins serialize_query_plan=0 so the genuinely-remote AST send is still exercised.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [315a3da]

Summary: ✅


AI Review

Summary

This PR makes 04401_distributed_with_fill_const_to_scalar opt out of serialize_query_plan so the test stays on the AST-sent distributed path that still exercises buildQueryTreeForShard / ReplaceLongConstWithScalarVisitor, while avoiding the separate WITH FILL serialized-sort-description NOT_IMPLEMENTED limitation in the distributed-plan profile. I did not find a correctness or coverage regression in the change.

Final Verdict
  • Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 315a3da

CI fully finished (Finish Workflow / Mergeable Check / PR all pass). No failing checks. Every gate green.

Check / test Reason Owner / fixing PR
(none) - -
Sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260711-030000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Closing as superseded. Master already merged an identical fix for this exact flaky test in #110044 (serialize_query_plan = 0 on the distributed-plan shard, same root cause: serializeSortDescription throws NOT_IMPLEMENTED for WITH FILL when the shard enables serialize_query_plan globally). That PR merged 2026-07-10 23:50 UTC and master has been green for the test since (0 FAIL on master post-merge). This PR now conflicts because it duplicates the same change.

@groeneai groeneai closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants