kensho-technologies/graphql-compiler

SQLAlchemy does not specify whether an index is partial or not.

Opened this issue · 1 comments

Postgres, SQL Server and MySQL all have partial/filtered indexes, which are basically indexes that apply only to a subset of the rows in the table. Whether an index is partial or not is information that one should be able to obtain by querying the underlying database. (This at least holds for SQL Server). However, SQLAlchemy does not reflect this information from the database.

Therefore, we can't know whether a unique SQLAlchemy index implies uniqueness over either a subset of the table or the entire table.

SQLAlchemy does have dialect-specific fields for inputting this kind of information:
https://docs.sqlalchemy.org/en/13/dialects/mssql.html#filtered-indexes

However, as I mentioned earlier, this information is not captured during SQLAlchemy reflection. This makes sense because the SQLAlchemy library does not have a way of mapping filter definitions that are defined in SQL strings to SQLAlchemy constructs.

In the future, it might be a good idea to make a PR against the SQLAlchemy library to change their reflection method such that it includes this information.

Here is a relevant issue:
sqlalchemy/sqlalchemy#4966