Opened 9 months ago
Last modified 8 months ago
#36290 closed Bug
Unnecessary query performed when prefetching nullable foreign key relationships — at Version 1
| Reported by: | Simon Charette | Owned by: | Simon Charette |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.2 |
| Severity: | Release blocker | Keywords: | prefetch_related foreign object key null |
| Cc: | Baptiste Mispelon | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
As reported by Baptiste on Discord
Because the tuple_lookups.TupleIn.process_rhs logic doesn't replicate the None eliding logic on lookups.In.process_rhs logic the usage of TupleIn introduced in 626d77e52a3f247358514bcf51c761283968099c to resolve #36116 resulted in the unnecessary execution of queries of the form
SELECT "releases_release"."version" FROM "releases_release" WHERE ("releases_release"."version") IN ((NULL))
which are never going to match because NULL != NULL in SQL.
This has to relation to #31667 which introduced this optimization for the same prefetch related optimization purposes.