#34450: Lookup expressions across foreign keys introduce extra joins
-------------------------------------+-------------------------------------
Reporter: Roman Odaisky | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by David Sanders):
Some testing:
Correct joining:
{{{
query = Query(Parent)
query.add_q(Q(child__x__exact= 'x'))
query.add_q(Q(Exact(F("child__x"), 'x')))
print(query)
SELECT "ticket_34450_parent"."id" FROM "ticket_34450_parent" INNER JOIN
"ticket_34450_child" ON ("ticket_34450_parent"."id" =
"ticket_34450_child"."parent_id") WHERE ("ticket_34450_child"."x" = x AND
"ticket_34450_child"."x" = (x))
}}}
On the other hand with the order reversed:
{{{
query = Query(Parent)
query.add_q(Q(Exact(F("child__x"), 'x')))
query.add_q(Q(child__x__exact= 'x'))
print(query)
SELECT "ticket_34450_parent"."id" FROM "ticket_34450_parent" LEFT OUTER
JOIN "ticket_34450_child" ON ("ticket_34450_parent"."id" =
"ticket_34450_child"."parent_id") INNER JOIN "ticket_34450_child" T3 ON
("ticket_34450_parent"."id" = T3."parent_id") WHERE
("ticket_34450_child"."x" = (x) AND T3."x" = x)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34450#comment:2>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/0107018737a3e8e8-6d0e3869-65ff-4d28-bdc6-dcbc582dca2f-000000%40eu-central-1.amazonses.com.