I have legacy code that uses an ORM subquery that produces an SQL SELECT query with JOIN and conditions that also contain SELECT and JOIN. This request takes a long time to complete. By the way, when I execute this query in raw SQL taken from Django_ORM_query.query, it executes with a reasonable amount of time.
What are the best optimization methods in such cases?
Will the query run faster if I use the ManyToManyand relationships ForeignKey?
source
share