Repository navigation
Improve canceling queries in nested expression functions in FilterTransform - #112705
Conversation
…uery_condition_cache
… is live before KILL
…dd use_statistics_for_part_pruning=0
# Conflicts: # src/Common/FailPoint.cpp # src/Processors/Transforms/FilterTransform.cpp
…lsHavingTransform Address review: `FilterSortedStreamByRange` holds a private `FilterTransform` and calls its `transform` directly, but the pipeline only cancels the outer processor, so the inner `isCancelled` flag never became true and `cancelExecution` was never forwarded to functions of the filter expression. Forward the cancellation from `FilterSortedStreamByRange::onCancel`. Address review: `HAVING` evaluates its predicate in `TotalsHavingTransform` via `expression->execute` without a cancellation callback, so a long-running function in `HAVING` remained uninterruptible by `KILL QUERY` or Ctrl+C in `clickhouse-client`. Mirror the `FilterTransform` changes: cancel function execution in `onCancel`, pass a `check_cancelled` callback to `execute`, and return before the totals/filter bookkeeping when cancelled.
…sHavingTransform` Uses a new `totals_having_transform_pause` failpoint placed after the `HAVING` expression execution, mirroring the existing `04612_kill_query_filter_pause` test for `FilterTransform`.
|
Workflow [PR], commit [d81412b] Summary: ✅
AI ReviewSummaryThis PR threads processor cancellation into several expression-evaluating transforms so Findings
Final VerdictChanges requested: one previously fixed cancellation/cache race is still present on the current head. |
…filter-transform-cancel
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=112705&sha=4d90e5864c5a3e79cabf0f713a4a1486d909e8cd&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 ( |
|
The fix is already in progress: #121230 (same bug as #121254). The fatal query of this run is the SELECT [1, nan, 3, 4], number, toUInt64(-2) AS value FROM numbers(1) ORDER BY number ASC NULLS LAST WITH FILL FROM 0 TO 2 INTERPOLATE (`value` AS (value + 1 AS d) + (arrayMap(value -> moduloLegacy(d, value), [1])[1]))
CIDB: STID 1611-3fe5 has 23 failures since 2026-09-19 (20 PRs, 2 master runs), only in |
The fill loops only `break` on cancellation, and an interrupted `INTERPOLATE` leaves an empty block, which `insertFromFillingRow` turns into defaults. So a `KILL QUERY` could still publish a partial or default-filled chunk of the cancelled range. Clear the chunk in `transform` when the transform is cancelled; the soft `timeout_overflow_mode = 'break'` path keeps its partial result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-06): the only red check was |
|
🕵 Status update (2026-10-07): the only red check was
I merged current |
…s residual is evaluated Add the `iejoin_residual_before_expression_pause` failpoint right before the cancellation check in `IEJoinAlgorithm::evaluateResidualMask`, and a test that kills a `LEFT` `ie_join` parked there. The residual is a `throwIf` that fails on every pair, so evaluating it after the kill reports `FUNCTION_THROW_IF_VALUE_IS_NON_ZERO` instead of `QUERY_WAS_CANCELLED`, and emitting the batch or the unmatched rows after the kill would print rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…filter-transform-cancel Conflicts in `src/Common/FailPoint.cpp` and `TotalsHavingTransform.cpp`: master added its own cancellation checks to `TotalsHavingTransform` together with the failpoints `totals_having_transform_pause` (inside the `addToTotals` loop) and `totals_having_transform_drop_cancelled_chunk`. This PR used the same name `totals_having_transform_pause` for the pause after the `HAVING` expression, which would have made the `PAUSEABLE_ONCE` failpoint fire at the wrong place in `05317_kill_query_totals_having`. Renamed the PR's failpoint to `totals_having_transform_after_expression_pause` (and updated `04658_kill_query_having_totals_pause` and `04905_kill_query_cancelled_before_expression`), and kept both sides' cancellation checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status update (2026-10-08):
|
|
🕵 Status update (2026-10-08): every Praktika check is green on |
|
Tests for cancellations have little value. They are also slow and flaky, so the net value can be even negative. We will be okay merging without the tests as long as the code is clear. Thanks to the Stress test and Fuzzers, we, de facto, test for these paths. |
…d for them Per the review comment at #112705 (comment), tests for cancellation are slow and flaky and have little value, while the Stress tests and fuzzers already exercise these paths. Remove all the `KILL QUERY` tests added by this PR, the pause failpoints they used (including `wasm_guest_pause` and the `_wasm_signal_ready` host function with the `infinite_loop_signal` function in `faulty.wasm`), and the cancellation re-checks that existed only to close the windows opened by those failpoints. The cancellation forwarding into the expression functions and the cancellation checks around `ExpressionActions::execute` stay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Done in db07ba0: removed all 23 cancellation tests added by this PR, every pause failpoint they used (including |
|
🕵 Status update (2026-10-10): the two red checks on
Merged |
alexey-milovidov
left a comment
There was a problem hiding this comment.
This looks correct and good enough.
… mask `StringBytesUniqImpl::process` kept a 32-byte `UInt64 mask[4]` on the stack and, for every row, zeroed it with one 32-byte store, did a load-or-store per byte and reloaded all 32 bytes for the popcount. On aarch64 the speed of that per-row store/reload depends on the alignment of `mask`, which is decided by the stack depth at the call, i.e. by unrelated caller frames: `executeImpl` is identical in 8 arm builds, 4 fast and 4 slow, and the slow ones are exactly those where `mask` lands 32-byte aligned (depth at entry mod 32 = 16). ClickHouse#124599 (thread pool worker frame 592 -> 608 bytes) flipped master to fast, ClickHouse#112705 (`ExpressionTransform::transform` 400 -> 480 bytes) flipped it back to slow, so `string_bytes_functions #0` runs at 0.050 or 0.061 s per arm binary and is reported `slower` on PRs whose binary draws the other mode than its reference (21 PRs plus master in 30 days on arm_release, none on amd_release). Count with a per-call table of the last row number in which each byte value occurred instead. It is zeroed once per `executeImpl` call and never cleared between rows, so the only per-row stack traffic left is the 8-byte, 8-aligned load and store of the table entry per byte. `alignas` on `mask` was rejected: the 32-byte-aligned placement is the slow one, so it would pin every build to the slow mode. A register-resident mask was measured 1.2-1.85x slower on x86. `FunctionStringBytes::executeImpl` now calls `process` on a local `Impl`, and `StringBytesEntropyImpl::process` becomes a `const` member; entropy's machine code is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #103705
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve canceling queries by
KILL QUERYand Ctrl+C inclickhouse-clientwhile a long-running function is evaluated in a filter expression:FilterTransform(WHERE, including theFilterSortedStreamByRangepath) andTotalsHavingTransform(HAVINGwithWITH TOTALS) now forward cancellation into nested expression functions.This supersedes #103705 by @rvasin (Roman Vasin), whose commits are preserved here — all credit for the feature goes to them. The original branch is in a fork with maintainer edits disabled, so the merge conflicts with
masterand the remaining review feedback could not be pushed there.On top of the original PR, this PR:
masterand resolves the conflicts.FilterSortedStreamByRangeholds a privateFilterTransformand calls itstransformdirectly, but the pipeline cancels only the outer processor. NowFilterSortedStreamByRange::onCancelforwards the cancellation into the inner transform, socancelExecutionreaches functions of range-filter predicates fromPartsSplitter.TotalsHavingTransformevaluates theHAVINGexpression (for the main stream and the totals row) with the cancellation flag,onCancelcancels function execution, and the transform returns before the totals/filter bookkeeping when cancelled.FilterTransform,ExpressionTransformandTotalsHavingTransformfor a task that was dispatched before the cancellation and started after it.ConvertingTransform,AddingDefaultsTransform,CheckConstraintsTransform,FillingTransform(WITH FILL ... INTERPOLATE) and theIEJoinresidualJOIN ONpredicate.ExpressionActions::executetakes a pointer to the processor's cancellation flag instead of astd::functioncallback.There are no dedicated tests: per review, tests for cancellation are slow and flaky, and these paths are exercised by the Stress tests and fuzzers. The earlier
KILL QUERYtests and the pause failpoints added for them were removed.Workflow [PR]
Sync PR [sync-upstream/pr/112705]
Version info
26.10.1.2106-master(included in26.10and later)