cockroachdb / cockroachdb/cockroach
sql: generic query plans cannot use indexes for IN sets or disjunction
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
For generic query plans we usually replace scans with lookup joins to handle placeholders. But this technique doesn't seem to be working when the scan would come from an IN set or a disjunction over equality.
Here's a demonstration using `cockroach demo movr` on v24.2.0-rc.1:
```sql
SET plan_cache_mode = force_generic_plan;
PREPARE p AS SELECT * FROM users WHERE city = $1;
-- this can use a scan over the primary index thanks to the placeholder fast path
EXPLAIN ANALYZE EXECUTE p ('seattle');
PREPARE p2 AS SELECT * FROM users WHERE city = $1 OR city = $2;
-- this should become a lookup join into the primary index, but is instead a full table scan and filter
EXPLAIN ANALYZE EXECUTE p2 ('seattle', 'los angeles');
PREPARE p3 AS SELECT * FROM users WHERE city IN ($1, $2, $3, $4);
-- again, this should become a lookup join into the primary index, but is instead a full table scan and filter
EXPLAIN ANALYZE EXECUTE p3 ('seattle', 'portland', 'vancouver', 'los angeles');
```
Jira issue: CRDB-41279
Contributor guide
Assessment
This issue has not been assessed yet.