Cleaner query for image cleanup
While working on !1967 (merged), I found out that Exists
can now be used directly as a filter, and not only as an annotation as it was restricted to a long time ago. This can be a performance optimization as Django no longer includes the EXISTS ()
in the SELECT
clause, and only uses it in the WHERE
clause.
I looked for existing uses of Exists
and only found the one in manage.py cleanup
to find images without elements. We were using a hack where the annotation was overwritten after filtering on it, specifically to avoid selecting the EXISTS
and getting a nice performance boost on that query as PostgreSQL can use a rare and fast Nested Loop Anti Join
instead of a long Hash Join
. So this merge request changes nothing apart from making the query look a little cleaner.