Repository navigation
Make the pointInPolygon preprocessed polygon cache shared, bounded, and configurable - #107247
Merged
nihalzp merged 26 commits intoJun 25, 2026
Merged
Conversation
Contributor
|
Workflow [PR], commit [1a98b24] Summary: ✅
AI ReviewSummaryThis PR replaces the process-lifetime Final Verdict✅ No blockers or majors found in this pass. |
Algunenano
requested changes
Jun 15, 2026
Algunenano
left a comment
Member
There was a problem hiding this comment.
- We need a way to drop the cache as we have
SYSTEM DROP PARQUET METADATA CACHE,SYSTEM CLEAR|DROP TEXT INDEX CACHES, etc. - The cache should be using the arena for caches (
JemallocCacheArena/JemallocCacheAllocator).
This was referenced Jun 22, 2026
Algunenano
reviewed
Jun 22, 2026
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 146/155 (94.19%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 3 line(s) · Uncovered code |
Merged
via the queue into
ClickHouse:master
with commit Jun 25, 2026
75ea03e
328 of 330 checks passed
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Jun 25, 2026
For a constant polygon, executeImpl parsed and hashed the polygon on every input block before the preprocessed-polygon cache lookup, because the cache key was a hash of the parsed geometry. Key the cache on the raw constant arguments instead and move the parse into the cache-miss load function, so repeated invocations skip the parse entirely. This addresses the per-block parse cost behind the ARM regression in ClickHouse#106596, which the shared bounded cache added in ClickHouse#107247 did not remove. The key folds in the validate_polygons setting and the argument types: parsing (and its validity check) runs only on a miss, so an entry built under one validate mode or coordinate type must not satisfy a lookup under another. Co-Authored-By: Claude Opus 4.8 <[email protected]>
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Jun 26, 2026
For a constant polygon, executeImpl parsed and hashed the polygon on every input block before the preprocessed-polygon cache lookup, because the cache key was a hash of the parsed geometry. Key the cache on the raw constant arguments instead and move the parse into the cache-miss load function, so repeated invocations skip the parse entirely. This addresses the per-block parse cost behind the ARM regression in ClickHouse#106596, which the shared bounded cache added in ClickHouse#107247 did not remove. The raw-argument key is computed with XXH3 over the constant columns' contiguous buffers (array offsets, tuple elements, numeric leaves), the same hash the parsed-geometry key used. Hashing the constant polygon is on the per-block hot path, so an element-wise SipHash walk over the raw values regressed the point_in_polygon_const_hashing perf test; the bulk XXH3 walk is faster than the previous parse-then-hash (no parse on the hot path) and removes that regression. The key folds in the validate_polygons setting and the argument types: parsing (and its validity check) runs only on a miss, so an entry built under one validate mode or coordinate type must not satisfy a lookup under another. Co-Authored-By: Claude Opus 4.8 <[email protected]>
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Jun 26, 2026
For a constant polygon, executeImpl parsed and hashed the polygon on every input block before the preprocessed-polygon cache lookup, because the cache key was a hash of the parsed geometry. Key the cache on the raw constant arguments instead and move the parse into the cache-miss load function, so repeated invocations skip the parse entirely. This addresses the per-block parse cost behind the ARM regression in ClickHouse#106596, which the shared bounded cache added in ClickHouse#107247 did not remove. The raw-argument key is computed with XXH3 over the constant columns' contiguous buffers (array offsets, tuple elements, numeric leaves), the same hash the parsed-geometry key used. Hashing the constant polygon is on the per-block hot path, so an element-wise SipHash walk over the raw values regressed the point_in_polygon_const_hashing perf test; the bulk XXH3 walk is faster than the previous parse-then-hash (no parse on the hot path) and removes that regression. The key folds in the validate_polygons setting and the argument types: parsing (and its validity check) runs only on a miss, so an entry built under one validate mode or coordinate type must not satisfy a lookup under another. Co-Authored-By: Claude Opus 4.8 <[email protected]>
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Jun 26, 2026
For a constant polygon, executeImpl parsed and hashed the polygon on every input block before the preprocessed-polygon cache lookup, because the cache key was a hash of the parsed geometry. Key the cache on the raw constant arguments instead and move the parse into the cache-miss load function, so repeated invocations skip the parse entirely. This addresses the per-block parse cost behind the ARM regression in ClickHouse#106596, which the shared bounded cache added in ClickHouse#107247 did not remove. The raw-argument key is computed with XXH3 over the constant columns' contiguous buffers (array offsets, tuple elements, numeric leaves), the same hash the parsed-geometry key used. Hashing the constant polygon is on the per-block hot path, so an element-wise SipHash walk over the raw values regressed the point_in_polygon_const_hashing perf test; the bulk XXH3 walk is faster than the previous parse-then-hash (no parse on the hot path) and removes that regression. The key folds in the validate_polygons setting and the argument types: parsing (and its validity check) runs only on a miss, so an entry built under one validate mode or coordinate type must not satisfy a lookup under another. Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…ed-bounded-cache Make the `pointInPolygon` preprocessed polygon cache shared, bounded, and configurable
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
For a constant polygon, executeImpl parsed and hashed the polygon on every input block before the preprocessed-polygon cache lookup, because the cache key was a hash of the parsed geometry. Key the cache on the raw constant arguments instead and move the parse into the cache-miss load function, so repeated invocations skip the parse entirely. This addresses the per-block parse cost behind the ARM regression in ClickHouse#106596, which the shared bounded cache added in ClickHouse#107247 did not remove. The raw-argument key is computed with XXH3 over the constant columns' contiguous buffers (array offsets, tuple elements, numeric leaves), the same hash the parsed-geometry key used. Hashing the constant polygon is on the per-block hot path, so an element-wise SipHash walk over the raw values regressed the point_in_polygon_const_hashing perf test; the bulk XXH3 walk is faster than the previous parse-then-hash (no parse on the hot path) and removes that regression. The key folds in the validate_polygons setting and the argument types: parsing (and its validity check) runs only on a miss, so an entry built under one validate mode or coordinate type must not satisfy a lookup under another. Co-Authored-By: Claude Opus 4.8 <[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.
pointInPolygonpreprocesses constant polygons into a grid / R-tree and keeps them in a process-wide pool. The pool kept up tomax_threadscopies of the same preprocessed polygon per thread, grew without bound across distinct polygons, and never released anything until server restart, while the tracked memory counted toward the server memory limit and could fail unrelated queries withMEMORY_LIMIT_EXCEEDED.Now all queries and threads share a single immutable preprocessed instance per polygon, kept in a bounded LRU cache. The bound is the new server setting
point_in_polygon_cache_size(default 256 MiB, changeable at runtime,0disables the cache), and the current usage is visible insystem.metricsasPointInPolygonCacheBytesandPointInPolygonCacheCells.Related: #100759
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The cache of preprocessed constant polygons for the function
pointInPolygonis now shared between queries and threads and bounded by the new server settingpoint_in_polygon_cache_size(default 256 MiB,0disables the cache, changeable at runtime; previously the cache kept up tomax_threadscopies of each preprocessed polygon, grew without bound across distinct polygons, and was never released until server restart). It can be cleared at runtime withSYSTEM DROP POINT IN POLYGON CACHEand current usage is reported insystem.metricsasPointInPolygonCacheBytes,PointInPolygonCacheCells, andPointInPolygonCacheSizeLimit. Closes #106393.Version info
26.7.1.82