Hi everyone<br><br>I've been investigating some of the SQL queries that's really slow. I've noticed that we are using quite a few queries that uses sub-queries - "where value1 in (select value 2 from ... )<br>
<br>So, as a first example (and also one of the slowest queries):<br><br>We have this function: <a href="https://github.com/p2pu/lernanta/blob/master/lernanta/apps/projects/models.py#L323-L334">https://github.com/p2pu/lernanta/blob/master/lernanta/apps/projects/models.py#L323-L334</a><br>
<br>that generate this SQL: <a href="https://gist.github.com/4473163">https://gist.github.com/4473163</a><br><br>I've rewritten the query using only joins to achieve the same (faster): <a href="https://gist.github.com/4473181">https://gist.github.com/4473181</a><br>
<br>So the riddle: how do you get Django's ORM to generate something more like the second query?<br><br>Cheers<br>Dirk<br><br>