#34591: Django ORM replace INNER JOIN with STRAIGHT_JOIN
-------------------------------------+-------------------------------------
Reporter: Cubed | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: 4.2
layer (models, ORM) |
Severity: Normal | Keywords: sql join
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Similar to this post here from 9+ years ago:
https://code.djangoproject.com/ticket/22438
We have queries being generated that use "inner join" - which should be
fine, but the SQL engine optimiser is not playing nice with it.
When I swap "inner join" for "straight_join" - thus by-passing the
optimiser - I get the performance I'd expect.
With "inner join" - 1+ hour
With "straight_join" - 2 seconds.
This isnt a fault of Django, but after a lot of researching and tinkering,
it appears sometimes you have to by-pass the optimiser to get the exact
query you want.
Is this possible to do in Django? Perhaps Ive missed it in the docs. Even
if its something a bit hacky like:
qs = myModel.object.filters(....).otherStuff(...)
qs.raw_sql.replace("inner ", "straight_")
that would be enough for me to test this further.
Any pointers would be greatly appreciated.
--
Ticket URL: <https://code.djangoproject.com/ticket/34591>
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/0107018848de009b-a7435eef-8542-430d-956a-953b3b1d8adf-000000%40eu-central-1.amazonses.com.