Skip to content

Revert "Resolve the query status per call in functions that check for cancellation" - #114537

Closed
PedroTadim wants to merge 1 commit into
masterfrom
revert-113456-groeneai/fix-ctor-captured-query-status-in-persisted-expressions
Closed

PedroTadim wants to merge 1 commit into
masterfrom
revert-113456-groeneai/fix-ctor-captured-query-status-in-persisted-expressions

Conversation

@PedroTadim

Copy link
Copy Markdown
Member

Reverts #113456

Needs a better solution

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [86236da]

Summary: ❌

job_name test_name status info comment
Stress test (amd_asan_ubsan) FAIL
Sanitizer (STID: 1464-4709) FAIL cidb

AI Review

Summary

This PR reverts the execution-time QueryStatus lookup that #113456 added and restores constructor-captured query state in six cancellation-aware functions. That reintroduces the persisted-expression bug on both routes that matter here: PARTITION BY keeps running the function instance built during CREATE TABLE, while sorting-key / skip-index expressions are rebuilt from MergeTreeData's global context. In both cases the cancellation state is wrong for the query that actually executes the expression, so I would block this revert as-is.

Missing context / blind spots

⚠️ The PR body says only Needs a better solution, so I could not validate what regression from #113456 requires reverting all six functions. A concrete failing case from that PR would be needed to judge a narrower fix.

Findings

❌ Blockers
[src/Functions/FunctionBaseXXConversion.h:303-313] Reintroducing constructor-captured QueryStatusPtr breaks persisted expressions again, and the same root cause is repeated in src/Functions/array/arrayFold.cpp, src/Functions/geohashesInBox.cpp, src/Functions/h3PolygonToCells.cpp, src/Functions/h3PolygonToCellsWithContainment.cpp, and src/Functions/sleep.cpp. KeyDescription::getKeyFromAST stores the built expression in metadata (src/Storages/KeyDescription.cpp:175-180, src/Storages/MergeTree/registerStorageMergeTree.cpp:686), so PARTITION BY later runs with the finished CREATE TABLE query's status; sorting-key / skip-index expressions are rebuilt from MergeTreeData::getContext() (src/Storages/MergeTree/MergeTreeData.cpp:744, 1417-1431, 1476-1478), which is global and has no process-list element. The result is that the in-loop cancellation checks are stale or disabled, so persisted expressions can ignore max_execution_time and KILL QUERY; on the partition-key route the stored strong reference also keeps the old query status alive.
Suggested fix: keep the execution-time lookup of the current query state (for example via CurrentThread or Functions/CancellationBudget) and fix the specific regression that motivated the revert without restoring cached QueryStatusPtr members.

Final Verdict

Status: ❌ Block
Minimum required actions: restore an execution-time source of cancellation state for these six functions instead of caching QueryStatusPtr in the function object, and then address the specific regression that motivated the revert with a narrower change.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.00% -0.10%

Changed lines: Changed C/C++ lines covered: 61/65 (93.85%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 12, 2026
@PedroTadim
PedroTadim enabled auto-merge August 12, 2026 19:56
@PedroTadim
PedroTadim disabled auto-merge August 12, 2026 20:03
if (max_input_size != 0)
max_input_size = context->getSettingsRef()[Setting::function_base58_max_input_size];
return std::make_shared<FunctionBaseXXConversion>(max_input_size);
return std::make_shared<FunctionBaseXXConversion>(context->getProcessListElementSafe(), max_input_size);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Capturing QueryStatusPtr here reopens the persisted-expression bug that #113456 fixed, and the same problem applies to the other five constructor changes in this revert. KeyDescription::getKeyFromAST stores built functions inside partition_key.expression (src/Storages/KeyDescription.cpp:175-180, src/Storages/MergeTree/registerStorageMergeTree.cpp:686), so later INSERTs execute them with the finished CREATE TABLE query's status; the sorting-key / skip-index path rebuilds from MergeTreeData::getContext() (src/Storages/MergeTree/MergeTreeData.cpp:744, 1417-1431, 1476-1478), which is the global context and therefore has no process-list element at all. In both routes the in-loop cancellation checks become stale or dead again, so persisted expressions can ignore max_execution_time and KILL QUERY, and the PARTITION BY route also keeps the old query status alive via a strong reference. This still needs an execution-time lookup (for example via CurrentThread / makeCancellationCheck) rather than restoring query state as member data.

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 86236dae3 with master 0264662fd (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 692.09 MiB 689.09 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

23 translation units recompiled, 115 s compile time in total, 23 of them have a recent master baseline.

Job report

@PedroTadim

Copy link
Copy Markdown
Member Author

Let's decide on this first

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant