Skip to content

Check for query cancellation in h3PolygonToCells - #101042

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-h3-polygon-to-cells-stress-timeout
Mar 30, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-h3-polygon-to-cells-stress-timeout

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 28, 2026 •

Copy link
Copy Markdown
Member

The h3PolygonToCells function processes all rows in a tight loop calling H3 library functions (maxPolygonToCellsSize + polygonToCells) without ever checking if the query has been cancelled. Under MSan, these calls are extremely slow (~10-50x), and a query on 10,000 rows can run for ~30 minutes, ignoring max_execution_time and triggering the hung check in stress tests.

Add a per-row check of QueryStatus::isKilled (a single std::atomic<bool> load — essentially free) so the function respects cancellation.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100277&sha=53fa68604439a19ba43fbb7a772fb0f95a520e69&name_0=PR&name_1=Stress%20test%20%28amd_msan%29
#100277

Changelog category (leave one):

  • CI Fix or Improvement

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

The h3PolygonToCells function now respects query cancellation (max_execution_time, KILL QUERY), preventing it from running indefinitely on large inputs.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Author's comment: I'd not consider this approach, but the function is extremely slow, and its code is heavyweight, so this is normal.

Version info

  • Merged into: 26.4.1.404

…k in stress tests

The function processes all rows in a tight loop calling H3 library functions
(`maxPolygonToCellsSize` + `polygonToCells`) without ever checking if the
query has been cancelled. Under MSan, these calls are extremely slow, and
a query like `SELECT DISTINCT h3PolygonToCells(ring, 7) FROM rings` on
10,000 rows can run for ~30 minutes, ignoring `max_execution_time` and
triggering the hung check in stress tests.

Add a per-row check of `QueryStatus::isKilled` (a single atomic bool load)
so the function respects cancellation.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100277&sha=53fa68604439a19ba43fbb7a772fb0f95a520e69&name_0=PR&name_1=Stress%20test%20%28amd_msan%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1b37a00]

Summary: ✅


AI Review

Summary

This PR updates h3PolygonToCells to respect query cancellation by checking QueryStatus::isKilled once per input row and throwing QUERY_WAS_CANCELLED. The change is minimal, targeted, and consistent with the stated CI motivation; I did not find correctness, safety, compatibility, or maintainability regressions in the modified code.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 28, 2026
@alexey-milovidov alexey-milovidov added pr-ci and removed pr-bugfix Pull request with bugfix, not backported by default labels Mar 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.70% 76.70% +0.00%

Changed lines: 94.74% (18/19) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will fix "hung check" in stress tests.

@alexey-milovidov alexey-milovidov self-assigned this Mar 30, 2026
@alexey-milovidov
alexey-milovidov merged commit 74e8d6a into master Mar 30, 2026
149 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-h3-polygon-to-cells-stress-timeout branch March 30, 2026 03:24
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants