Repository navigation
Conversation
|
Workflow [PR], commit [e2a8bff] Summary: ✅
AI ReviewSummaryAdds experimentally gated Bernoulli row sampling for Findings
Missing context / blind spots
Tests
Final VerdictStatus: Handle sampling inside stored views in cache eligibility and add bounded cancellation checks to mask construction, with focused regression coverage. |
|
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. |
|
The |
|
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]>
|
🕵 Pass 2026-10-11 (head
@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 |
|
This is already fixed on Root cause: I measured it with the CI
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]>
|
🕵 Pass 2026-10-19 (head
@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 |
|
Acknowledged. I'm investigating the remaining |
|
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 |
# 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]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
🕵 Pass 2026-10-27 (head
|
# 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(); |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
🕵 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
🕵 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.
There was a problem hiding this comment.
[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.
# 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]>
|
🕵 Pass 2026-11-20 (head
|
…story The `settings_changes_history` style check requires new settings to be recorded under the current version, which is now 26.12: `allow_experimental_bernoulli_sample` and `bernoulli_sample_seed` were still recorded under 26.11. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101022&sha=ddd7a90c24fcfb9931f86223cccbbe38a8a8456f&name_0=PR&name_1=Style%20check ClickHouse#101022 Co-Authored-By: Claude Fable 5.2 <[email protected]>
Fixes the `modernize-use-nodiscard` error in the `arm_tidy` builds. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101022&sha=ddd7a90c24fcfb9931f86223cccbbe38a8a8456f&name_0=PR&name_1=Build%20%28arm_tidy%2C%202%2F4%29 ClickHouse#101022 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Pass 2026-11-24 (head
|
| 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) |
There was a problem hiding this comment.
[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.
Attempt to implement sampling via geometric distribution (#85195)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Experimental. Allow
SAMPLEclause onMergeTreetables without aSAMPLE BYkey using Bernoulli row-level sampling. Enable withSET 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
Workflow [PR]
Sync PR [sync-upstream/pr/101022]