#36290: Unnecessary query performed when prefetching nullable foreign key
relationships
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: Bug | Status: assigned
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: prefetch_related | Triage Stage:
foreign object key null | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):
* has_patch: 0 => 1
Old description:
> [https://discord.com/channels/856567261900832808/859997770274045954/1357036282651345006
> 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`
> [https://github.com/django/django/blob/c7ff347c641f2f97fa9f2f7d182982f789a211b4/django/db/models/lookups.py#L527-L536
> 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.
New description:
[https://discord.com/channels/856567261900832808/859997770274045954/1357036282651345006
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`
[https://github.com/django/django/blob/c7ff347c641f2f97fa9f2f7d182982f789a211b4/django/db/models/lookups.py#L527-L536
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/36290#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070195f877c212-a41365d9-aa6d-4170-9651-810c7ad52983-000000%40eu-central-1.amazonses.com.