Skip to content

Fix cubic complexity of enumerating subcolumns of deeply nested types - #126554

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-deeply-nested-array-subcolumns
Oct 20, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-deeply-nested-array-subcolumns

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

supportsPooling of SerializationArray, SerializationNullable, SerializationTuple and SerializationWrapper (thus SerializationNamed) recursed into the nested serialization, so it cost O(depth), and it is called on every create of these serializations. IDataType::forEachSubcolumn calls ISerialization::createFromPath for every subcolumn, which applies one SerializationArray::create per enclosing level, so for an Array nested D levels deep, enumerating subcolumns took O(D^3) time: seconds of CPU for a depth of 2000 and minutes with multiple GB of memory for a depth of 10000 (reachable via schema inference with a raised max_parser_depth).

Now the result of supportsPooling of the nested serializations is cached in the constructors, which makes it O(1) and forEachSubcolumn O(D^2) for such types. The remaining quadratic factor is inherent: there are D subcolumns size0 ... size{D-1} whose types have nesting depth up to D.

Changelog category (leave one):

  • Performance Improvement

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

Fix cubic complexity of enumerating subcolumns of deeply nested Array types.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.330-master (included in 26.11 and later)
  • Backported to: 26.10.6.5, 26.9.34.10, 26.8.42.8

alexey-milovidov and others added 2 commits October 18, 2026 00:02
`supportsPooling` of `SerializationArray`, `SerializationNullable`, `SerializationTuple`
and `SerializationWrapper` (thus `SerializationNamed`) recursed into the nested
serialization, so it cost O(depth). It is called by every `create` of these
serializations before pooling. `IDataType::forEachSubcolumn` calls
`ISerialization::createFromPath` for every subcolumn, which applies one
`SerializationArray::create` per enclosing level, so for `Array` nested `D` levels
deep enumerating subcolumns took O(D^3) time: about 8 seconds of CPU for a depth
of 2000 and minutes with multiple GB of memory for a depth of 10000 (reachable via
schema inference with raised `max_parser_depth`).

Cache the result of `supportsPooling` of the nested serializations in the
constructors, which makes it O(1) and `forEachSubcolumn` O(D^2) for such types.
The remaining quadratic factor is inherent: there are D subcolumns `size0` ...
`size{D-1}` whose types have nesting depth up to D.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4892784]

Summary: ✅


AI Review

Summary

The PR caches nested supportsPooling results in SerializationArray, SerializationNullable, SerializationTuple, and SerializationWrapper to reduce deeply nested subcolumn enumeration from cubic to quadratic complexity. The existing performance-evidence finding remains unresolved at head 489278424d8ac2ab171451c0b4349673d62424b2; no new inline findings were identified. Request changes until the claimed improvement has measured evidence.

Findings

⚠️ Majors

  • tests/queries/0_stateless/05423_deeply_nested_array_subcolumns.sql:11: The performance improvement remains unverified. The test exercises depth 300 and checks output, which would also match with the original recursive supportsPooling implementation. The description and commit message report pre-change runtime without matching post-change measurements. Keep the functional test and supply a focused benchmark or reproducible before/after timings. This is the existing open finding, retained without a duplicate comment.
Tests
  • ⚠️ Measure the subcolumn enumeration query before and after the change at several depths, such as 500, 1000, and 2000, using the same release build configuration. Record the commands and CPU timings, or add a focused performance test that demonstrates the benefit and detects its removal.
Final Verdict

Status: ⚠️ Request changes. The minimum required action is to provide reproducible performance evidence for the claimed complexity improvement.

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-data-types Type system & core datatypes used across query planning/execution. labels Oct 18, 2026
…ack limit in TSan builds

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 489278424 with master c8d67a8a9 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

668 translation units recompiled, 5603 s compile time in total, 668 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.18 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +902.3 s (+19%) in total before that adjustment.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

Baseline selected using StressHouse version hint 26.11.1.42530; measured build ancestry could not be verified. Measured differences are not attributed to this PR. ⚙️ 1 flagged delta falls inside the range master itself produced for the same query over the last 7 days — environment variance, not attributable to this PR.

no significant changes detected. K_source=6 K_base=28 flagged=0/65

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 16 not_sure 531 598 +12.5% <0.0001

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: c2b99278-89bc-4e65-8c0c-411a049a9583
  • MIRAI run: f0c74e09-4824-4176-8900-2b8751400322
  • PR check IDs:
    • clickbench_577250_1792370231
    • clickbench_577384_1792370257
    • clickbench_577494_1792370276
    • tpch_adapted_1_official_577617_1792370308
    • tpch_adapted_1_official_577726_1792370325
    • tpch_adapted_1_official_577948_1792370473

@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.

Trivial. LGTM.

@alexey-milovidov alexey-milovidov self-assigned this Oct 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 20, 2026
Merged via the queue into master with commit dff9a12 Oct 20, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-deeply-nested-array-subcolumns branch October 20, 2026 17:53
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 20, 2026
@KochetovNicolai KochetovNicolai added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 17, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 17, 2026
Backport #126554 to 26.10: Fix cubic complexity of enumerating subcolumns of deeply nested types
alexey-milovidov added a commit that referenced this pull request Nov 19, 2026
Resolve the conflict in `SerializationNullable.h`: 26.8 has no
`isNullMapSubcolumn`, so keep only the cached `nested_supports_pooling`
from the original PR. The resulting diff against the backport branch is
identical to the original PR #126554.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll4 added a commit that referenced this pull request Nov 19, 2026
Cherry pick #126554 to 26.8: Fix cubic complexity of enumerating subcolumns of deeply nested types
robot-clickhouse added a commit that referenced this pull request Nov 19, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 19, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 19, 2026
Backport #126554 to 26.8: Fix cubic complexity of enumerating subcolumns of deeply nested types
clickhouse-gh Bot added a commit that referenced this pull request Nov 19, 2026
Backport #126554 to 26.9: Fix cubic complexity of enumerating subcolumns of deeply nested types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-data-types Type system & core datatypes used across query planning/execution. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements 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.

4 participants