-
Notifications
You must be signed in to change notification settings - Fork 229
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
Stop using "IS NOT DISTINCT FROM" #28
Comments
Can you provide more detail? Do you have any reason to believe "IS NOT DISTINCT FROM" is slower than "=" in PostgreSQL for non-nullable fields? |
When I run the query with "IS NOT DISTINCT FROM", it took 600ms, then I replace for "=" and it is only 1ms |
Can you please send the two queries which demonstrate this, including a schema? |
I've made some test with a new table having only two fields, both uuid. If I run the two queries with only few records, it took the same time. When adding 1,000,000 records then I'm starting having performance issue : 10ms vs 87ms. UPDATE mytable SET parentid='00000000-0000-0000-0000-000000000000' where id iS NOT DISTINCT FROM '015bf336-74a8-4bbd-b4cc-ecdc1fdbe996' |
OK, I'll take a look at this. |
Another issue is that "IS NOT DISTINCT FROM" will not use an index. Here is a thread from the pgsql-hackers mailing list that discusses it. http://postgresql.nabble.com/IS-NOT-DISTINCT-FROM-Indexing-td5812296.html We are running into this issue as well and have update queries timing out because of it. In our case a simple equality would work and would use the index. |
Thanks for the thread @scolemann, this definitely explains the performance difference @CaucaCG noted above. I'll make this change soon. |
Note: I originally used |
So recalling the original problem, this is actually more of an EFCore issue than an Npgsql one - they actually generate good null comparisons for queries but not for updates. That's why I "hacked" things to use I really hope we can avoid implementing doing null comparison logic ourselves here. |
@roji thanks for the explanation and sorting this out. |
Hi @roji, It looks like the EF team fixed issue 3023 (Update Pipeline: Use C# null semantics for WHERE clauses). Is there any chance you could remove that IS NOT DISTINCT FROM code soon? Thanks for your help! |
Thanks for telling me @scolemann, that somehow slipped under my radar! I've removed the |
Awesome, thank you! |
Performance issue due to the query generation on update.
It's using "IS NOT DISTINCT FROM" instead of "="
I don't think there's any reason to not use the "=" on not nullable field
The text was updated successfully, but these errors were encountered: