Skip to content

Fix flaky 03223_nested_json_in_shared_data_merges: order its SELECTs - #128385

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03223-nested-json-order-by-all
Nov 1, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03223-nested-json-order-by-all

Conversation

@groeneai

@groeneai groeneai commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #116577

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

The test failed in Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) on #116577, and 172 of 174 reruns with the same settings failed too.

None of the six select JSON*Paths(arrayJoin(json.a[])) from test queries has an ORDER BY. A randomized index_granularity = 1 gives the merged part one granule per row. On a remote disk the minimum read task is 8 marks, so the part is read as two tasks whose streams are united in no particular order.

The queries now end with order by all, and the reference is reordered within each section without changing its contents. I did not use order by _part_offset: the planner evaluates JSON*Paths after that sort, on a re-assembled JSON column, which changes the reported layout.

Validation: replaying the CI job's exact settings with parallel replicas against an s3-backed server, 78/100 (parallel_replicas_local_plan = 1) and 45/50 (= 0) runs fail before the fix, and 100/100 pass after it with each value.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/128385]

Version info

  • Merged into: 26.11.1.1048-master (included in 26.11 and later)

The six `select JSON*Paths(arrayJoin(json.a[])) from test` queries had no
ORDER BY, so they asserted the physical read order of the merged part.

With a randomized `index_granularity = 1` the merged part (10, then 15 rows)
has one granule per row. On a remote disk the minimum read task is
`merge_tree_min_read_task_size` = 8 marks (the `_for_remote_filesystem`
row/byte minimums default to 0), so the part is read as two tasks, [0, 8) and
[8, N), whose streams are united without order; the short task usually
finishes first and its rows are printed first. That is the failure seen in
`Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)` on
PR ClickHouse#116577 (172 of 174 same-settings reruns failed). Only release builds can
draw that granularity: debug and sanitizer builds draw it from [100, 65536].

Order each SELECT by its own result (`order by all`) and reorder the
reference within each section accordingly. The per-section contents are
unchanged, and since every row carries exactly one path, those multisets
still pin which path is dynamic and which is in shared data.

`order by _part_offset` is not usable here: the planner evaluates the
JSON*Paths functions after that sort, on a JSON column re-assembled from the
two read tasks' chunks, which changes the reported layout (the `c` paths
become dynamic). With `order by all` the sort key is the function result, so
the function still runs on each read chunk before the sort.

Related: ClickHouse#116577
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review of the diff (0 findings on the test change).

I checked that order by all keeps the sort key equal to the JSON*Paths result, so the functions still run on each read chunk before the sort, and that each section of the new reference has the same contents as before. Every row carries exactly one path, so a misplaced b or c path still changes the output.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261031-153600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. I replayed the failing job's exact settings blob (--settings-file/--merge-tree-settings-file) with the lane's parallel-replicas profile against an s3-backed server: the base test failed 78/100 runs (parallel_replicas_local_plan=1) and 45/50 (=0), with the CI diff shape.
b Root cause explained? Randomized index_granularity = 1 gives the merged 10/15-row part one granule per row. On a remote disk the minimum read task is merge_tree_min_read_task_size = 8 marks, so the part is read as two tasks whose streams are united unordered. The SELECTs had no ORDER BY.
c Fix matches root cause? Yes. The queries assumed an order that SQL never guaranteed, and now they order by their own result. No setting is pinned and no tag is added.
d Test intent preserved / new tests added? Yes. Each section's multiset is unchanged (checked mechanically), and since every row carries exactly one path, those multisets still pin which path is dynamic and which is in shared data.
e Both directions demonstrated? Yes. On real s3, before 78/100 + 45/50 FAIL and after 100/100 + 100/100 OK. On the forced-task-size rig, before 80/100 FAIL and after 200/200 OK at each of LP=1, LP=0 and no parallel replicas, also with query_plan_execute_functions_after_sorting set to 0 or 1.
f Fix is general across code paths? N/A (test-only). The sibling 03224/03211 merge tests already order by the printed value, and 03223 is the only file with this unordered shape.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). Verified under both parallel-replicas plans, without parallel replicas, at granularity 1 and 8192, and under randomized settings.
h Backward compatible? (maintainer-approved exception only) N/A (test-only, no settings or formats touched).
i Invariants and contracts preserved? Yes. The sort key is the function result, so JSON*Paths still runs on each read chunk before the sort (EXPLAIN checked). That is what keeps the reported layout unchanged.

Session id: cron:clickhouse-impl-slot-40:20261031-150800

@clickhouse-gh

clickhouse-gh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1950b83]

Summary: ✅


AI Review

Summary

The PR stabilizes 03223_nested_json_in_shared_data_merges by adding ORDER BY ALL to its six JSON path queries and reordering the reference output. No actionable findings: the change preserves the path assertions and addresses the ordering failure shown in the linked CI report.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Avogar, could you review this and add the can be tested label so CI runs? The six JSON*Paths(arrayJoin(json.a[])) SELECTs had no ORDER BY, and with randomized index_granularity = 1 on a remote disk the merged part is read as two 8-mark tasks united unordered; the queries now use order by all and the reference is reordered within each section.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 31, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Nov 1, 2026
@alexey-milovidov alexey-milovidov self-assigned this Nov 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 1, 2026
Merged via the queue into ClickHouse:master with commit 6d1f61b Nov 1, 2026
529 of 531 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 1, 2026
@clickhouse-gh clickhouse-gh Bot added comp-json-datatype JSON/Dynamic/Object datatype: semi-structured column storage, typed and dynamic paths, sub-object... and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-json-datatype JSON/Dynamic/Object datatype: semi-structured column storage, typed and dynamic paths, sub-object... pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants