Skip to content

Make 04413_documentation_no_indented_lines linear in the number of lines - #127390

Merged
cv4g merged 1 commit into
masterfrom
fix-documentation-indent-test-memory
Oct 22, 2026
Merged

cv4g merged 1 commit into
masterfrom
fix-documentation-indent-test-memory

Conversation

@cv4g

@cv4g cv4g commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fix 04413_documentation_no_indented_lines failing with MEMORY_LIMIT_EXCEEDED:

Since 2026-10-20 the test exceeds the 4.66 GiB memory limit in many PRs and on master (e.g. #110548, #115605, #124893, #126971, #127220), whenever the randomized settings include enable_lazy_columns_replication = 0. CI reproduces it with that setting and passes without it.

CIDB: https://play.clickhouse.com/play?user=play&run=1&tab=Query%20C#V0lUSAogICAgOTAgQVMgaW50ZXJ2YWxfZGF5cwpTRUxFQ1QKICAgIHRvU3RhcnRPZkRheShjaGVja19zdGFydF90aW1lKSBBUyBkYXksCiAgICBjb3VudCgpIEFTIGZhaWx1cmVzLAogICAgZ3JvdXBVbmlxQXJyYXkocHVsbF9yZXF1ZXN0X251bWJlcikgQVMgcHJzLAogICAgYW55KHJlcG9ydF91cmwpIEFTIHJlcG9ydF91cmwKRlJPTSBjaGVja3MKV0hFUkUgKG5vdygpIC0gdG9JbnRlcnZhbERheShpbnRlcnZhbF9kYXlzKSkgPD0gY2hlY2tfc3RhcnRfdGltZQogICAgQU5EIHRlc3RfbmFtZSA9ICcwNDQxM19kb2N1bWVudGF0aW9uX25vX2luZGVudGVkX2xpbmVzJwogICAgLS0gQU5EIGNoZWNrX25hbWUgPSAnU3RhdGVsZXNzIHRlc3RzIChhbWRfZGVidWcsIHBhcmFsbGVsKScKICAgIEFORCB0ZXN0X3N0YXR1cyBJTiAoJ0ZBSUwnLCAnRVJST1InKQogICAgQU5EIChwdWxsX3JlcXVlc3RfbnVtYmVyID0gMCBPUiBiYXNlX3JlZiBJTiAoJ21hc3RlcicpKQogICAgQU5EIHRlc3RfY29udGV4dF9yYXcgTElLRSAnJXJldHVybiBjb2RlJScKR1JPVVAgQlkgZGF5Ck9SREVSIEJZIGRheSBERVNDCg==

The query checked every line of every documentation entry in a lambda that refers to the per-line arrays of the entry, so each array was copied for every line: quadratic in the number of lines, and system.events alone has about 7000. With lazy replication disabled these copies are materialized.

The query now:

  • finds the candidate lines first (non-blank, outside a fenced code block, indented by four columns or more, preceded by a blank line) with a lambda over the arrays shifted by one line, which needs no copies;
  • looks up the container (the nearest preceding non-blank line indented less) only for these candidates, a few dozen in all of system.documentation, and only once per candidate instead of four times.

For an entry with n lines and k candidates this is O(n + k * n) instead of O(n²).

before after
minimum max_memory_usage, enable_lazy_columns_replication = 1 1444 MiB 30 MiB
minimum max_memory_usage, enable_lazy_columns_replication = 0 3940 MiB 30 MiB
run time, lazy replication on / off 0.4 s / 1.2 s 0.16 s / 0.16 s

The rule the test checks is unchanged:

  • the old and new query flag exactly the same entries for 150000 random Markdown-like descriptions (indentation, tabs, list markers, fences, blank lines), about half of them flagged;
  • they also agree on hand-written cases: an indented admonition, indented prose, a tab-indented line and a code block inside a list item are flagged; a sub-bullet, a wrapped list paragraph, fenced code and an indented line without a blank line before it are not.

Related: https://github.com/ClickHouse/ClickHouse/actions/runs/39757783682/job/119767959935

Changelog category (leave one):

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

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

Version info

  • Merged into: 26.11.1.554-master (included in 26.11 and later)
  • Backported to: 26.10.9.13

…lines

The lambda over all lines of a documentation entry referred to the arrays of the entry, so every
array was copied for every line: quadratic in the number of lines, which reach thousands
(`system.events` has about 7000). With the randomized `enable_lazy_columns_replication = 0` the copies
are materialized, and the query needed about 3.9 GiB locally. In CI, where it needs a little more, it
exceeded the 4.66 GiB memory limit, failing the test in many PRs and on master.

Find the lines that may start a code block first, from the arrays shifted by one line, with a lambda
that gets one element of each array instead of referring to whole arrays. Only these few lines (56 of
about 180000) look up their container, which is also computed once instead of four times. The query now
needs about 30 MiB with or without lazy replication. The result is the same: compared with the old
query on 150000 random Markdown-like descriptions.
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [45324f3]

Summary: ✅


AI Review

Summary

Reworks 04413_documentation_no_indented_lines to identify candidate lines before resolving their containers, reducing array replication while preserving the Markdown indentation check. No actionable findings. The reported memory measurements and independent comparison of the original and revised predicates on 10,000 synthetic descriptions and 14 boundary cases support approval.

Missing context / blind spots
  • ⚠️ PR-head stateless results were not available at review time. Independent SQL validation used a public server with enable_lazy_columns_replication = 1; validation with the setting disabled relies on the author's reported results. A passing PR-head run with enable_lazy_columns_replication = 0 would close this limit.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 22, 2026
@rienath rienath self-assigned this Oct 22, 2026
@cv4g

cv4g commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Related fix in #116577 alongside more changes.

@cv4g
cv4g enabled auto-merge October 22, 2026 12:15
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 22, 2026
@cv4g
cv4g added this pull request to the merge queue Oct 22, 2026
Merged via the queue into master with commit cbe1bba Oct 22, 2026
178 checks passed
@cv4g
cv4g deleted the fix-documentation-indent-test-memory branch October 22, 2026 15:53
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 20, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 20, 2026
Backport #127390 to 26.10: Make `04413_documentation_no_indented_lines` linear in the number of lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-testing Test content only (no production code). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants