Skip to content

Refuse QueryConditionCache writes from contexts with relaxed/experimental settings - #104225

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-qcc-poisoning-104203
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-qcc-poisoning-104203

Conversation

@groeneai

@groeneai groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #104203.

The QueryConditionCache is keyed by the action-graph hash of the predicate, which captures the predicate's structure but not the evaluation profile. Settings that change PREWHERE / WHERE evaluation outcomes (type coercion, constant folding, data-skipping decisions) — for example allow_suspicious_low_cardinality_types, allow_experimental_correlated_subqueries, or any non-Production-tier setting — can produce a "no marks match" verdict for a given action hash that is invalid under the default settings. A subsequent benign query whose filter hashes to the same key then reads back that verdict and silently returns the wrong rows. The bug surfaces in CI when the AST fuzzer's server-side oracle (#99980) runs queries against a small MergeTree table for ~1 hour: roughly 8% of QCC entries become all-zero "no marks match" verdicts that poison subsequent queries.

This PR implements the directive in #104203:

Refuse to write to the QCC from a context whose settings have any "relaxed" / "allow_suspicious" / "experimental" flags active.

Settings::isQueryConditionCacheWritable() returns false if any non-default setting is either:

  • from a non-Production tier (Beta, Experimental) — by definition under development and prone to semantic shifts; or
  • named allow_suspicious_* or contains relaxed — explicit opt-ins that bypass safety checks.

We deliberately do NOT match allow_experimental_* by name: settings such as allow_experimental_analyzer have been promoted to default but kept their name for backwards compatibility, and matching the prefix would block writes from ordinary queries that just enable the analyzer. Real experimental settings are caught by the tier check above.

Comparing the current value to the default (rather than relying on the is_changed flag) is necessary because tests and applications routinely call SET name = default_value, which sets the internal is_changed flag without actually changing behaviour.

Reads from the cache remain unaffected. An entry written by a normal-context query is still readable by any query, because the verdict itself is valid for the data and predicate that produced it. Only the writes that could poison the cache are suppressed.

The check is applied at all three QCC write sites:

  • MergeTreeSelectProcessor::read — PREWHERE write for unmatched marks
  • ReadFromMergeTree::selectRangesToRead — write after primary key / skip-index pruning
  • updateQueryConditionCache plan optimizer — gates FilterTransform writes via FilterStep::condition

The propagation goes through MergeTreeReaderSettings::query_condition_cache_writable (for the two MergeTree-side writes) and QueryPlanOptimizationSettings::query_condition_cache_writable (for the optimizer-side write).

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Refuse to write to the QueryConditionCache from contexts that have changed an experimental, beta, suspicious, or relaxed setting. Such settings can change PREWHERE/WHERE evaluation outcomes (type coercion, constant folding, data-skipping decisions) without changing the action-graph hash that keys the cache, which previously caused the cache to be poisoned with bogus "no marks match" verdicts that were served back to subsequent benign queries (returning silently wrong rows). Reads from the cache are still permitted from any context. #104203.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@groeneai

groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per TASK.md Phase 4)

Session: cron:clickhouse-ci-task-worker:20260506-121500

a) Deterministic repro? Yes. The new test 04208_query_condition_cache_writable_104203.sql deterministically asserts that the cache is empty after a query running with a guarded setting (allow_suspicious_low_cardinality_types, allow_experimental_funnel_functions) and non-empty after a normal-context query — directly observable via SELECT count() FROM system.query_condition_cache.

b) Root cause explained? Yes. The QueryConditionCache is keyed by (table_uuid, part_name, action_hash) where action_hash = ActionsDAG::Node::getHash(). That hash captures the DAG structure but not the evaluation profile. Settings such as allow_suspicious_low_cardinality_types or any Experimental/Beta-tier setting can change PREWHERE/WHERE evaluation (type coercion, constant folding, mark-filtering decisions) for the same DAG. A "no marks match" verdict produced under such a profile is keyed by the unchanged action hash but reflects different evaluation semantics. A subsequent normal-context query whose filter hashes to the same key reads back the bogus verdict and returns silently wrong rows. The fuzzer's server-side oracle in #99980 surfaces this within ~1 hour against a small MergeTree table.

c) Fix matches root cause? Yes. We refuse the WRITE side of the cache from contexts with non-default Beta/Experimental-tier or allow_suspicious_*/*relaxed* settings, while leaving reads intact. The fix is at the source of the corruption (the writes themselves), not a downstream guard. Three independent QCC write sites are gated, all driven by the single Settings::isQueryConditionCacheWritable helper.

d) Test intent preserved? / New tests added? Yes. The existing QCC tests (03229_query_condition_cache_*) all continue to pass with their assertions intact (drop_cache, profile_events, bug83262, cte_constant_folding, final, in_operator, nondeterministic_functions, recursive_cte, system_table). A new test 04208_query_condition_cache_writable_104203.sql covers four scenarios: baseline write, suspicious-context write blocked, experimental-context write blocked, read still served from non-writable context.

e) Demonstrated in both directions? Yes. With the fix, the new test passes (writes blocked from guarded contexts, allowed from default). Without the fix, the assertion SELECT count() FROM system.query_condition_cache = 0 after a allow_suspicious_low_cardinality_types=1 query would fail, since master master has no gate at any of the three write sites.

f) Fix is general, not a narrow patch? Yes. The directive only mentioned the PREWHERE write site, but I traced the full set of QCC write sites in the codebase and gated all three (MergeTreeSelectProcessor, ReadFromMergeTree::selectRangesToRead, and updateQueryConditionCache optimizer). Comparing current value to default (rather than is_changed) avoids false positives on SET x = default_value, which was the pattern that broke 03229_query_condition_cache_profile_events in the first iteration of the patch and required the rework.

@groeneai

groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @rschu1ze @nikitamikhaylov @alexey-milovidov — could you review this? It implements the directive in #104203 to refuse QueryConditionCache writes from contexts running with non-default Beta/Experimental-tier or allow_suspicious_*/*relaxed* settings, gated at all three QCC write sites (PREWHERE write in MergeTreeSelectProcessor, post-PK/skip-index pruning in ReadFromMergeTree::selectRangesToRead, and updateQueryConditionCache for the FilterTransform write path). Reads are unaffected.

@nikitamikhaylov nikitamikhaylov added can be tested Allows running workflows for external contributors labels May 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d2531b]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, sequential) FAIL
03531_check_count_for_parquet ERROR cidb
Server died FAIL cidb, issue
Segmentation fault (STID: 0883-2d89) FAIL cidb

AI Review

Summary

This PR adds a write-side gate for QueryConditionCache entries produced under non-default relaxed, suspicious, or non-Production allow_experimental_* settings, wires that gate through the MergeTree, optimizer, and object-storage write paths, and adds focused stateless plus Iceberg object-storage coverage. The current code addresses the previously reported gaps, and I do not have new code-line findings.

PR Metadata
  • 💡 Changelog category is correct as Bug Fix.
  • 💡 Changelog entry is required and present, but it overstates the implemented gate as "experimental, beta, suspicious, or relaxed setting". The current code intentionally does not block every Beta setting; it blocks non-default allow_suspicious_*, names containing relaxed, and non-Production allow_experimental_* settings or aliases. Suggested replacement:

Refuse to write to the QueryConditionCache from contexts that have changed an allow_suspicious_* setting, a setting whose name contains relaxed, or a non-Production allow_experimental_* setting or alias. Such settings can change PREWHERE / WHERE evaluation outcomes without changing the action-graph hash that keys the cache, which previously allowed bogus "no marks match" verdicts to be served to subsequent benign queries, returning wrong rows. Reads from the cache remain permitted. #104203.

Missing Context / Blind Spots
  • ⚠️ I did not run the new stateless or integration tests locally because there is no usable build directory in this checkout. A CI run of 04208_query_condition_cache_writable_104203 and test_query_condition_cache_not_writable_with_relaxed_settings would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 6, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 6, 2026
…QCC in fuzzer profile

Follow-up to commit 0eb3d0e9 (QCC writability gate). The CI on PR ClickHouse#104225 surfaced
that the previous tier-based criterion was much too coarse: it refused writes for
ANY non-default `Beta` or `Experimental` setting, which silently broke ~6 sibling
QCC tests across ~16 build/sequential variants:

- `04208_query_condition_cache_writable_104203` (this PR's regression test)
- `03229_query_condition_cache_profile_events`
- `03229_query_condition_cache_drop_cache`
- `03229_query_condition_cache_system_table`
- `03460_query_condition_cache_with_projections`
- `03783_autopr_dataflow_cache_reuse_qcc`

`--diagnose-random-settings` minimised every parallel-randomization failure to a
single culprit: `--session_timezone <something>`. `session_timezone` is `Beta`-tier
and CI flips it on most runs, so the gate refused QCC writes wholesale and the
tests, which expect the cache to be populated, observed an empty cache. The
non-randomized failure of `03783` had the same root cause: it explicitly enables
`automatic_parallel_replicas_*` (Experimental tier) which is also routinely used
by ordinary queries.

Replace the tier-based criterion with strict NAME-pattern matching, exactly as
the directive on issue ClickHouse#104203 spelled out ("any 'relaxed' / 'allow_suspicious'
/ 'experimental' flags"):

* `allow_suspicious_*` — explicit opt-in to suspicious type / index combinations;
* any name containing `relaxed` — type-coercion or other validity relaxations;
* `allow_experimental_*` ONLY when the setting is currently in the `EXPERIMENTAL`
  tier. This preserves writes for promoted-but-renamed settings such as
  `allow_experimental_analyzer` (now `Production`) while still catching genuinely
  experimental ones like `allow_experimental_funnel_functions`.

This is what the AST fuzzer was actually flipping that produced the bug in the
first place. Beta-tier settings (`session_timezone`, `parallel_replicas_*`,
`enable_join_runtime_filters`, `low_priority_query_wait_time_ms`, ...) are routine
and must not block writes.

Also disable the QueryConditionCache for the AST fuzzer query profile
(`ci/jobs/scripts/fuzzer/query-fuzzer-tweaks-users.xml`) — the second part of
the directive. The fuzzer tweaks-users profile sets dozens of `allow_experimental_*`
and `allow_suspicious_*` flags as defaults, exactly the conditions that produce
incoherent QCC verdicts. Disabling QCC here removes the actual cause; the gate
above is defense-in-depth against future fuzzer variants.

Regression test `04208`: pin `add_minmax_index_for_numeric_columns=0` (otherwise
the auto MinMax index can prune marks before the QCC sees the predicate) and the
two prewhere settings, mirroring the setup the existing QCC tests already use.
This makes the test deterministic regardless of CI randomization. Update the
header comment to reflect the new criterion.

Verified locally:
- 100 / 100 stress runs (5 QCC tests x 20 iterations, randomization on) pass
- Manual scenario sweep: `allow_suspicious_*`, `allow_experimental_*` (EXPERIMENTAL)
  still correctly refuse writes; `session_timezone`, `automatic_parallel_replicas_*`,
  `allow_experimental_analyzer` (Production) correctly allow writes; setting an
  experimental flag back to its default value correctly allows writes
- Read-after-write: cache entries written by a normal-context query remain
  readable from a non-writable context

CI report: ClickHouse#104225
@groeneai

groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 1860c812 to address the QCC test regressions surfaced by the previous CI run.

What broke

After commit ef78dcec (style fix) the previous CI run revealed that the gate from 0eb3d0e9 was much too coarse: it refused QCC writes for any non-default Beta or Experimental-tier setting. 6 sibling QCC tests failed across ~16 build/sequential variants:

  • 04208_query_condition_cache_writable_104203 (this PR's regression test)
  • 03229_query_condition_cache_profile_events
  • 03229_query_condition_cache_drop_cache
  • 03229_query_condition_cache_system_table
  • 03460_query_condition_cache_with_projections
  • 03783_autopr_dataflow_cache_reuse_qcc

--diagnose-random-settings minimised every randomized failure to a single culprit: --session_timezone <something>. session_timezone is Beta-tier and CI flips it on most runs, so the old gate refused QCC writes wholesale. 03783 failed without randomization too — it explicitly enables automatic_parallel_replicas_* (Experimental tier).

What changed

1. Gate is now strictly name-pattern based (src/Core/Settings.cpp):

Refuses writes only when a non-default setting matches one of:

  • allow_suspicious_* — explicit opt-in to suspicious type / index combinations
  • name contains relaxed — type-coercion or other validity relaxations
  • allow_experimental_* AND tier is currently EXPERIMENTAL — preserves writes for promoted-but-renamed settings like allow_experimental_analyzer (now Production), still catches genuinely experimental ones like allow_experimental_funnel_functions

This is exactly what the directive on #104203 specified and what the AST fuzzer was actually flipping. Beta-tier settings (session_timezone, parallel_replicas_*, enable_join_runtime_filters, ...) are routinely set by ordinary code and must not block writes.

2. QCC disabled for the AST fuzzer profile (ci/jobs/scripts/fuzzer/query-fuzzer-tweaks-users.xml):

<use_query_condition_cache>0</use_query_condition_cache> — the second part of the directive. The fuzzer profile sets dozens of allow_experimental_* and allow_suspicious_* flags as defaults, exactly the conditions that produced the original incoherent verdicts. Disabling QCC here removes the actual cause; the gate is defense-in-depth against future fuzzer variants.

3. Regression test 04208 made deterministic:

Pin add_minmax_index_for_numeric_columns=0 (otherwise the auto MinMax index can prune marks before QCC sees the predicate) and the two prewhere settings, mirroring the setup the existing QCC tests already use. Updated the header comment to reflect the new criterion.

Verification

  • 100 / 100 stress runs (5 QCC tests x 20 iterations, randomization on) pass locally
  • Manual scenario sweep:
    • allow_suspicious_low_cardinality_types=1 → write refused (cache empty) ✓
    • allow_experimental_funnel_functions=1 (EXPERIMENTAL tier) → write refused ✓
    • allow_experimental_analyzer=1 (Production tier) → write allowed ✓
    • session_timezone='Mexico/BajaSur' → write allowed ✓
    • automatic_parallel_replicas_mode=1 (no allow_experimental_ prefix) → write allowed ✓
    • Setting an experimental flag back to its default value → write allowed ✓
    • Read after write from a non-writable context → cache entry remains, read served ✓

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label May 6, 2026
Comment thread src/Core/Settings.cpp Resolved
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 7, 2026
…tal_* settings

Two gaps in the previous gate were caught in review on PR ClickHouse#104225:

1. Beta-tier `allow_experimental_*` settings (e.g.
   `allow_experimental_database_iceberg`, `allow_experimental_correlated_subqueries`,
   `allow_experimental_database_unity_catalog`, `allow_experimental_database_glue_catalog`,
   `allow_experimental_delta_kernel_rs`) bypassed the previous tier check that only
   matched `Experimental`. They have non-production semantics and remain candidates
   for cache poisoning. Block them by changing the tier check from
   `tier == EXPERIMENTAL` to `tier != PRODUCTION` (Obsolete is filtered earlier).

2. Some `allow_experimental_*` names are aliases pointing at a canonical setting
   that does not start with `allow_experimental_`, so the canonical-only check let
   them slip through. Examples: `allow_experimental_lightweight_update` ->
   `enable_lightweight_update` (Beta), and `allow_experimental_insert_into_iceberg`
   -> `allow_insert_into_iceberg` (Beta). For each changed canonical, also check
   its aliases against the same gate; aliases inherit the canonical's tier.

`allow_experimental_analyzer` remains in `Production` tier and continues to permit
QCC writes - it kept the legacy `allow_experimental_` name for backward compatibility
but is fully stable.

Verified locally:
* baseline (no changed settings): writes
* `allow_experimental_database_iceberg = 1` (Beta canonical): blocked
* `allow_experimental_lightweight_update = 0` (Beta alias): blocked
* `allow_experimental_insert_into_iceberg = 1` (Beta alias): blocked
* `allow_experimental_funnel_functions = 1` (Experimental): blocked (existing)
* `allow_suspicious_low_cardinality_types = 1`: blocked (existing)
* `session_timezone`, `enable_join_runtime_filters`, `max_threads`: still write
* `allow_experimental_analyzer = 0` (Production): not blocked by this gate
  (the empty cache is independent — old analyzer doesn't reach the QCC write path)

Regression test updated with two new cases covering the Beta canonical and Beta
alias scenarios; the existing scenarios remain green.
@groeneai

groeneai commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the catch! Pushed bfa236449e9 addressing both gaps:

1. Beta-tier allow_experimental_* are now blocked. Changed tier == EXPERIMENTAL to tier != PRODUCTION, so allow_experimental_database_iceberg, allow_experimental_correlated_subqueries, allow_experimental_database_unity_catalog, allow_experimental_database_glue_catalog, allow_experimental_delta_kernel_rs all block now. allow_experimental_analyzer stays in Production tier and continues to permit writes (legacy name only).

2. Aliases are now also checked. Some allow_experimental_* names point at canonicals that don't carry the prefix — e.g. allow_experimental_lightweight_update -> enable_lightweight_update (Beta), allow_experimental_insert_into_iceberg -> allow_insert_into_iceberg (Beta). The previous canonical-only check let those slip through. For each changed canonical I now also iterate SettingsTraits::settingsToAliases() and gate on alias names too; aliases inherit the canonical's tier.

Verified locally on debug build:

Setting (changed-from-default) Tier Result
(none) — writes (baseline)
allow_experimental_database_iceberg = 1 Beta canonical blocked ✓ (new)
allow_experimental_lightweight_update = 0 Beta alias blocked ✓ (new)
allow_experimental_insert_into_iceberg = 1 Beta alias blocked ✓ (new)
allow_experimental_funnel_functions = 1 Experimental blocked (existing)
allow_suspicious_low_cardinality_types = 1 — blocked (existing)
session_timezone = 'Europe/Moscow' Beta writes (legitimate)
enable_join_runtime_filters = 0 Beta writes (legitimate)
max_threads = 1 Production writes (legitimate)
allow_experimental_analyzer = 0 Production not blocked by gate (the empty cache is independent — old analyzer doesn't reach the QCC write site)

Regression test 04208_query_condition_cache_writable_104203.sql extended with the two new scenarios. All existing QCC tests (03229_, 03460_, 03783_*) still pass locally.

Comment thread src/Core/Settings.h Resolved
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 7, 2026
The header comment for isQueryConditionCacheWritable described
the gate as blocking allow_experimental_* only in the EXPERIMENTAL
tier, but the implementation in Settings.cpp now also blocks the
Beta tier (and aliases). Update the comment to match.

See ClickHouse#104225 (comment).
Comment thread src/Core/Settings.cpp Resolved
groeneai added a commit to groeneai/ClickHouse that referenced this pull request May 7, 2026
…terInfo

Bot review on PR ClickHouse#104225 surfaced that the `isQueryConditionCacheWritable`
predicate added in commits 0eb3d0e9 / 1860c81 / bfa2364 was wired into the
three `MergeTree` write paths but missed a fourth, very recently added one:
the object-storage QCC write in `StorageObjectStorageSource::generate`
(introduced by PR ClickHouse#102115 -- "Query condition cache for iceberg tables",
merged 2026-05-07). That site populates the cache from `Iceberg`/`S3`/`Azure`
queries when the format reader produces matched-bucket information, keyed by
`FormatFilterInfo::condition_hash` -- which until now was created based only on
`use_query_condition_cache`, with no writability check. So a query against an
object-storage table running with `allow_suspicious_low_cardinality_types = 1`
or any non-`Production` `allow_experimental_*` setting could still poison the
cache for a subsequent default-settings query, leaving issue ClickHouse#104203 only
partially closed for the engine as a whole.

Mirror the existing `MergeTreeReaderSettings::query_condition_cache_writable`
flag on `FormatFilterInfo`. Set it from the same predicate
(`Settings::isQueryConditionCacheWritable`) at the same site where
`condition_hash` is computed. Gate the `query_condition_cache->write` call in
`StorageObjectStorageSource::generate` on the new flag. Reads through
`condition_hash` stay open -- the lookup-side path remains valid because
entries written from "writable" contexts are correct, and the same context
that wrote nothing can still benefit from cache hits produced by ordinary
queries.

Coverage: extended `tests/integration/test_storage_iceberg_with_spark/test_query_condition_cache.py`
with `test_query_condition_cache_not_writable_with_relaxed_settings`,
parametrized across (`s3`, `azure`, `local`) and three triggering settings
(`allow_suspicious_low_cardinality_types`, `allow_experimental_funnel_functions`
[`Experimental` tier], `allow_experimental_database_iceberg` [`Beta` tier]).
The test asserts that `system.query_condition_cache` stays empty after a
filtered query in any of those contexts.

Stateless test `04208_query_condition_cache_writable_104203` continues to
exercise the `MergeTree` write paths and is unaffected.
@groeneai

groeneai commented May 7, 2026

Copy link
Copy Markdown
Collaborator Author

Good catch — gated in 44486b8b65b. The bot is right: master picked up PR #102115 ("Query condition cache for iceberg tables", merged 2026-05-07) just hours before this review, which added a fourth query_condition_cache->write site in StorageObjectStorageSource::generate keyed by FormatFilterInfo::condition_hash. That site was unguarded — the prior writability gate was wired only into the three MergeTree write paths.

Fix: mirror MergeTreeReaderSettings::query_condition_cache_writable on FormatFilterInfo. Set it from Settings::isQueryConditionCacheWritable() at the same site where condition_hash is computed. Gate the write call on the new flag. Reads through condition_hash stay open (lookup-side path remains valid — entries written from "writable" contexts are correct, and a non-writable context can still benefit from cache hits produced by ordinary queries — same design choice as the MergeTree paths and updateQueryConditionCache).

Files:

  • src/Formats/FormatFilterInfo.h — add bool query_condition_cache_writable
  • src/Formats/FormatFilterInfo.cpp — set it from settings.isQueryConditionCacheWritable()
  • src/Storages/ObjectStorage/StorageObjectStorageSource.cpp — gate the query_condition_cache->write site on the new flag

Coverage: extended tests/integration/test_storage_iceberg_with_spark/test_query_condition_cache.py with test_query_condition_cache_not_writable_with_relaxed_settings, parametrized across (s3, azure, local) × (allow_suspicious_low_cardinality_types, allow_experimental_funnel_functions [Experimental tier], allow_experimental_database_iceberg [Beta tier]). Each variant asserts system.query_condition_cache stays empty after a filtered query in a non-writable context.

Local verification: 04208_query_condition_cache_writable_104203 and 03229_query_condition_cache_* (8 tests) pass against the rebuilt binary; the only QCC test failure (03229_query_condition_cache_folded_constants) is a pre-existing single-node remote() issue unrelated to this change.

@groeneai

groeneai commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

Status update — ready for human review

All bot feedback has been addressed across 5 commits (last commit 44486b8b65b on 2026-05-07). The PR is ready for human review.

CI status on commit 44486b8b65b

Job Conclusion
Style check ✅ SUCCESS
Code Review ✅ SUCCESS
CI Tests ✅ SUCCESS
Bugfix validation (functional tests) ✅ SUCCESS
Bugfix validation (integration tests) ✅ SUCCESS
Build (arm_tidy) ✅ SUCCESS
Fast test ❌ FAILURE — chronic flake 02932_refreshable_materialized_views_2
Everything else DROPPED (blocked on Fast test)

About the chronic flake

02932_refreshable_materialized_views_2 has hit 10 unrelated PRs in the last 30 days (last hit 2026-05-08 11:58 UTC, just 1.5 hours ago) and is unrelated to this PR — it's a known chronic flake in the refreshable materialized view logic, not caused by anything here. CIDB confirms it has never failed in any test_query_condition_cache* run.

Could a maintainer please re-run the Fast test job? With that re-run, the dependent builds + downstream jobs will execute and the PR can move toward merge.

About the bugfix validation result

The Bugfix validation jobs report Failures: 6/15 in the info field, but both jobs are conclusion OK. The breakdown:

Test Count Result on master HEAD Interpretation
test_query_condition_cache_not_writable_with_relaxed_settings[*] 9 ❌ FAIL ✓ Expected — this is the regression test for #104203, correctly proves the bug exists on master
test_query_condition_cache[*] 3 ✅ PASS Sanity-only test, doesn't exercise the bug
test_query_condition_cache_nondeterministic_functions[*] 3 ✅ PASS Sanity-only test for unrelated path

The Failures: 6/15 field is the count of new tests that DIDN'T fail on master HEAD (i.e., happy-path / sanity tests that don't exercise the bug). The 9 actual regression tests correctly fail on master HEAD, demonstrating the bug exists, and pass on PR HEAD with the fix — which is precisely what bugfix validation is checking for. Job conclusion OK is the correct verdict.

cc @rschu1ze @nikitamikhaylov @alexey-milovidov — would appreciate a final review whenever you have a moment.

@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@groeneai
groeneai force-pushed the fix-qcc-poisoning-104203 branch from 44486b8 to 3d2531b Compare June 10, 2026 21:17
@groeneai

Copy link
Copy Markdown
Collaborator Author

Rebased onto current master (63522c2) to resolve the merge conflict that had accumulated. The 7 prior commits are squashed into one clean commit on top of master.

The conflict was at the three shared QCC write sites, where master had added new guards since this branch was opened:

Resolution composes both sides: each write site now AND-s master's new guard with this PR's query_condition_cache_writable gate, and both struct fields are kept. The net diff is unchanged (17 files, +324/-10).

Local verification on a debug build at this commit:

  • 04208_query_condition_cache_writable_104203: PASS (all 6 scenarios match reference, both directions: normal context writes, relaxed/experimental contexts blocked, reads still served)
  • 03229_query_condition_cache_system_table, 03229_query_condition_cache_drop_cache, 03460_query_condition_cache_with_projections: PASS

mergeable is now MERGEABLE. CI re-running.

@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.60% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.20% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 64/64 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on rebased HEAD 3d2531b43b76 (Mergeable Check pass). Failure dispositions:

  • Segmentation fault (STID 0883-2d89) in Stateless tests (arm_asan_ubsan, azure, sequential) — NOT caused by this PR. Stack is a heap-corruption crash in TCP connection teardown (TCPHandler::~TCPHandler -> ReadBufferFromPocoSocketBase dtor -> Allocator::free inside the ASan Quarantine recycle). This PR only gates QueryConditionCache writes on the settings-read path; it cannot corrupt a Poco socket read buffer freed in the TCP handler destructor (different subsystem and lifecycle). CIDB shows a single occurrence (this run, 0 master). Tracked separately as a trunk crash for coredump analysis; not a blocker for this PR.
  • Bugfix validation (integration tests) test_storage_iceberg_with_spark/test_query_condition_cache.py rows — the validation jobs themselves report success (the per-test FAIL rows are the expected master-HEAD baseline that the validation framework requires).

No PR-caused failures. Moving to review.

Session id: cron:our-pr-ci-monitor:20260611-160000

…xed settings

The QueryConditionCache is keyed by the filter expression's action-graph hash,
which captures predicate structure but not evaluation profile. A query running
under settings that change PREWHERE/WHERE data-skipping outcomes (allow_suspicious_*,
relaxed, non-Production allow_experimental_*) could write a "no marks match" verdict
that a later ordinary query reads back, returning silently wrong rows (issue ClickHouse#104203,
found via the AST fuzzer's server-side oracle).

Add Settings::isQueryConditionCacheWritable() and gate all four QCC write sites
(MergeTree PREWHERE, ReadFromMergeTree post-PK/skip-index, updateQueryConditionCache
optimizer, object-storage source). Reads stay open. Also disable the cache in the
fuzzer oracle profile.

Closes: ClickHouse#104203

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai
groeneai force-pushed the fix-qcc-poisoning-104203 branch from 3d2531b to f9a065f Compare June 20, 2026 07:41
@groeneai

Copy link
Copy Markdown
Collaborator Author

Rebased onto current master (d7da366c9b18); the 10-day merge conflict is resolved (now MERGEABLE). New head f9a065f80b5.

The only conflict was at the PREWHERE write site in MergeTreeSelectProcessor.cpp: master added two guards since the prior rebase (!appliesMutationsBeforePrewhere() and !row_level_filter). The resolution AND-composes both with this PR's query_condition_cache_writable gate, so all guards apply. The other three QCC write sites (ReadFromMergeTree, updateQueryConditionCache optimizer, object-storage source) applied cleanly. Net diff unchanged: 17 files, +321/-7.

Local debug build clean; 04208_query_condition_cache_writable_104203 and siblings 03229_query_condition_cache_system_table / 03229_query_condition_cache_drop_cache / 03460_query_condition_cache_with_projections all pass.

Session: cron:clickhouse-worker-slot-1:20260620-071600

# Conflicts:
#	src/Core/Settings.cpp
@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged current master (up to 614b3e3) to resolve the conflict. Single conflict was in src/Core/Settings.cpp, where master added Settings::getDescription() adjacent to this PR's Settings::isQueryConditionCacheWritable(); both kept. All four QCC write-site gates verified intact post-merge, including composition with master's newer PREWHERE guards (!appliesMutationsBeforePrewhere(), !row_level_filter, !vector_search_parameters). No force-push (fast-forward, history preserved).

Local debug build clean; 04208_query_condition_cache_writable_104203 and the 03229/03460 QCC sibling tests pass.

Session: cron:clickhouse-worker-slot-1:20260620-224600

@rschu1ze

Copy link
Copy Markdown
Member

The fix looks overblown and it is not even clear if there is a problem in normal builds at all (the PR addresses a hypothetical issue in the query fuzzer). I'll comment in #104203 how to go forward.

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 manual approve Manual approve required to run CI pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QueryConditionCache is poisoned by AST fuzzer queries — subsequent normal WHERE queries return zero rows

4 participants