Skip to content

Keep the set of IN in memory in 00673_subquery_prepared_set_performance - #126681

Merged
nihalzp merged 1 commit into
ClickHouse:masterfrom
groeneai:keep-in-set-in-memory-00673
Oct 20, 2026
Merged

nihalzp merged 1 commit into
ClickHouse:masterfrom
groeneai:keep-in-set-in-memory-00673

Conversation

@groeneai

@groeneai groeneai commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124907
Related: #126623

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

00673_subquery_prepared_set_performance fails with Primary key (x) is not used and setting 'force_primary_key' is set. (INDEX_NOT_USED) in Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) with --max_bytes_before_external_set 29596895 (105/105 reruns with the same settings fail, 141/141 pass without randomization).

Since #124907 the runner randomizes the spill thresholds of the set of IN. A threshold below the memory of the 1M-key set makes the set spill while it is built, and such a set is not used by the primary key by design (docs), so force_primary_key = 1 throws. The test checks the in-memory set, so it now clamps both thresholds to 0 on its existing Random settings limits line; other settings stay random. Same fix as #126623 for 02844_subquery_timeout_with_break. #106734 pins only max_bytes_before_external_set in this test; the ratio threshold can also spill the set when little memory is left under the server or user limit, so both are clamped here.

Validation: with the CI value the query throws and spills, with 0 it returns the row; with the runner's draw forced to the CI value the test fails 10/10 without the clamp and passes 5/5 with it; 50/50 randomized runs pass, and system.query_log shows max_bytes_ratio_before_external_set = 0 in all 50.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.282-master (included in 26.11 and later)
  • Backported to: 26.10.2.30

Since ClickHouse#124907 the test runner randomizes max_bytes_before_external_set and
max_bytes_ratio_before_external_set. A threshold below the memory of the
1M-key set makes the set spill while it is built, and such a set keeps no
explicit elements, so the primary key cannot use it and force_primary_key = 1
throws INDEX_NOT_USED. This is documented (docs/reference/statements/in.mdx:
"A set written to disk while it is built cannot be used by the primary key or
data skipping indexes"). CI hit it with --max_bytes_before_external_set 29596895.

Clamp both thresholds to 0 on the existing Random settings limits line (the
runner reads only the first such line); other settings stay random. Same fix
as ClickHouse#126623 for 02844_subquery_timeout_with_break.

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) and my own cold review (0 findings). Test-only change; nothing to adjudicate.

Session id: cron:clickhouse-review-slot-9:20261019-114300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. x IN (SELECT * FROM numbers(1000000)) with force_primary_key = 1, max_bytes_before_external_set = 29596895 throws INDEX_NOT_USED every time; with the runner's draw forced to that value the test fails 10/10.
b Root cause explained? Since #124907 the runner randomizes the set spill thresholds. Below the set's memory the set spills while it is built, keeps no explicit elements (documented in in.mdx), the primary key cannot use it, and force_primary_key throws.
c Fix matches root cause? Yes. Both spill thresholds are clamped to 0 on the test's existing Random settings limits line, so the set stays in memory; all other settings stay random.
d Test intent preserved / new tests added? Yes. Queries, assertions and .reference are unchanged; test-only fix.
e Both directions demonstrated? Yes. Forced draw: 10/10 FAIL without the clamp, 5/5 OK with it. 50/50 randomized runs OK, max_bytes_ratio_before_external_set = 0 in system.query_log for all 50; without the clamp 25/30 runs draw a nonzero threshold.
f Fix is general across code paths? Both randomizer modes (bytes and ratio) are clamped. No other force_primary_key test uses a set large enough to spill; 02844_subquery_timeout_with_break is fixed by #126623.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only setting clamp).
h Backward compatible? (maintainer-approved exception only) N/A (test-only, no setting or default change).
i Invariants and contracts preserved? Yes. The runner reads only the first Random settings limits line, so the clamp extends the existing one; the enable_parallel_replicas=(0, 0) clamp is kept.

Session id: cron:clickhouse-impl-slot-5:20261019-112900

@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b25c6c7]

Summary: ✅


AI Review

Summary

This test-only change disables randomized spilling of the IN set in 00673_subquery_prepared_set_performance, preventing expected INDEX_NOT_USED exceptions while preserving the primary-key and single-preparation assertions. No actionable findings.

Final Verdict

Status: ✅ Approve. Both spill thresholds are covered by the runner's existing limit mechanism. The unchanged regression assertions pass in the PR's Fast test report.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nihalzp, could you review this and add the can be tested label so CI runs? Since #124907 randomizes the spill thresholds of the set of IN, the 1M-key set in 00673_subquery_prepared_set_performance can spill while it is built and is then not used by the primary key, so force_primary_key = 1 throws INDEX_NOT_USED; the test now clamps both thresholds to 0 on its existing Random settings limits line (same shape as #126623).

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 19, 2026
@nihalzp nihalzp added the can be tested Allows running workflows for external contributors label Oct 19, 2026
@nihalzp nihalzp self-assigned this Oct 19, 2026
@nihalzp
nihalzp added this pull request to the merge queue Oct 20, 2026
Merged via the queue into ClickHouse:master with commit 788e854 Oct 20, 2026
526 of 528 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 20, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 20, 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 Oct 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 20, 2026
Backport #126681 to 26.10: Keep the set of `IN` in memory in `00673_subquery_prepared_set_performance`
zoomxi pushed a commit to zoomxi/ClickHouse that referenced this pull request Nov 19, 2026
Since ClickHouse#124907 the runner randomizes max_bytes_before_external_set and
max_bytes_ratio_before_external_set. A draw below the memory of an IN set
(CI: 1215 bytes) makes the set spill while it is built. A spilled set keeps
no explicit elements, so KeyCondition does not use it, partition pruning
keeps all 3 partitions, and EXPLAIN ESTIMATE reports 3 parts instead of 2 in
the "Non-safe cast" section (results stay correct; documented in
docs/reference/statements/in.mdx). The LowCardinality, Nullable and
LowCardinality(Nullable) set sections lose pruning the same way for a
smaller draw.

The test checks pruning by the in-memory set, so clamp both thresholds to 0
with a Random settings limits line; every other setting stays random. Same
fix as ClickHouse#126681 (00673) and ClickHouse#126623 (02844).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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.

4 participants