Skip to content

Fix FutureSet identity mismatch in TTLDeleteFilterStep - #98946

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-ttl-delete-filter-futureset
Mar 9, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-ttl-delete-filter-futureset

Conversation

@antonio2368

@antonio2368 antonio2368 commented Mar 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • TTLDeleteFilterStep::transformPipeline created new TTLDeleteFilterTransform instances via addSimpleTransform, each rebuilding TTL expressions with new FutureSetFromSubquery objects. These differed from the ones filled by CreatingSetStep, causing a "Not-ready Set" exception when the TTL WHERE expression contained a subquery (e.g. WHERE col IN (SELECT ...)).
  • Fixed by following the same pattern as TTLStep: create a single TTLDeleteFilterTransform in the constructor, store it, and reuse it in transformPipeline via addTransform.
  • Added a regression test that forces vertical merge with a TTL WHERE + subquery.

Fixes #98614, Fixes #98692, Fixes #98814.

Test plan

  • New test 04029_ttl_delete_filter_vertical_merge_subquery passes with the fix
  • Same test fails with "Not-ready Set" exception against the unfixed binary

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

🤖 Generated with Claude Code


Note

Medium Risk
Touches vertical-merge TTL delete filtering and merge row-count bookkeeping; issues could surface as incorrect row filtering or merge progress/accounting when TTL WHERE uses subqueries.

Overview
Fixes vertical-merge TTL delete filtering when TTL WHERE contains subqueries by building TTL expressions once and sharing them via a new TTLDeleteFilterTransform::SharedState, ensuring CreatingSetStep fills the same FutureSet instances used at execution.

Refactors TTLDeleteFilterTransform to be a pure filter producer (removes per-part TTL-info mutation/finalization) and updates TTLDeleteFilterStep construction accordingly.

Adjusts vertical merge row counting to use total_rows_count (instead of progress-driven rows_read) and adds a regression test 04029_ttl_delete_filter_vertical_merge_subquery covering TTL delete + subquery during vertical merge.

Written by Cursor Bugbot for commit 73bddd2. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.512

`TTLDeleteFilterStep::transformPipeline` was creating new
`TTLDeleteFilterTransform` instances via `addSimpleTransform`, each of
which called `buildTTLExpressions` and produced new `FutureSetFromSubquery`
objects. These were different from the ones filled by `CreatingSetStep`,
causing a "Not-ready Set" exception when the TTL WHERE expression
contained a subquery (e.g. `WHERE col IN (SELECT ...)`).

Fix by following the same pattern as `TTLStep`: create a single
`TTLDeleteFilterTransform` in the constructor, store it, and reuse it
in `transformPipeline` via `addTransform`. This ensures the `FutureSet`
objects are shared between `CreatingSetStep` and execution.

Fixes #98614, #98692, #98814.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [73bddd2]

Summary: ❌

job_name test_name status info comment
SQLLogic test failure
Complete test failure cidb

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 6, 2026
Comment thread src/Storages/MergeTree/MergeTask.cpp Resolved
@CurtizJ CurtizJ mentioned this pull request Mar 6, 2026
1 task
- Move the min-TTL gate from transform time into `build`: entries whose
  `old_ttl_info.min` hasn't expired (and `force` is false) are now
  skipped before calling `buildTTLExpressions`, avoiding unnecessary DAG
  construction and `FutureSet` subqueries that would never be consumed.
  WHERE TTL entries are also skipped when `all_data_dropped` is already
  set.

- Replace the two member methods `isTTLExpired` and `isMinTTLExpired`
  with a single static free function `isTTLExpired(ttl, current_time)`
  used in both `build` (for the min-TTL gate) and `transform` (for
  per-row checks).

- Remove `force` and `old_ttl_info` from `SharedState` / `Entry` — they
  are now consumed entirely at build time.

- Capture `shared_state` by value (`[state = shared_state]`) instead of
  by reference in the `transformPipeline` lambda in `TTLDeleteFilterStep`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@antonio2368

antonio2368 commented Mar 6, 2026 •

Copy link
Copy Markdown
Member Author

The diff became too big for me to quickly verify. I will do it at some point but @CurtizJ and @murphy-4o if you think this is just complete trash feel free to close this PR.

At least the test is legit, it reproduces the issue.

antonio2368 and others added 2 commits March 6, 2026 22:47
…count

`rows_read` is updated from pipeline progress and may include auxiliary
reads such as `CreatingSetStep` subqueries. Use `total_rows_count` to
get the exact number of rows from source parts only.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add extra columns and deterministic merge settings to ensure the test
reliably triggers the Vertical algorithm. Query `part_log` to assert
the merge used Vertical and produced the expected row count.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@antonio2368

Copy link
Copy Markdown
Member Author

Changes make sense to me

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

/// has already been called by createMergedStream(), so subqueries must be available now.
TTLDeleteFilterTransform probe(context, input_header_, metadata_snapshot, old_ttl_infos, current_time, force, data_part);
subqueries_for_sets = probe.getSubqueries();
/// Build TTL expressions once and share them across all per-stream

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable. LGTM.

@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.20% 83.80% +0.60%
Functions 23.60% 23.90% +0.30%
Branches 75.30% 76.40% +1.10%

PR changed lines: PR changed-lines coverage: 97.75% (87/89)
Diff coverage report
Uncovered code

@alexey-milovidov
alexey-milovidov merged commit 3545dc2 into master Mar 9, 2026
158 of 159 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-ttl-delete-filter-futureset branch March 9, 2026 01:27
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

4 participants