We've got some slow running queries in our DB and I think some of them can be solved by changing the underlying SQL.
Given the following:
Model.objects.filter(rel_id__in=[1,2,3])
Outputs (abridged):
SELECT all, the, fields FROM "model" WHERE ("rel_id" IN (1, 2, 2))
What I want is for the SQL to change to:
SELECT all, the, fields FROM "model" WHERE ("rel_id" = ANY(array[1, 2, 2]))
I know that this might be not be optimum approach, but EXPLAIN ANALYSE
returns significantly lower figures with the second query.
So my question is, how can I get the second SQL query from my QuerySet lookup?
Thanks in advance