-
Notifications
You must be signed in to change notification settings - Fork 4.1k
opt: add geospatial inverted index recommendations #80934
Copy link
Copy link
Closed
Labels
C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries TeamSQL Queries Team
Description
There should be geospatial inverted index recommendations for queries that use index accelerated geospatial functions:
cockroach/pkg/geo/geoindex/geoindex.go
Lines 36 to 51 in 6f85a0b
| var RelationshipMap = map[string]RelationshipType{ | |
| "st_covers": Covers, | |
| "st_coveredby": CoveredBy, | |
| "st_contains": Covers, | |
| "st_containsproperly": Covers, | |
| "st_crosses": Intersects, | |
| "st_dwithin": DWithin, | |
| "st_dfullywithin": DFullyWithin, | |
| "st_equals": Intersects, | |
| "st_intersects": Intersects, | |
| "st_overlaps": Intersects, | |
| "st_touches": Intersects, | |
| "st_within": CoveredBy, | |
| "st_dwithinexclusive": DWithin, | |
| "st_dfullywithinexclusive": DFullyWithin, | |
| } |
For example, the query below has no recommendation:
defaultdb> CREATE TABLE t (k INT PRIMARY KEY, g GEOMETRY);
defaultdb> EXPLAIN SELECT k FROM t WHERE st_covers(g, 'POINT(0 0 0 0)');
info
--------------------------------------------------------------------------------------------------------
distribution: local
vectorized: true
• filter
│ filter: st_covers(g, '01010000C00000000000000000000000000000000000000000000000000000000000000000')
│
└── • scan
missing stats
table: t@t_pkey
spans: FULL SCAN
(10 rows)
But if an index is added, a query plan using it is chosen because it is more efficient:
defaultdb> CREATE INVERTED INDEX ON t(g);
CREATE INDEX
defaultdb> EXPLAIN SELECT k FROM t WHERE st_covers(g, 'POINT(0 0 0 0)');
info
--------------------------------------------------------------------------------------------------------
distribution: local
vectorized: true
• filter
│ filter: st_covers(g, '01010000C00000000000000000000000000000000000000000000000000000000000000000')
│
└── • index join
│ table: t@t_pkey
│
└── • inverted filter
│ inverted column: g_inverted_key
│ num spans: 31
│
└── • scan
missing stats
table: t@t_g_idx
spans: 31 spans
(17 rows)
Jira issue: CRDB-15446
Epic: CRDB-14532
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries TeamSQL Queries Team
Type
Projects
Status
Done