Skip to content

Make 03759_distinct_json_paths_optimization independent of the columns cache - #123942

Merged
Avogar merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-03759-distinct-json-paths-columns-cache
Oct 10, 2026
Merged

Avogar merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-03759-distinct-json-paths-columns-cache

Conversation

@groeneai

@groeneai groeneai commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #96844

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):

Make the test 03759_distinct_json_paths_optimization independent of the randomized columns cache.

Description

03759_distinct_json_paths_optimization has failed twice since #96844 started randomizing use_columns_cache. One failure was on master in Stateless tests (amd_tsan, parallel) (report), the other on the unrelated #115722 (report). Before that it ran about 25,000 times in 14 days with no failure.

With the cache on, MergeTreeReaderWide::readRowsWithColumnsCache starts a new read call wherever the set of cached columns changes between granules. json.__special_subcolumn_name_for_distinct_paths_calculation is never cached and puts all paths of one call into that call's first row. So when json (or json.a0, ...) is cached for only some granules, the paths are split over two rows. The union, which is all that distinctJSONPaths reads, is unchanged. In the failing master job's query_log, the three failing statements had mixed per-granule coverage (1 hit / 2 misses, 2/1, 1/5). Every statement with uniform coverage passed.

The change pins use_columns_cache = 0 on the 9 statements that check this per-row layout next to another column. The rest of the test keeps the randomized cache, including the 100000-row reads of the subcolumn next to cached columns. The reference is unchanged.

Validation, debug build, private server with the CI columns-cache config (100 MB, SLRU):

  • Cache granule 0 of json, then run SELECT arraySort(<subcolumn>), json: the paths split over rows 0 and 4 (1 hit / 2 misses), every time. With the pin: the reference layout, 0 cache operations.
  • 50/50 randomized runs, plus 20/20 at -j 4 alongside a cache-pressure loop. In every run, the pinned statements did 0 cache operations.

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

Version info

  • Merged into: 26.10.1.2043-master (included in 26.10 and later)

…s cache

With use_columns_cache = 1, MergeTreeReaderWide::readRowsWithColumnsCache
starts a new read call wherever the set of cached columns changes between
granules. json.__special_subcolumn_name_for_distinct_paths_calculation is
never cached (columns_not_cacheable) and puts all paths of one call into
that call's first row, so when a companion column is cached for only some
granules of the 10-row part, the per-row output is split over two rows at
that granule boundary. The union of paths, which is all distinctJSONPaths
consumes, is unchanged.

In the parallel CI run the 100 MB cache is shared, admission is adaptive
under pressure and concurrent stripe writes can be lost, so partial
coverage happens. The failing master job (Stateless tests (amd_tsan,
parallel), b62bc5c) shows it in its own
query_log: the three failing statements had mixed per-granule coverage
(ColumnsCacheHits/Misses 1/2, 2/1, 1/5), and every statement with uniform
coverage passed.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=b62bc5c3970468c88fb4e3860cefd2883ca27972&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29

Pin use_columns_cache = 0 on the 9 statements that check this per-row
layout next to another column. The rest of the test keeps the randomized
cache, including the 100000-row reads of the subcolumn next to cached
columns. The reference is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 5, 2026
@groeneai

groeneai commented Oct 5, 2026

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 (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 No statement compares the per-row layout of the distinct-paths subcolumn with the cache on any more Noted, not blocking That layout depends on the read shape by design (MergeTreeReaderWide.h:187-192), so only the union is a valid oracle with the cache on. distinctJSONPaths and the 100000-row reads next to cached columns keep the randomized cache.

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

Session id: cron:clickhouse-review-slot-9:20261005-041600

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a server with the CI columns-cache config, cache granule 0 of json in a 10-row, 3-granule part, then SELECT arraySort(json.__special_subcolumn_name_for_distinct_paths_calculation), json: the paths split over rows 0 and 4 with 1 cache hit / 2 misses, byte-identical in 6/6 runs.
b Root cause explained? Yes. With the cache on, the wide reader starts a new read call wherever the set of cached columns changes between granules. The distinct-paths subcolumn is never cached and puts all paths of one call into that call's first row, so partial cache coverage of a companion column in the shared CI cache splits the per-row layout. The union is unchanged.
c Fix matches root cause? Yes. The per-row layout depends on the read shape, and only the union is consumed (distinctJSONPaths). So the 9 statements that assert this layout pin use_columns_cache = 0. No blanket tag, no reference change.
d Test intent preserved / new tests added? Yes. The 9 statements still check the per-row layout on a one-call read. The rest of the test, including the 100000-row reads of the subcolumn next to cached columns, keeps the randomized cache. Test-only change, so no new test.
e Both directions demonstrated? Yes, at the mechanism level: same table and session, split with the cache, reference layout with the pin, 6/6. The failing master job's query_log shows that the 3 failing statements had mixed coverage. Locally the pinned statements did 0 cache operations in all 37 randomized runs that drew the cache (26 of 50, 11 of 20).
f Fix is general across code paths? Yes. One template edit covers all 6 iterations (3 shared-data serializations x wide/compact; compact parts are not cached). The subcolumn read alone is one call by construction. The only other test reading the subcolumn uses Memory tables.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only CI fix).
h Backward compatible? (maintainer-approved exception only) Yes. Test-only, no setting or format change.
i Invariants and contracts preserved? Yes. Test-only. The union of the subcolumn over a whole read, which is what distinctJSONPaths relies on, is unchanged and still checked.

Session id: cron:clickhouse-impl-slot-5:20261005-034600

@clickhouse-gh

clickhouse-gh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aacd107]

Summary: ✅


AI Review

Summary

This PR narrows the layout-sensitive assertions in 03759_distinct_json_paths_optimization to run with use_columns_cache = 0, while leaving the actual distinctJSONPaths coverage and the cache-exercising FORMAT Null reads randomized. That matches the current contract in SerializationObjectDistinctPaths and MergeTreeReaderWide: the special subcolumn's row placement is per read call, so partial cache coverage can legitimately split the paths across multiple rows without changing the union that distinctJSONPaths consumes. I do not see a correctness, coverage, or PR-metadata issue in the current patch.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 5, 2026
@Avogar Avogar self-assigned this Oct 5, 2026
@Avogar
Avogar enabled auto-merge October 5, 2026 17:40
@Avogar
Avogar added this pull request to the merge queue Oct 10, 2026
Merged via the queue into ClickHouse:master with commit 20b50c8 Oct 10, 2026
149 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 10, 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... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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