Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying NULLS NOT DISTINCT for unique indexes #2298

Closed
roji opened this issue Mar 11, 2022 · 5 comments · Fixed by #2537
Closed

Add support for specifying NULLS NOT DISTINCT for unique indexes #2298

roji opened this issue Mar 11, 2022 · 5 comments · Fixed by #2537
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@roji
Copy link
Member

roji commented Mar 11, 2022

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 dotnet/efcore#16949 (comment).

@roji roji added the enhancement New feature or request label Mar 11, 2022
@roji roji added this to the 7.0.0 milestone Mar 11, 2022
@roji roji self-assigned this Mar 11, 2022
@roji
Copy link
Member Author

roji commented Mar 22, 2022

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

@roji
Copy link
Member Author

roji commented Mar 22, 2022

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

@roji
Copy link
Member Author

roji commented Mar 22, 2022

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.

@mqudsi
Copy link

mqudsi commented Mar 22, 2022

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?

@roji
Copy link
Member Author

roji commented Mar 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants