cockroachdb / cockroachdb/cockroach
sql/stats: support constrained stats using computed columns that can be inferred from predicates
Open
A-sql-table-stats
C-enhancement
T-sql-queries
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Currently, constrained partial statistics (`CREATE STATISTICS ... WHERE ...`, #93998) require that the `WHERE` clause directly constrain the column being collected on, which must also be the prefix of an index. However, we should also support cases where an index prefix is a computed column that can be inferred from the predicate.
Example:
```
CREATE TABLE t (
x INT NOT NULL,
y INT NOT NULL AS (x % 5) STORED,
PRIMARY KEY (y, x)
);
CREATE STATISTICS stat ON x FROM t WHERE x = 100;
```
Jira issue: CRDB-54328
Contributor guide
Assessment
This issue has not been assessed yet.