Changes between Initial Version and Version 1 of Ticket #34597, comment 1
- Timestamp:
- May 25, 2023, 12:13:06 PM (18 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #34597, comment 1
initial v1 3 3 AFAIK this is the only report in three years about this change making things slower and the fact it jumped from a couple of seconds to hours makes me think there might be something else at play here (lack of analyze?). FWIW this change was advised [https://www.percona.com/blog/sql-optimizations-in-postgresql-in-vs-exists-vs-any-all-vs-join/ by this article] and examples in the wild of `NOT IN` performing poorly. 4 4 5 Without more details such as the Postgres execution plans (use `EXPLAIN` on the query) it's very hard to provide any guidance here so I'll close as ''needsinfo'' for now as I cannot reproduce any form of slowdown with the provided model. The `AND "blog"."id" = "blog"."id"` part seems definitely fishy though so it'd be great to see if you get fast results without it as that appear to be a bug.5 Without more details such as the Postgres execution plans (use `EXPLAIN` on the query) it's very hard to provide any guidance here so I'll close as ''needsinfo'' for now as I cannot reproduce any form of slowdown with the provided model. 6 6 7 In the mean time you can use `~Q(id__in=Blog.objects.filter(translation=None, id=OuterRef("id")))` instead of `~Q(translation=None)`. 7 The `AND "blog"."id" = "blog"."id"` part seems definitely fishy though so it'd be great to see if you get fast results without it as that appear to be a bug. You can try it out by doing 8 9 {{{#!python 10 Blog.objects.filter( 11 Q(is_published=True) & ~Exist(Blog.objects.filter(translation=None, id=OuterRef("id"))) 12 ) 13 }}} 14 15 In the mean time you can use `~Q(id__in=Blog.objects.filter(translation=None, id=OuterRef("id")))` instead of `~Q(translation=None)` to restore the previous behaviour if you're blocked.