﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34591	Django ORM replace INNER JOIN with STRAIGHT_JOIN	dev-c	nobody	"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.
"	Cleanup/optimization	closed	Database layer (models, ORM)	4.2	Normal	invalid	sql join		Unreviewed	0	0	0	0	0	0
