Opened 7 months ago
Last modified 7 months ago
#36290 closed Bug
Unnecessary query performed when prefetching nullable foreign key relationships — at Initial Version
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
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
{{{#sql
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.