Skip to content

dialect(postgresql, mssql, sqlite), metadata(mssql): partial indexes - #90

Merged
stbischof merged 1 commit into
mainfrom
feature/partial-indexes
Nov 11, 2026
Merged

stbischof merged 1 commit into
mainfrom
feature/partial-indexes

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

An index over the rows of a condition could not be written: the dialect API had no WHERE for an index, so a model that holds one could only leave it out, as a unique one written without its condition would hold for more rows than intended.

What changes

DdlGenerator gains:

  • Optional<String> createIndex(String indexName, TableReference table, List<String> columnNames, boolean unique, String condition, boolean ifNotExists), which writes CREATE [UNIQUE] INDEX ... WHERE condition. Without a condition it writes the plain index of every dialect; with one it is empty where the database has no partial indexes.
  • boolean supportsFilteredIndexes(), false by default.
Dialect Partial index
PostgreSQL, SQL Server the condition as given
SQLite from 3.8.0
Oracle, MySQL, MariaDB, H2, Derby, ClickHouse, Hive, Impala, ANSI none
DuckDB none; it rejects the WHERE as not implemented

The SQL Server metadata provider reported a filtered index without its condition; it now reads sys.indexes.filter_definition. PostgreSQL's read it already.

Tests

The consistency tests check the statements of every dialect. On PostgreSQL, SQL Server and SQLite a unique partial index is created, holds among the rows of its condition only, and is read back with its condition where a metadata provider reads indexes. The metadata contract creates one where the database has them and expects the provider to give its condition.

An index over the rows of a condition could not be written: the dialect
API had no WHERE for an index, so a model that holds one could only
leave it out, as a unique one written without its condition would hold
for more rows than intended.

DdlGenerator gains createIndex(name, table, columns, unique, condition,
ifNotExists), which writes CREATE [UNIQUE] INDEX ... WHERE condition,
and supportsFilteredIndexes(), false by default. Without a condition
it writes the plain index of every dialect; with one it is empty where
the database has no partial indexes. PostgreSQL and SQL Server write
the condition as given, and SQLite from 3.8.0. Oracle, MySQL, MariaDB,
H2, DuckDB (which rejects the WHERE as not implemented), Derby,
ClickHouse, Hive, Impala and the ANSI dialect have none.

The SQL Server provider reported a filtered index without its
condition; it now reads sys.indexes.filter_definition. PostgreSQL's
read it already.

The consistency tests check the statements of every dialect. On
PostgreSQL, SQL Server and SQLite a unique partial index is created,
holds among the rows of its condition only, and is read back with its
condition where a metadata provider reads indexes. The metadata
contract creates one where the database has them and expects the
provider to give its condition.

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof merged commit 03c5338 into main Nov 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant