cockroachdb / cockroachdb/cockroach
sql: regression due to `GenerateMinimalInvertedIndexScans`
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
#131784 introduced a new exploration rule which causes the query in the example below to regress in latency:
```sql
CREATE TABLE test (
id UUID NOT NULL AS ((doc->>'id':::STRING)::UUID) STORED,
doc JSONB NOT NULL,
PRIMARY KEY (id),
INVERTED INDEX doc_contents (doc)
);
INSERT INTO test (doc)
SELECT ('{"id" : "' || gen_random_uuid() ||
'", "timestamp" : "' || (now() + (n || ' microseconds')::INTERVAL) ||
'", "flag1" : ' || (case when (n % 2 = 0) then 'true' else 'false' end) ||
', "flag2" : ' || (case when (n % 23 = 0) then 'true' else 'false' end) ||
', "string1" : "testa' || (n % 13) ||
'", "string2" : "testb' || (n % 23) ||
'"}')::json
FROM
(select generate_series(1, 100000) as n) AS x;
ANALYZE test;
SELECT pg_sleep(3);
-- Warm up.
SELECT COUNT(*) FROM test;
SELECT COUNT(*) FROM test WHERE doc->'flag2' = 'true'::JSONB AND doc->'string2' = '"testb0"'::JSONB AND doc->'string1' = '"testa0"'::JSONB;
-- v24.2.4: 16ms, scan actual row count: 16,386
-- v24.3.0: 78ms, scan actual row count: 4,347
```
Let's investigate why the optimizer is picking the slower plan.
Jira issue: CRDB-45275
Contributor guide
Assessment
This issue has not been assessed yet.