[PostgreSQL] New feature - Consider partial Index
Please, consider partial Index (PostgreSQL)
A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries only for those table rows that satisfy the predicate.
SQL example
CREATE TABLE tests (
subject text,
target text,
success boolean,
...
);
CREATE UNIQUE INDEX tests_success_constraint ON tests (subject, target)
WHERE success is true;
Suggestion:
table test {
subject text
target text
success boolean
Indexes {
(subject, target) [name: 'tests_success_constraint', unique, expression: `success is true`]
}
}
Important note:
There is already a perfect comment from Yokozuna59 here issue 68 that could solve this one graciously
Hi, I'd like to work on this one, if nobody else is.
My plan would be:
dbml-parse: accept a setting on index definitions (validator + interpreter).dbml-core: store it onIndex, include it inshallowExportand the types. TodayshallowExport()lists its fields explicitly, so a new field has to be added there to reach the normalized model, the JSON output and the exporters.- Postgres importer: read the
WHEREpredicate ofCREATE [UNIQUE] INDEX(the grammar already haswhere_clause?, butvisitIndexstmtignores it). - Exporters: write it back in
DbmlExporterandPostgresExporter(... WHERE <predicate>). - Tests, docs and
llms.txt.
One question before I start: which setting name do you want? The issue suggests expression: \success is true`, which is the same word used for functional index columns. where: `success is true`` would be closer to the SQL. I'd go with whichever you prefer.
Also, should other dialects be in scope (for example SQL Server filtered indexes, or SQLite partial indexes), or only PostgreSQL for now?