Skip to content

External IN (1/2) - #123860

Merged
nihalzp merged 59 commits into
ClickHouse:masterfrom
nihalzp:external-in
Oct 9, 2026
Merged

nihalzp merged 59 commits into
ClickHouse:masterfrom
nihalzp:external-in

Conversation

@nihalzp

@nihalzp nihalzp commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Related: #116569

The sets of IN built from a subquery or a table can now spill to disk while they are filled, as ORDER BY, GROUP BY, JOIN and DISTINCT already do.

Every set of IN that is filled while the query runs can spill:

  • with a subquery or a table, in WHERE, PREWHERE, HAVING, the SELECT list, lambdas and JOIN ON;
  • in INSERT ... SELECT, views, materialized views, refreshable materialized views and dictionary sources;
  • in mutations: ALTER TABLE ... DELETE, ALTER TABLE ... UPDATE and lightweight DELETE. The parts of a mutation share a spilled set through the prepared sets cache, as they share a set in memory;
  • on the remote side of GLOBAL IN and the set that the conversion of JOIN to IN builds.

These sets stay in memory:

  • literal lists such as x IN (1, 2, 3) and Set tables, which the query does not build;
  • the set of lazy FINAL, which serves only index analysis and needs its values;
  • the temporary table of GLOBAL IN on the initiator and the shards. The set that a shard builds from it can spill.

This PR only has a very basic disk based set. Future improvements are planned and will come in a separate PR.

Since disk set of this version is basic, and spilling is off by default.

Optimizing it is planned for follow-up PRs: a membership filter that skips reads for misses, sorted probe batches across chunks, reused readers and a block cache, integer encodings of the blocks, and more.

Changelog category (leave one):

  • New Feature

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

The sets of IN with a subquery or a table can now spill to disk, once the tracked memory of the query exceeds max_bytes_before_external_set bytes or the max_bytes_ratio_before_external_set fraction of the available server or user memory. Both settings are 0 by default, which keeps sets in memory.


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

Version info

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

nihalzp added 30 commits October 3, 2026 11:45
Comment thread src/Interpreters/FutureSetSettings.cpp Resolved
Comment thread src/Interpreters/PreparedSets.cpp Resolved
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Interpreters/DiskSetBuilder.cpp Resolved
Comment thread src/Interpreters/DiskSetBuilder.cpp Resolved
Comment thread src/Interpreters/Set.cpp Resolved
Comment thread src/Interpreters/PreparedSets.cpp Resolved
@nihalzp

nihalzp commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

@nihalzp
nihalzp added this pull request to the merge queue Oct 9, 2026
Merged via the queue into ClickHouse:master with commit 0994a31 Oct 9, 2026
162 of 163 checks passed
@nihalzp
nihalzp deleted the external-in branch October 9, 2026 10:31
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 2026
PedroTadim added a commit that referenced this pull request Oct 9, 2026
…top-K dynamic filtering settings

- `max_bytes_before_external_set` / `max_bytes_ratio_before_external_set` join the external
  sort/group by/distinct family. The bytes threshold is drawn low (1 byte to 64 MiB) so that
  sets actually spill.
- `enable_join_seal_gated_reading` (experimental) is enabled with 30% probability.
- `enable_group_by_top_k_dynamic_filtering` is disabled with 5% probability.

The last two are forced off when their parent settings are off.

Related: #123860
Related: #113512
Related: #121145

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nihalzp nihalzp mentioned this pull request Oct 25, 2026
47 of 72 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-feature Pull request with new product feature 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