cockroachdb / cockroachdb/cockroach
sql: add generic query plans to plan cache
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Generic query plans are not currently included in the plan cache. This means that each time we prepare and execute using generic query plans, we must optimize, even if nothing has changed about the tables involved. It would be nice to also cache generic query plans so that we get the benefits of avoiding optimization across sessions.
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 max(revenue) FROM rides WHERE city = $1;
-- we re-optimize the first time
EXPLAIN ANALYZE EXECUTE p ('seattle');
-- then we reuse each subsequent time
EXPLAIN ANALYZE EXECUTE p ('chicago');
-- but if we prepare and execute the exact same query again, we must re-optimize again
DEALLOCATE p;
PREPARE p AS SELECT max(revenue) FROM rides WHERE city = $1;
EXPLAIN ANALYZE EXECUTE p ('new york');
```
Jira issue: CRDB-41272
Contributor guide
Assessment
This issue has not been assessed yet.