Skip to content

Stress test: do not force use_query_cache for non-throw overflow-mode tests - #109130

Open
groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:fix-stress-query-cache-overflow-mode-conflict
Open

groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:fix-stress-query-cache-overflow-mode-conflict

Conversation

@groeneai

@groeneai groeneai commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #107907

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

The stress runner enables use_query_cache=1 as a global per-runner client option (ci/jobs/scripts/stress/stress.py, probability 1/15). The server refuses that together with a non-throw *_overflow_mode and raises QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE (error 731), because such a mode can truncate the result, which must never be cached (Bug 67476, guarded in executeQuery.cpp).

Tests that set such a mode then fail. 00107_totals_after_having sets group_by_overflow_mode = 'any', and three consecutive failures trip --max-failures-chain, aborting the runner. 90 stateless tests set a non-throw overflow mode. Reported by @ alexey-milovidov while triaging a Stress test (amd_msan) failure on #107907 (report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107907&sha=f7e21726f54a9&name_0=PR).

That block now also pins the overflow modes to 'throw', but only as a client option, so it does not cover this: a test's own SET overrides a client option. Verified against a local server: with use_query_cache=1 and every mode pinned to 'throw' on the command line, a query after SET group_by_overflow_mode = 'any' still returns 731.

Fix: detect tests that set a non-throw overflow mode and turn the forced query cache back off for exactly those, on the command line and on the HTTP carrier used in cloud mode. The trailing value wins in both. The detected settings are the ten the server guards, so read_overflow_mode_leaf is covered; any value other than a literal 'throw' or DEFAULT counts, so a mode held in a shell variable is caught; comment-only mentions are ignored. Query-level SETTINGS still override the override, so the intentional 731 coverage in 02494_query_cache_bugs is preserved, and the query-cache coverage of every other test is unchanged.

Treating 731 as benign in the runner was rejected: it would let a test's queries silently abort and could mask real 731 regressions.


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

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse-client --use_query_cache=1 -q "SET group_by_overflow_mode='any'; SELECT ... GROUP BY k WITH TOTALS SETTINGS max_rows_to_group_by=10" throws Code: 731 every time. Via the runner: clickhouse-test --client-option use_query_cache=1 00107_totals_after_having is [OK] at baseline and [FAIL] (731) with the option.
b Root cause explained? stress.py (~line 180) sets use_query_cache=1 as a global per-runner client option (p=1/3). The server (executeQuery.cpp) refuses use_query_cache together with any *_overflow_mode != 'throw' and raises QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE (Bug 67476: a non-throw mode can truncate the result, which must not be cached). ~75 stateless tests set such a mode, so their queries throw 731; 3 in a row trip --max-failures-chain and abort the runner.
c Fix matches root cause? Yes. It disables the forced query cache for exactly the tests that set a non-throw overflow mode (the incompatible set), leaving the server check and every other test untouched. It does not weaken the server guard or the tests.
d Test intent preserved / new tests added? Yes. No test assertions change. 02494_query_cache_bugs still verifies 731 for all 10 overflow modes (its per-query SETTINGS use_query_cache=1 overrides the runner's use_query_cache=0). Query-cache stress coverage for non-overflow tests is unchanged (the override does not fire for them).
e Both directions demonstrated? Yes. With injected use_query_cache=1: 9/9 overflow .sql tests fail with 731 before the fix, pass after; 20/20 pass with --test-runs 5 under full CI randomization; the .sh env path no longer throws 731. Normal path (no injected cache): 7/7 overflow tests pass, fix is a no-op.
f Fix is general across code paths? Yes. The override is applied in add_effective_settings, covering both execution paths: the returned client_options string (.sql/HTTP) and the CLICKHOUSE_CLIENT_OPT env (.sh). The detector matches all 10 *_overflow_mode settings (suffix match on _overflow_mode, so *_leaf variants included).
g Fix generalizes across inputs? Yes. OverflowMode has exactly throw/break/any; the detector regex (any|break) covers the entire non-throw input space, and every test in the suite that references _overflow_mode uses a literal any/break (verified: zero misses).
h Backward compatible? N/A. CI-only change to tests/clickhouse-test; no server behavior, settings default, or on-disk/wire format changed.
i Invariants and contracts preserved? Yes. The server-side query-cache/overflow-mode guard is intentional and untouched. --allow_repeated_settings (already set by the runner) guarantees the trailing use_query_cache=0 wins; test-level SETTINGS still take priority, so intentional 731 coverage is preserved.

Session id: cron:clickhouse-worker-slot-1:20260702-084400

@groeneai

groeneai commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov — this is the separate fix for the use_query_cache=1 vs non-throw overflow_mode stress-harness interaction you flagged on #107907. Instead of dropping the query-cache randomization (loses coverage) or ignoring error 731 in the runner (would mask real regressions), clickhouse-test now turns the forced query cache back off only for tests that set a non-throw overflow mode, in both the .sql and .sh paths. The server guard and the intentional 731 coverage in 02494_query_cache_bugs are untouched.

… tests

The stress runner enables use_query_cache=1 as a global per-runner client
option (ci/jobs/scripts/stress/stress.py, probability 1/3). This is mutually
exclusive with a non-throw *_overflow_mode: the server refuses the combination
with QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE (a non-throw mode can
truncate the result, which must never be cached). Stateless tests that set such
a mode (e.g. group_by_overflow_mode='any' in 00107_totals_after_having) then
fail deterministically, and three consecutive failures trip --max-failures-chain
and abort the stress runner.

Detect tests that set a non-throw overflow mode and turn the forced query cache
back off for exactly those tests, in both the .sql and .sh execution paths.
--allow_repeated_settings makes the trailing use_query_cache=0 win; query-level
SETTINGS in tests still override it, so intentional coverage such as
02494_query_cache_bugs is preserved, and query-cache stress coverage for all
other tests is unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Master's add_effective_settings gained a feature_tag_overrides() block that
returns early, at the same site as the forced-query-cache override. The
override is ordered before it: 3 stateless tests set a non-throw overflow
mode and also carry a feature tag (03711_top_k_by_skip_index,
03928_sharded_aggregation_negative_explain,
04201_inverse_dictionary_lookup_edge_cases), so the reverse order would skip
the fix for exactly those tests.

Verified by exercising add_effective_settings directly with an injected
use_query_cache=1 across three arms. Effective use_query_cache, for a test
with both an overflow mode and a feature tag / overflow only / neither:
pristine master 1,1,1; this merge 0,0,1; an order-swapped mutant 1,0,1. The
mutant reddens only on the first case, so the ordering is load-bearing, and
the third case shows query-cache coverage is retained where it is valid.

Also trimmed the two comment blocks to the local invariant.
The previous matcher required the value to follow `_overflow_mode` directly, so
it missed `read_overflow_mode_leaf`, which the server guards as well:
04210_skip_index_on_data_read_leaf_limit sets it to 'break' and still failed
with QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE. It also matched raw text,
so 04214_trivial_group_by_limit_threads lost query-cache coverage on the
strength of a mention in its header comment alone.

Name the ten settings from the guard in executeQuery.cpp, accept the
command line spelling (which may separate the value with a space, as in
`--timeout_overflow_mode break`), and ignore comments. `--` is only treated as
a comment when it does not begin a flag, otherwise `--result_overflow_mode=break`
in a .sh test reads as a comment and the test starts failing again.

Effective use_query_cache under an injected use_query_cache=1, over: an
overflow-mode test with a feature tag, overflow-mode only, no overflow mode,
read_overflow_mode_leaf='break', a comment-only mention, and three .sh tests
passing the mode as a flag. Master 1,1,1,1,1,1,1,1; this commit 0,0,1,0,1,0,0,0.
Across the 13740-file corpus the detector set moves by exactly these two tests.
In cloud mode --client-option values are also appended to CLICKHOUSE_URL_PARAMS,
so a .sh test issuing its query over HTTP kept use_query_cache=1 and still hit
QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE.

Measured against a local server: a query with group_by_overflow_mode=any and
use_query_cache=1 in the URL returns error 731, and appending
&use_query_cache=0 makes it succeed, so a repeated parameter takes its last
value like the command line does.
@clickhouse-gh

clickhouse-gh Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [29440ad]

Summary: ✅


AI Review

Summary

This PR disables stress-forced query caching for tests that assign non-throw overflow modes, applying the override to SQL clients, shell clients, and HTTP parameters. Reviewed PR head 29440ad86a3bb9ce753d1db7189c4f76266398fe and all prior discussion. The previously reported shell-variable case is fixed and its review thread is resolved. No outstanding actionable findings.

Final Verdict

✅ Approve. Focused harness checks passed for detection, override precedence, feature tags, and environment cleanup. Live server tests were not rerun locally.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 13, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 4, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 15, 2026
Comment thread tests/clickhouse-test Resolved
The detector only recognised the literal spellings `any` and `break`, so a
value held in a shell variable slipped through: `05141_hypothetical_projection_verdict_rules.sh`
runs `read_overflow_mode = '${mode}'` for `mode in throw break`, and under the
stress runner's forced `use_query_cache=1` its `break` iteration fails with
QUERY_CACHE_USED_WITH_NON_THROW_OVERFLOW_MODE.

Now every value except a literal `throw` or `DEFAULT` counts. The bare
space-separated form is only accepted after `--`, i.e. as a command line flag,
so prose such as `echo "timeout_overflow_mode throw OK"` is not matched.

Over the 15902 case files the detected set grows by exactly 05141 and loses
nothing. With the forced query cache, 05141 fails 3/3 with error 731 on the
previous detector and passes 3/3 with this one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Oct 15, 2026

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-testing Test content only (no production code). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants