Skip to content

Pin the Top-K limit in 05100_autopr_gate_lazy_read - #132873

Merged
devcrafter merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-top-k-limit-05100-autopr-gate-lazy-read
Nov 19, 2026
Merged

devcrafter merged 1 commit into
ClickHouse:masterfrom
groeneai:pin-top-k-limit-05100-autopr-gate-lazy-read

Conversation

@groeneai

@groeneai groeneai commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131858
Related: #128413

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

05100_autopr_gate_lazy_read fails in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (2 of 55 runs in 30 days, e.g. this report); the runner's diagnosis names query_plan_max_limit_for_top_k_optimization 0.

With that limit at 0 or 100000, Top-K takes the test's LIMIT 10000 and adds __topKFilter(ord) to the read. Plan-based parallel replicas keeps such a read local, so automatic parallel replicas logs The plan built with parallel replicas contains no read from the other replicas and collects no statistics (#131858). The test now pins the limit to its default, as 801dfec4b8a5 did for 05055_autopr_limit_offset. No revert: the test and the keep-local rule predate the job that exposed this.

Validation: with parallel_replicas_plan_based=1 and the limit at 0 or 100000, 5/5 FAIL before and 5/5 OK after; removing only the new SET fails again. Fully randomized plan-based runs: 6/50 FAIL before, 50/50 OK after; query-based 50/50 OK.


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

Version info

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

`clickhouse-test` randomizes `query_plan_max_limit_for_top_k_optimization`
over [0, 1, 10, 100, 1000, 100000]. At 0 (no limit) or 100000, Top-K takes
the test's `ORDER BY ord LIMIT 10000` and adds `__topKFilter(ord)` to the
read's PREWHERE. Plan-based parallel replicas keeps such a read local
(`mergeTreeReadCanBeShipped`), so automatic parallel replicas finds no read
on the other replicas, skips the query and collects no statistics, and the
`05100_lazy_large_scan` row turns from 1 to 0 in
`Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel)`.

Pin the limit to its default, as 801dfec did for 05055. The product
limitation is ClickHouse#131858.

Locally, with `parallel_replicas_plan_based=1` and the limit at 0 or 100000:
5/5 FAIL before, 5/5 OK after, 5/5 FAIL again with only the new `SET`
removed. Fully randomized plan-based runs: 6/50 FAIL before, 50/50 OK after.

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 (0 findings).

# Sev Finding Verdict Evidence / action
- - No findings - Checked: the optimizeTopK limit gate, mergeTreeReadCanBeShipped keeping a Top-K read local, the randomized values, and the sibling tests (05055 pinned the same way, 05175 and 05394 pinned to query-based)

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

Session id: cron:clickhouse-review-slot-48:20261119-041700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. --client-option parallel_replicas_plan_based=1 query_plan_max_limit_for_top_k_optimization=0 (or 100000) with no other randomization: 5/5 FAIL each, 05100_lazy_large_scan 1 -> 0. Each setting alone: 5/5 OK.
b Root cause explained? Yes. At limit 0/100000 Top-K takes LIMIT 10000 and stamps the read with __topKFilter(ord); plan-based parallel replicas keeps a stamped read local, so automatic parallel replicas finds no remote read and skips the query before collecting statistics (#131858). Seen in the server log of every failing execution.
c Fix matches root cause? Yes. The pin removes exactly the trigger (Top-K taking this query), the same remedy as 801dfec4b8a5 for 05055; no blanket tag, no assertion changed, plan-based coverage kept.
d Test intent preserved / new tests added? Yes. Every assertion is kept and still runs under plan-based parallel replicas; test-only change.
e Both directions demonstrated? Yes. 5/5 FAIL before, 5/5 OK after for both values; removing only the new SET fails 5/5 again. Randomized plan-based: 6/50 FAIL before, 50/50 OK after; query-based 50/50 OK.
f Fix is general across code paths? The product limitation is #131858. Every other automatic parallel replicas statistics test with a Top-K-eligible ORDER BY ... LIMIT >= 1000 is already pinned (05055, 05175, 05394).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test setting pin); both triggering values, 0 and 100000, validated.
h Backward compatible? (maintainer-approved exception only) N/A, no setting or format change.
i Invariants and contracts preserved? N/A (test-only). The SET precedes every query and equals the default, so it is a no-op wherever the runner did not randomize the setting.

Session id: cron:clickhouse-impl-slot-41:20261119-040200

@clickhouse-gh

clickhouse-gh Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [437e698]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) FAIL
05829_autopr_skip_index_on_read_in_subquery FAIL cidb
05829_autopr_skip_index_on_read_in_subquery FAIL cidb
05829_autopr_skip_index_on_read_in_subquery FAIL cidb
01283_max_threads_simple_query_optimization NOT_FAILED cidb

AI Review

Summary

PR #132873 pins query_plan_max_limit_for_top_k_optimization to its default of 1000 in 05100_autopr_gate_lazy_read. This excludes its LIMIT 10000 queries from Top-K filtering, avoiding the known plan-based parallel replica limitation tracked in #131858. The lazy-materialization and statistics assertions remain intact. No actionable findings.

Missing context / blind spots
  • ⚠️ The plan-based parallel replica CI jobs are pending for 437e69806bd9787b57ea4c9ca93c1b7b529b5b65. No local binary was available for an independent rerun. The PR records deterministic before/after checks for both triggering setting values, a reversal check, and randomized runs; completed CI will provide independent confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 437e698

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) / 05829_autopr_skip_index_on_read_in_subquery not from this PR (it changes only 05100_autopr_gate_lazy_read): a deterministic red of this test under the plan-based parallel replicas job, on 11 master commits since 2026-11-19 00:41Z (master report) and on 42 other PRs #132867 (mine, open)
PR praktika rollup of the row above #132867 (mine, open)

The other CIDB FAIL rows on this head are Config Workflow / Pre Hooks of the runs before the can be tested label. Mergeable Check is red only because of the row above; CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261119-073024

@devcrafter devcrafter added the comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). label Nov 19, 2026
@devcrafter devcrafter self-assigned this Nov 19, 2026
@devcrafter

Copy link
Copy Markdown
Member

Failed test fixed in #132867

@devcrafter
devcrafter added this pull request to the merge queue Nov 19, 2026
Merged via the queue into ClickHouse:master with commit 3c82c71 Nov 19, 2026
576 of 580 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot removed the comp-testing Test content only (no production code). label 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-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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