Repository navigation
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 intoSep 23, 2026
Conversation
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
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job