#36290 closed Bug (fixed)
Unnecessary query performed when prefetching nullable foreign key relationships
| 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.
Change History (5)
comment:1 by , 7 months ago
| Description: | modified (diff) | 
|---|---|
| Has patch: | set | 
comment:2 by , 7 months ago
| Triage Stage: | Unreviewed → Accepted | 
|---|
comment:3 by , 7 months ago
| Triage Stage: | Accepted → Ready for checkin | 
|---|
comment:4 by , 7 months ago
| Resolution: | → fixed | 
|---|---|
| Status: | assigned → closed | 
  Note:
 See   TracTickets
 for help on using tickets.
    
In f7f38f3: