Repository navigation
Conversation
|
@tiandiwonder, @scanhex12, @vdimir could you please assign Note: in this PR I am using a simple functional test as in other tests for query cancellation:
If needed I may rewrite it into integration test to check as cancellation path. |
|
Workflow [PR], commit [485162b] Summary: ❌
AI ReviewSummaryThe PR adds cancellation polling to the hash-based Findings
Tests
Final Verdict |
There was a problem hiding this comment.
Pull request overview
This PR reduces query cancellation latency for the fallback DistinctTransform by adding in-loop cancellation checks, so KILL QUERY / client cancel can interrupt DISTINCT processing without waiting for a full chunk to finish.
Changes:
- Add cancellation checks inside
DistinctTransformhot loops (including LowCardinality optimization path) and at the start oftransform. - Add a stateless query test that starts a large DISTINCT query and cancels it via
KILL QUERY. - Add the expected output reference for the new test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Processors/Transforms/DistinctTransform.cpp |
Adds cancellation checks so DISTINCT processing can be interrupted during per-row work within a chunk. |
tests/queries/0_stateless/04411_kill_query_distinct_transform.sh |
Introduces a regression test that launches a heavy DISTINCT query and cancels it. |
tests/queries/0_stateless/04411_kill_query_distinct_transform.reference |
Expected output (OK) for the new test. |
…e TIMEOUT_EXCEEDED
…e unreliable functional test
|
@scanhex12 could you please review the PR again? The failed tests are not related. |
…d surface gRPC cancels to inner executors
…t a raw QUERY_WAS_CANCELLED as a clean cancel
…es to master state
| else | ||
| { | ||
| for (size_t i = 0; i < rows; ++i) | ||
| for (size_t begin = 0; begin < rows; begin += CANCELLATION_POLL_ROWS) |
There was a problem hiding this comment.
[P2] Bound fixed-key preparation as well as insertion
For an unsorted DISTINCT over two UInt64 columns, Method::State at line 286 is HashMethodKeysFixed. Its constructor calls packFixedBatch over every row in the chunk before either of these new polling loops is reached. A KILL QUERY received during that allocation/packing pass therefore still waits for the whole chunk, contrary to the stated one-batch cancellation bound. The single-number and LowCardinality test cases do not exercise this preparation path.
Please make preparation interruptible too, for example by constructing ColumnsHashing::SubRangeState for each polled row batch, and add focused coverage for a composite fixed-width key.
| if (!can_insert && key_columns_pos.size() == 1) | ||
| { | ||
| lc_mask = lc_filter.buildMaskIfApplicable(*column_ptrs[0], num_rows); | ||
| lc_mask = lc_filter.buildMaskIfApplicable(*column_ptrs[0], num_rows, cancellation_flag); |
There was a problem hiding this comment.
[P2] Stop cancelled LC prepasses before intersecting full-chunk masks
For a single LowCardinality(Nullable(...)) key with skip_null_keys = true (the preliminary IN set-build path), markLowCardinalityNullRows creates a nonempty keep mask when the chunk contains a NULL. If cancellation is observed during that scan or during buildMaskIfApplicable, the latter can return a nonempty, partially built lc_mask. Execution then still runs the num_rows-iteration mask intersection at lines 664–667 before reaching the cancellation return at line 700. Cancellation during the intersection is likewise only observed after the whole scan. Thus a large chunk still incurs whole-chunk work after cancellation, despite the new 4096-row polling bound.
Return immediately after a prepass observes cancellation, and poll the mask intersection in batches too. Please cover a single nullable LowCardinality key with skip_null_keys: the new two-key LC-null test bypasses the single-key mask optimization, and the plain LC tests have no keep mask.
Description
Reduces the cancellation latency of
DISTINCTqueries that deduplicate with the hash-setDistinctTransform(the fallback used when the input is not sorted). Before this change the transform only observed cancellation between chunks: once it started hashing a large chunk,KILL QUERY(and cancellation in general) had to wait for the whole hash table build of that chunk to finish. Now the transform polls the query cancellation flag inside its row loops and stops within one batch of rows.Related: #111061
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduced cancellation latency of
DISTINCTqueries that use the hash-setDistinctTransform:KILL QUERYnow interrupts hash table construction within a single chunk instead of finishing the current chunk first.Workflow [PR]
Sync PR [sync-upstream/pr/108588]