Repository navigation
Do not walk the geohashesInBox grid when one axis has no items - #112976
PedroTadim merged 2 commits into
Conversation
`geohashesInBoxPrepare` rejects reversed and NaN boxes, but not a box of zero area whose bounds are merely equal: `latitude_max < latitude_min` is false when the two are equal, and also for `-0.0 < 0.0`. Such a box aligns one axis to a single grid line, so that axis' item count is zero while the other stays enormous. For `(0., 0., 180., 0.)` at precision 12 that is `longitude_items = 536870912` and `latitude_items = 0`, which makes `items_count` `max(1, 536870912 * 0)` = 1 while `geohashesInBox` still walks the outer axis in full with a zero-trip inner loop: 536 million iterations to produce one geohash. The row loop's cancellation checkpoint cannot help, because it is throttled on accumulated items and each of these rows contributes a single unit. A whole block of them stays orders of magnitude below the threshold, currently `items_between_cancellation_checks = 100'000`, so `checkTimeLimit` is never consulted and neither `max_execution_time` nor `KILL QUERY` is observed. That is how a Stress test run sat in this loop for 714 s with `is_cancelled` already set. Reachable without a fuzzer: `SELECT geohashesInBox(0., 0., 180., 0., 12)` burns the same ~5e8 iterations per row. Skip the loops when either item count is zero and let the existing `items == 0` fallback emit the single geohash the box degenerates to, so results are unchanged. Measured on a debug build: 200 rows of the degenerate block go from 28.0 s to 0.11 s, and the unfixed arm overruns a `max_execution_time` deadline by that same margin under either throttle value. A 1875-case sweep over boxes and precisions is byte-identical before and after. The non-degenerate path is untouched.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20260802-034600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-46:20260802-015300 |
|
cc @nikitamikhaylov @scanhex12, could you review this? A box of zero area passes the reversed and NaN guard in |
|
Workflow [PR], commit [163657b] Summary: ✅
AI ReviewSummaryThis PR fixes the Final VerdictNo new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code |
… only The review pointed out that asserting `['s00000000000']` for `geohashesInBox(0., 0., 180., 0., 12)` freezes a preexisting result question into the test contract. That box is a line segment, not a point, so a precision-12 cover is not one cell, and both the documentation and `FunctionDocumentation::ReturnedValue` state that non-strict bounds return an empty array. Pinning the current output would make a later semantics fix read as a regression against this reference file. Measured on a debug build: that row passes unchanged with the guard reverted (0.43 s, byte-identical output), so it never carried the oracle and is pure surplus commitment. The liveness rows are what redden, at ~28 s against a 10 s deadline. `sum(length(...))` carried the same claim less visibly, since a length of 1 per row is exactly the one-cell assertion. Both now use `ignore`, which forces evaluation while asserting nothing about the result, so the test reddens only on the behaviour this change actually fixes. Re-verified both directions: green on the fixed binary, TIMEOUT_EXCEEDED on the pristine one, and 50 of 50 randomized runs pass.
|
Hi @groeneai @PedroTadim — while reviewing this PR I found the following:
Could you review the test PR and add the |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
geohashesInBoxspending an unbounded amount of time on a box of zero area, such asgeohashesInBox(0., 0., 180., 0., 12). Such a query returned the correct single geohash but burned roughly 5e8 empty loop iterations per row and ignored bothmax_execution_timeandKILL QUERY.Description
geohashesInBoxPreparerejects reversed and NaN boxes, but not a box of zero area whose bounds are merely equal:latitude_max < latitude_minis false when the two are equal, and also for-0.0 < 0.0. Such a box aligns one axis to a single grid line, so that axis' item count is zero while the other stays enormous. For(0., 0., 180., 0.)at precision 12 that islon_items = 536870912,lat_items = 0:items_countis 1, yetgeohashesInBoxstill walks the outer axis in full with a zero-trip inner loop, 536 million iterations to produce one geohash.The row loop's cancellation checkpoint, added in #112273, cannot help: it is throttled on accumulated items and each such row contributes a single unit, so a whole block stays far below the threshold and
checkTimeLimitis never consulted. Neither the deadline nor aKILLis observed. That is how the query in the CI report below sat in this loop for 714 s withis_cancelledalready set, reddeningStress test (arm_asan_ubsan).The fix skips the nested loops when either item count is zero, letting the existing
items == 0fallback emit the same single geohash, so results are unchanged. The non-degenerate path costs two added integer comparisons per row.Validated on a debug build: under
max_execution_time = 10, 200 rows of the degenerate block overrun to ~28 s unfixed and honour the deadline in 0.11 s fixed. The same numbers hold against the currentitems_between_cancellation_checks = 100'000. A 1875-case sweep over boxes and precisions is byte-identical before and after. The new test04694_geohashes_in_box_degenerate_spanasserts termination only, leaving the result of a line-degenerate box to the existing00972_geohashesInBoxinvariants; it reddens withTIMEOUT_EXCEEDEDwhen the guard alone is reverted, and passed 50 of 50 randomized runs.No related open issue. CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112668&sha=3f7020cf4114402a81c9d3dd6e7bef755802e34b&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29