efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Add support for specifying NULLS NOT DISTINCT for unique indexes

Open roji opened this issue 2 years ago • 5 comments

PostgreSQL 15 will allow specifying NULLS NOT DISTINCT on index columns, to make unique indexes disallow multiple rows with NULLs (see docs).

Raised by @mqudsi in https://github.com/dotnet/efcore/issues/16949#issuecomment-1064622802.

roji avatar Mar 11 '22 11:03 roji

Note: IIRC EF Core itself adds a nullability WHERE clause to indexes, that may become unnecessary here - investigate this.

roji avatar Mar 22 '22 08:03 roji

This is SqlServerIndexConvention, which works for unique non-clustered indexes for SQL Server only.

roji avatar Mar 22 '22 15:03 roji

Discussed with @AndriySvyryd about the possibility of a relational-level knob for this, which SqlServerIndexConvention would consult etc. We're not going to do this for now, since the implementation differences across providers (convention with index filter in SQL Server vs. native capability in PG) may have non-obvious consequences. So we'll just do a PG-specific index flag.

roji avatar Mar 22 '22 17:03 roji

Thanks for the update. I imagine it makes the most sense anyway to proof such an API w/ one provider, see how it goes, then consider upstream support based off that. ~~I don't think we'd be able to do anything regarding the upstream issue (on conflict support) without proper support from EF Core so this would be isolated to just supporting non-distinct nulls on pg15 and possibly w/ a fallback impl for earlier versions, right?~~

mqudsi avatar Mar 22 '22 18:03 mqudsi

Just FYI, am going to wait until a PG15 beta is available before implementing this, so that we can see it actually working in our CI.

roji avatar Mar 22 '22 23:03 roji