Skip to content

Sampling via geometric distribution - #101022

Open
jh0x wants to merge 81 commits into
ClickHouse:masterfrom
jh0x:jh-ber
Open

jh0x wants to merge 81 commits into
ClickHouse:masterfrom
jh0x:jh-ber

Conversation

@jh0x

@jh0x jh0x commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Attempt to implement sampling via geometric distribution (#85195)

SET allow_experimental_bernoulli_sample = 1;

DROP TABLE IF EXISTS t_bench;
CREATE TABLE t_bench (x UInt64, payload String DEFAULT randomString(200))
ENGINE = MergeTree ORDER BY x SETTINGS index_granularity = 256;
-- 50M rows × ~208 bytes = 10 GB uncompressed.
-- 50M / 256 = 195312 granules. At p=0.001, ~22.6% hits
INSERT INTO t_bench (x) SELECT number FROM numbers(50000000);
OPTIMIZE TABLE t_bench FINAL;

SELECT 'parts:', count(), 'total_rows:', sum(rows)
FROM system.parts WHERE database = currentDatabase() AND table = 't_bench' AND active;

TRUNCATE TABLE system.query_log;

SYSTEM DROP MARK CACHE;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;

SELECT 'sampled scan';
SELECT count(), sum(cityHash64(payload)) FROM t_bench SAMPLE 0.001 SETTINGS bernoulli_sample_seed = 42;

SYSTEM DROP MARK CACHE;
SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM DROP FILESYSTEM CACHE;

SELECT 'full scan';
SELECT count(), sum(cityHash64(payload)) FROM t_bench;

SYSTEM FLUSH LOGS;

SELECT 'query_log results (raw values)';
SELECT
    query_duration_ms AS ms,
    read_rows,
    read_bytes,
    formatReadableSize(read_bytes) AS bytes_h,
    replaceRegexpOne(query, '\\s+SETTINGS.*', '') AS q
FROM system.query_log
WHERE current_database = currentDatabase()
    AND query LIKE '%FROM t_bench%'
    AND query NOT LIKE '%query_log%'
    AND query NOT LIKE '%system%'
    AND type = 'QueryFinish'
ORDER BY event_time_microseconds;

DROP TABLE t_bench;

   ┌──ms─┬─read_rows─┬──read_bytes─┬─bytes_h──┬─q──────────────────────────────────────────────────────────────────┐
1. │ 176 │  11272960 │  1853847797 │ 1.73 GiB │ SELECT count(), sum(cityHash64(payload)) FROM t_bench SAMPLE 0.001 │
2. │ 262 │  50000000 │ 10150000000 │ 9.45 GiB │ SELECT count(), sum(cityHash64(payload)) FROM t_bench;             │
   └─────┴───────────┴─────────────┴──────────┴────────────────────────────────────────────────────────────────────┘


Changelog category (leave one):

  • Experimental Feature

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

Experimental. Allow SAMPLE clause on MergeTree tables without a SAMPLE BY key using Bernoulli row-level sampling. Enable with SET allow_experimental_bernoulli_sample = 1. Each row is independently selected with the given probability, and entire granules with no sampled rows are skipped.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Mar 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e2a8bff]

Summary: ✅


AI Review

Summary

Adds experimentally gated Bernoulli row sampling for MergeTree tables without a SAMPLE BY key, with deterministic seeds and granule skipping. Two major issues remain: stored views bypass zero-seed result-cache protection, and full-part mask construction cannot be interrupted by cancellation.

Findings

⚠️ Majors

  • src/Interpreters/Cache/QueryResultCache.cpp:300: Stored views hide nondeterministic sampling from the result cache. Given a populated MergeTree table t(id UInt64) without a sampling key, enable allow_experimental_bernoulli_sample and create v AS SELECT id FROM t SAMPLE 0.1. Then SELECT sum(id) FROM v SETTINGS bernoulli_sample_seed = 0, use_query_cache = 1, query_cache_for_subqueries = 0, query_cache_nondeterministic_function_handling = 'throw' passes the cache check: executeQuery supplies the original outer AST, which contains no SAMPLE, and the traversal does not inspect the view body. Repeated executions can replay one sample despite the zero-seed contract. Propagate nondeterminism from resolved reads or inspect view bodies with their effective settings. This remains part of the existing cache finding; the quoted-setting and profile reproductions are fixed.
  • src/Storages/MergeTree/BernoulliGranuleFilter.cpp:103: Mask construction ignores cancellation and execution deadlines. initializePipeline builds masks serially for all selected parts; the builder visits every mark and makes one geometric draw per sampled row without checking query status. Even SELECT x FROM t SAMPLE 0.5 LIMIT 1 on a billion-row part requires roughly 500 million draws before a source can observe cancellation. Pass query status or a callback into the builder and check it periodically during construction.
Missing context / blind spots
  • ⚠️ Findings are based on source traces; no local SQL or tests were executed. At head e2a8bff2984f, the Fast test report passes nine Bernoulli tests and skips the vector-search test. Full builds and subsequent test jobs are still pending; their completed reports would close that validation gap.
Tests
  • ⚠️ Add a stored-view regression with zero seed, subquery caching disabled, and the result-cache throw/ignore policies. It must prevent caching the outer query's random sample.
  • ⚠️ Verify that cancellation during mask construction stops the traversal before completing all selected parts.
Final Verdict

Status: ⚠️ Request changes

Handle sampling inside stored views in cache eligibility and add bounded cancellation checks to mask construction, with focused regression coverage.

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Mar 28, 2026
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@alexey-milovidov

Copy link
Copy Markdown
Member

The Can't adjust last granule error in CI is a known issue. The fix is in #101641

@alexey-milovidov

Copy link
Copy Markdown
Member

The flaky check failure is fixed in #102148, let's update the branch.

Conflicts resolved by keeping both sides: the `allow_experimental_bernoulli_sample`
extern next to master's `allow_experimental_lateral_join`, the `bernoulli_filter`
field next to master's `read_request_map` fields, and master's new
`MergeTreeReaderIndex::canSkipAnyMarkBesidesTopKPrimaryKey` together with the
PR's constructor taking a `BernoulliGranuleFilterPtr`. The new method also
reports that marks can be skipped when a Bernoulli filter is present, matching
`canSkipAnyMark`, so marks skipped by sampling are not attributed to PREWHERE
in the query condition cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass 2026-10-11 (head 9bbdb909341):

  • Merged current master (PR was CONFLICTING). Conflicts in QueryAnalyzer.cpp, MergeTreeReadTask.h and MergeTreeReaderIndex.cpp resolved by keeping both sides. master added MergeTreeReaderIndex::canSkipAnyMarkBesidesTopKPrimaryKey; it now also returns true when a Bernoulli filter is present (same as canSkipAnyMark), so marks skipped by sampling are not attributed to PREWHERE in the query condition cache.
  • Rebuilt clickhouse; the Bernoulli tests 04700, 04758, 05037, 05055, 05218 pass locally, and 04042 matches its reference up to the parallel-replicas query that needs the CI test cluster.
  • The stateless failures 05237_with_expression_alias_scope_descendant and 05213_timeseries_metric_families_target were fixed on master and come in with the merge.
  • Replied on the docs thread: the stale lines are inside the AUTOGENERATED region, and its source of truth is already updated.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101022&sha=534e03540b7f9ad78c9b327ce791ea7189cb1c78&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 (TLP WHERE oracle mismatch for SELECT * FROM t WHERE tuple(a, b) NOT IN (SELECT tuple(a, b) FROM t1__fuzz_0) WINDOW w_fuzz_430 AS (); no SAMPLE, so this PR is not involved) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

This is already fixed on master by #118957, merged 2026-10-09. That is after this report's run (2026-10-03, head 534e03540b7), and the current head 9bbdb909341 contains it.

Root cause: t1__fuzz_0 widened b to FixedString(210), but the primary key of t reads FixedString(6). Index analysis cast each subquery set element into the key type with castColumnAccurateOrNull. The zero-padded 'fd4c03' of length 210 does not fit FixedString(6), so the element was dropped as a cast failure. The not(... NOT IN ...) arm then pruned on an empty set. The server log shows Key condition: ((column 0, column 1) in 0-element set) and PK index has dropped 1/1 granules, although the row does match the set. The empty WINDOW clause plays no part. Since #118957 the index is not used for a set over a String/FixedString key when the element type is neither String nor the key's own type.

I measured it with the CI amd_release binaries in clickhouse local, using the tables from 03215_partition_in_tuple with t1.b FixedString(210):

Query 448b8797 (parent of the merge) 9fd0ee1a (merge of #118957)
TLP arms, count() (reference 2) 1 2
tuple(a, b) IN (SELECT tuple(a, b) FROM t1) 0 rows 1 row
same with use_index_for_in_with_subqueries = 0 1 row 1 row
count() with b NOT IN (SELECT b FROM t1) (truth 1) 2 1

No new PR is needed. This run is the only occurrence of this signature in CIDB in the last 30 days.

Resolve conflicts in `MergeTreeReaderIndex` and its callers: keep both the
`BernoulliGranuleFilter` from this PR and the `DeleteBitmap` filter from master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass 2026-10-19 (head 774228860d1):

  • Merged current master (the PR was CONFLICTING again). master added a DeleteBitmap row filter to MergeTreeReaderIndex (MergeTreeReadPoolBase.cpp, MergeTreeReadTask.cpp, MergeTreeReaderIndex.{h,cpp}). I resolved the conflicts by keeping both filters: the constructor now takes delete_bitmap_ followed by bernoulli_filter_, mustApplyFilter is true when either filter is set, and in readRows the Bernoulli filter is applied first (it ANDs with any filter the projection or lazy materialization already appended) and the delete bitmap is applied after it.
  • Rebuilt clickhouse. Locally 04700, 04758, 05037, 05218 and 05316 pass. 04042 and 05055 need the CI test clusters, so I could not run them.
  • 05316_top_k_primary_key_skip_query_condition_cache (amd_tsan, targeted) also fails in other PRs. It was fixed on master by Keep 64-row granules in test 05316_top_k_primary_key_skip_query_condition_cache #126583, and this merge brings that fix in.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101022&sha=9bbdb909341de4621f622b2ae370807525c88f2e&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. In 05317_local_read_throttler_filesystem_cache the throttler check returns 0 1 where the reference has 1 1. The test has no SAMPLE, so this PR is not involved. It still fails on master after #124920: it failed in PRs 124887, 106734 and 124426 between 2026-10-14 and 2026-10-18.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I'm investigating the remaining 05317_local_read_throttler_filesystem_cache failures after #124920; I'll follow up here with a PR (or my findings) shortly.

@groeneai

Copy link
Copy Markdown
Collaborator

I checked all three failures after #124920. None of them needs a new PR:

Since #124920 merged: 3 FAIL vs 46,033 OK rows on all refs; on master 4,241 OK on 372 commits (413 of them in the ParallelReplicas lane) and 0 FAIL.

alexey-milovidov and others added 2 commits October 27, 2026 06:31
# Conflicts:
#	src/Interpreters/Context.h
The `settings_changes_history` style check requires new settings to have a
record for the current version (`26.11`); `allow_experimental_bernoulli_sample`
and `bernoulli_sample_seed` were still recorded under `26.10`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101022&sha=774228860d17af67d82925e8f0de0a7cf7aa07b0&name_0=PR&name_1=Style%20check
PR: ClickHouse#101022

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

mintlify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit e2a8bff.

Approve preview

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass 2026-10-27 (head 00a39456be1):

  • Merged current master (the PR was CONFLICTING). The only conflict was in Context.h: master removed the positional_arguments_already_resolved context field (it is now passed through QueryAnalysisPass). I kept the PR's bernoulli_sample_seed field and dropped the removed one.
  • Fixed the settings_changes_history style check: allow_experimental_bernoulli_sample and bernoulli_sample_seed are now recorded under 26.11 instead of 26.10.
  • Rebuilt clickhouse. 04700, 04758 and 05037 match their references. 04042 matches up to the parallel-replicas query, which needs the CI test cluster.
  • Thanks @groeneai for the follow-ups on the 05317 and oracle failures. Both are fixed on master, so this PR needs no change for them.

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
alexey-milovidov and others added 3 commits November 4, 2026 05:29
# Conflicts:
#	src/Analyzer/Resolve/QueryAnalyzer.cpp
#	src/Interpreters/Context.h
The Bernoulli filter drops physical rows before `FINAL` merges the versions of a
key, and the masks of different versions are independent. So `FINAL` could return
an obsolete version or resurrect a key deleted by a tombstone in
`ReplacingMergeTree(ver, is_deleted)`. Reject the combination with
`SAMPLING_NOT_SUPPORTED` until sampling after the reconciliation is supported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The skip-index Top-K in `filterPartsByPrimaryKeyAndSkipIndexes` and the Top-K
entries of the query condition cache narrow the read to the granules holding the
top rows of the whole table. A Bernoulli sample drops rows after the read, so its
top rows can lie in exactly the granules they exclude. Both guards checked only
`use_sampling`, which is false for Bernoulli sampling; check
`use_bernoulli_sampling` too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
if (seed_setting != 0)
sampling.bernoulli_seed = seed_setting;
else
sampling.bernoulli_seed = context->getQueryContext()->getBernoulliSampleSeed();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Register zero-seed Bernoulli reads as nondeterministic

This branch chooses a fresh seed for each query, but astContainsNonDeterministicFunctions in QueryResultCache.cpp does not recognize Bernoulli sampling. An otherwise deterministic query such as SELECT sum(id) FROM t SAMPLE 0.1 with allow_experimental_bernoulli_sample = 1, bernoulli_sample_seed = 0, and use_query_cache = 1 is therefore admitted to the result cache even under the default query_cache_nondeterministic_function_handling = 'throw'.

The cache key hashes the AST and settings, including the literal seed setting 0, rather than the generated seed or initial query identity. A subsequent execution can consequently return the previous execution's sample result instead of drawing the documented fresh sample. This is separate from the query-condition-cache guards added elsewhere in this PR.

Please include this sampling mode in result-cache nondeterminism detection and honor the existing throw/ignore/save policy. Cover both a top-level sampled read and a sampled subquery with seed 0; explicitly seeded deterministic samples should remain cacheable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Fixed in 21375b4: astContainsNonDeterministicFunctions in QueryResultCache.cpp now reports a query as non-deterministic when it has a SAMPLE clause and the zero seed may apply. That means allow_experimental_bernoulli_sample = 1 with bernoulli_sample_seed = 0 in the query context, or a nested SETTINGS bernoulli_sample_seed = 0. The existing throw / ignore / save policy then applies. Whether the table has a SAMPLE BY key is not known at that point, so this is deliberately conservative. Added 05622_bernoulli_sample_query_result_cache, which covers a top-level sampled read, a sampled subquery, a nested-SETTINGS zero seed, and all three policies. It also checks that explicitly seeded samples stay cacheable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix in 21375b4fc58b is incomplete at src/Interpreters/Cache/QueryResultCache.cpp:323: the matcher accepts only a UInt64 literal zero, while ParserSetQuery preserves a quoted setting value as a String and fieldToNumberSettingValue accepts '0' as zero. With a nonzero outer seed, this sampled subquery therefore still bypasses the nondeterminism check:

-- t is a populated MergeTree table without SAMPLE BY.
SELECT sum(id)
FROM (SELECT id FROM t SAMPLE 0.1 SETTINGS bernoulli_sample_seed = '0')
SETTINGS allow_experimental_bernoulli_sample = 1,
         bernoulli_sample_seed = 1, use_query_cache = 1,
         query_cache_for_subqueries = 0,
         query_cache_nondeterministic_function_handling = 'throw';

A nested SETTINGS profile = '...' whose profile sets bernoulli_sample_seed = 0 also escapes this scan. Please evaluate the effective settings while descending, using the existing contextual traversal beside hasNonDeterministicObfuscate, rather than matching the literal field type. Add coverage for the quoted zero and profile forms. This is a source trace; I could not execute the SQL locally because no binary is installed and the current-head build artifact request returned HTTP 403.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Fixed in 0912a69. The Bernoulli check is now part of the contextual traversal that already tracks the effective obfuscate_seed (renamed to hasSettingsDependentNonDeterminism). A SAMPLE counts as non-deterministic when the (sub)query it belongs to effectively runs with allow_experimental_bernoulli_sample = 1 and bernoulli_sample_seed = 0, so the quoted '0' and the nested SETTINGS profile = ... forms are both caught. A nested nonzero seed under an outer zero seed is now cacheable, since the sample really is deterministic there. Added 05839_bernoulli_sample_nested_seed_query_result_cache covering the quoted zero, the profile form, profile-after-explicit-seed ordering, and the cacheable inverse cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] The settings cases are fixed, but the zero-seed cache issue remains through a stored VIEW at src/Interpreters/Cache/QueryResultCache.cpp:300. This check only recognizes a SAMPLE written in the AST being scanned. executeQuery.cpp:3786 passes the original outer AST, and the traversal never opens a referenced view's body.

For a populated MergeTree table t(id UInt64) without a sampling key:

SET allow_experimental_bernoulli_sample = 1;
CREATE VIEW v AS SELECT id FROM t SAMPLE 0.1;
SELECT sum(id) FROM v
SETTINGS bernoulli_sample_seed = 0, use_query_cache = 1,
         query_cache_for_subqueries = 0,
         query_cache_min_query_runs = 0, query_cache_min_query_duration = 0,
         query_cache_nondeterministic_function_handling = 'throw';

The outer AST contains no SAMPLE, so this returns false and permits caching a fresh random sample under a reusable key. Disabling subquery caching also prevents an inner cache check from catching it. Please propagate nondeterminism from the resolved reads, or inspect view bodies with their effective contexts, and add a stored-view regression. This is a source trace; SQL was not executed locally.

alexey-milovidov and others added 6 commits November 12, 2026 01:52
# Conflicts:
#	src/Databases/enableAllExperimentalSettings.cpp
Bernoulli sampling drops rows inside the reader after the vector similarity
index shortlisted its candidates, so a query whose only filter is `SAMPLE`
could get every shortlisted row discarded, and
`vector_search_filter_strategy = 'prefilter'` was ignored for it. Count
sampling in `additional_filters_present`, like `WHERE`, `PREWHERE` and row
policies: the prefilter strategy now falls back to the exact search, and the
postfilter strategy applies the fetch multiplier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ic in the query result cache

With `bernoulli_sample_seed = 0` every query draws a fresh sample, but the
query result cache key contains only the literal setting value, so the result
was cached and replayed. Report such queries as non-deterministic so that
`query_cache_nondeterministic_function_handling` (`throw` / `ignore` / `save`)
applies. Explicitly seeded samples stay cacheable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict in `MergeTreeReaderIndex.h`: `master` added `[[nodiscard]]` to the accessors, the PR extended
`mustApplyFilter` with the `bernoulli_filter` check. Kept both.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ettings in the query result cache

The check matched only a `UInt64` literal `0` in a nested `SETTINGS` clause, so `bernoulli_sample_seed = '0'`
or a nested `SETTINGS profile = '...'` that sets the zero seed escaped it, and such a sampled subquery was cached
as deterministic.

Fold the check into the contextual traversal which already tracks the effective `obfuscate_seed` (now
`hasSettingsDependentNonDeterminism`): a `SAMPLE` is non-deterministic when the (sub)query it belongs to runs
with `allow_experimental_bernoulli_sample = 1` and `bernoulli_sample_seed = 0`. As a side effect, a nested
nonzero seed under an outer zero seed is now correctly cacheable.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The test built an HNSW index over 20000 vectors twice (`INSERT` and `OPTIMIZE FINAL`). It takes 5-15 seconds in
regular jobs, but 300-600 seconds in every flaky check and in `amd_tsan, s3 storage, targeted`, where it failed
with `Test runs too long (> 180s)`. Use 300 rows and `SAMPLE 0.05`: the index build is about 70 times smaller,
and the test still tells the prefilter (exact search, a sampled row is returned) from the postfilter (the
shortlist is dropped by the sample).

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101022&sha=latest&name_0=PR
ClickHouse#101022

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass 2026-11-20 (head ddd7a90c24fc):

  • Merged current master (the PR was CONFLICTING). The only conflict was in MergeTreeReaderIndex.h: master added [[nodiscard]] to the accessors, and the PR extends mustApplyFilter with the bernoulli_filter check. Kept both.
  • Review thread on the query result cache: the zero-seed check now uses the effective settings of each (sub)query, so bernoulli_sample_seed = '0' and a nested SETTINGS profile = ... are caught. New test 05839_bernoulli_sample_nested_seed_query_result_cache.
  • CI: the only failing test was 05621_bernoulli_sample_vector_search with Test runs too long (> 180s). It took 5-15 seconds in regular jobs but 300-600 seconds in every flaky check and in amd_tsan, s3 storage, targeted, because it built an HNSW index over 20000 vectors twice. It now uses 300 rows and SAMPLE 0.05 and still tells prefilter from postfilter.
  • Rebuilt clickhouse locally. 04700, 04758, 05037, 05497, 05621, 05622, 05839 and the obfuscate query-cache tests 04320 and 05332 match their references. 04042 and 05055 need the CI test clusters and were not run locally.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pass 2026-11-24 (head e2a8bff2984f):

  • Merged current master (clean, no conflicts).
  • Style check / settings_changes_history: allow_experimental_bernoulli_sample and bernoulli_sample_seed were recorded under 26.11, but the current version is 26.12. Moved both records to 26.12.
  • Build (arm_tidy): marked BernoulliGranuleFilter::canSkipMark as [[nodiscard]] (modernize-use-nodiscard).
  • Built the merged tree locally and ran all ten *bernoulli* stateless tests: all pass.
  • Resolved the review thread about the query result cache and zero-seed Bernoulli SAMPLE: it was fixed in 0912a6916601, and its tests 05622_bernoulli_sample_query_result_cache and 05839_bernoulli_sample_nested_seed_query_result_cache pass on the merged tree.

size_t remaining_skip = nextGeometricSkip(rng, filter->log_one_minus_p);

size_t cumulative_row = 0;
for (size_t mark = 0; mark < num_marks; ++mark)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Make the full-part precomputation cancellable

build traverses every mark of the entire part and performs a geometric draw, including std::log, for every sampled row. ReadFromMergeTree::initializePipeline invokes it serially for every selected part before starting the read pipeline, but neither loop checks query cancellation or the execution deadline. For example, SELECT x FROM t SAMPLE 0.5 LIMIT 1 over a billion-row part performs roughly 500 million draws before any source can observe KILL QUERY or max_execution_time; cancellation still leaves the remaining precomputation running.

Please pass the query status or a cancellation callback into the builder and check it periodically during the mark/hit traversal, so cancellation can interrupt this work without waiting for all selected parts to finish.

This branch has not been deployed

No deployments
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-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-experimental Experimental Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants