Use the primary key index for pointInPolygon with a Point key column - #112956
Conversation
Support index analysis for `pointInPolygon(coord, [...])` where `coord` is a whole key column of type `Point` (or another `Tuple` of two numeric elements), in addition to the previously supported `pointInPolygon((x, y), [...])` form with two scalar key columns. Tuple values are ordered lexicographically, so the range of such a key column constrains the first coordinate (and the second one when the first is fixed); the resulting bounding box is intersected with the polygon as before. Closes: #54805 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Workflow [PR], commit [d1daacb] Summary: ✅
AI ReviewSummaryThis PR extends Findings
Final VerdictNeeds one more focused test pass before merge: the code looks plausible, but the current evidence does not prove the non-lightweight path or the whole-key-expression form. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 79/92 (85.87%) · Uncovered code |
|
Hi @alexey-milovidov @nihalzp — while reviewing this PR I found the following:
Could you review the test PR and add the |
… `Point` key Follow-up to ClickHouse#112956. That change touched both `KeyCondition::checkInHyperrectangle` overloads - the dense one and the lightweight (sparse) one - but the test did not pin `use_lightweight_primary_key_index_analysis`, which `clickhouse-test` randomizes, so a single CI run only exercised whichever overload the harness happened to pick. It also did not cover the new fallback for a whole key *expression* of `Tuple` type: note that `ORDER BY tuple(x, y)` is expanded by `extractKeyExpressionList` into the two key columns `x` and `y` and therefore takes the other code path, so the tuple has to be one element of a composite key, as in `ORDER BY (tuple(x, y), id)`. Related: ClickHouse#112956
Closes: #54805
KeyConditioncould use the index forpointInPolygon((x, y), [...])wherexandyare separate key columns, but not forpointInPolygon(coord, [...])wherecoordis a whole key column of typePoint— such queries performed a full scan even when the table is ordered by the point column.Now the first argument may also be a single key column (or key expression) of type
Point, or anotherTupleof two numeric elements. Tuple values are ordered lexicographically, so the range of such a key column in a granule constrains the first coordinate of the point, and also the second coordinate when the first one is fixed; the resulting bounding box is intersected with the polygon as before. Both the regular and the lightweight (use_lightweight_primary_key_index_analysis) analysis paths are covered.The
INpart of the linked issue (coord IN ((x, y), ...)) already works on master.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Use the primary key index for
pointInPolygonwhen the point argument is a whole key column of typePoint(or anotherTupleof two numeric elements), e.g.pointInPolygon(coord, [...])for a table ordered bycoord. Previously only thepointInPolygon((x, y), [...])form with two scalar key columns was analyzed. Closes #54805.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.8.1.627(included in26.8and later)