Skip to content

Cherry pick #116335 to 26.7: Check for timeouts and KILL QUERY while covering a polygon with H3 cells - #121388

Merged
robot-clickhouse-ci-2 merged 6 commits into
backport/26.7/116335from
cherrypick/26.7/116335
Sep 23, 2026
Merged

robot-clickhouse-ci-2 merged 6 commits into
backport/26.7/116335from
cherrypick/26.7/116335

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #116335

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Algunenano and others added 5 commits August 25, 2026 16:38
A stress test hung on a fuzzed `h3PolygonToCellsWithContainment` query whose
polygon had a vertex at latitude -1.7976931348623157e308. It spent about 45
minutes inside one H3 call, observing neither `max_execution_time` nor
`KILL QUERY`.

Two causes. H3 picks the coarse resolution for its size estimate by dividing
the polygon's bounding box area by the average cell area, and a vertex off the
sphere makes that area negative, so the reduction never triggers and the
estimate counts every cell of a polygon covering much of the globe: 2.6e8 cells
at resolution 9. And the cells of one polygon were filled inside a single H3
call, so the only cancellation checkpoint was between rows.

Vertices are now rejected unless longitude is in -180..180 and latitude in
-90..90 degrees, and the cells are enumerated one at a time through H3's cell
iterator, charging the shared `CancellationBudget` per cell. Both functions
share one implementation now, which also drops the staging buffer the results
were copied through.

`h3PolygonToCells` had the same shape, plus H3's legacy algorithm allocating
two estimate-sized buffers outside the memory tracker. It goes through the same
iterator with `CONTAINMENT_CENTER`, the containment rule its own H3 source
documents for itself. On a 20 by 20 degree box at resolution 9 it returns the
same 58823612 cells in 0.64 s instead of 47 s, with 1.35 GB of peak RSS instead
of 4.5 GB.

Measured on a release build: a valid 20000-vertex polygon at resolution 10 took
7.5 s per row for the first function and 29 s for the second, and both now stop
1.1 s after a 1 s deadline. Clean under MSan and TSan.

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

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`h3PolygonToCells` now enumerates the cells through H3's cell iterator, which
emits them in a different order than the legacy breadth-first algorithm. The
set is unchanged: sorting every array in the reference makes the old and new
outputs identical, and the test's own comparison against the expected cells,
which sorts, keeps passing on every line.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
H3 wraps its candidate walk in one call, and that call rejects millions of
candidates before it returns a cell, so charging the budget per returned cell
bounds nothing for a sliver polygon: the size estimate returns no cell at all,
and a needle whose bounding box covers much of the globe runs for minutes past
the deadline. The walk of `iterStepPolygonCompact` now runs here, over the same
H3 primitives so the cells and their order are unchanged, with a checkpoint per
candidate, and the size estimate goes through it too.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`h3PolygonToCells` enumerates the cells through H3's cell iterator now, which
emits them in a different order, so the example response is the new order. Both
functions document that the order is not guaranteed and that every vertex must
be on the sphere, and the missing anchor is added.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…lation

Check for timeouts and KILL QUERY while covering a polygon with H3 cells
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Sep 21, 2026
Resolve the conflicts in `h3PolygonToCells.cpp` and `h3PolygonToCellsWithContainment.cpp` by taking the
thin wrappers over `appendH3Cells` from the source PR, without the `MultiPoint` rejection branch: 26.7 has
no `ColumnToMultiPointsConverter`.

Also add `CancellationBudget.h` and `CancellationBudget.cpp` from master (introduced by #113369, which is not
in 26.7): `h3GeometryToCells` and both functions depend on `CancellationBudget` and `makeCancellationCheck`.
The helper is self-contained; it does not change `countSubstrings` or anything else on 26.7.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 0365fa9 into backport/26.7/116335 Sep 23, 2026
2 checks passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.7/116335 branch September 23, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants