Changes between Initial Version and Version 1 of Ticket #34597, comment 1


Ignore:
Timestamp:
May 25, 2023, 12:13:06 PM (18 months ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34597, comment 1

    initial v1  
    33AFAIK 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.
    44
    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.
     5Without 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.
    66
    7 In the mean time you can use `~Q(id__in=Blog.objects.filter(translation=None, id=OuterRef("id")))` instead of `~Q(translation=None)`.
     7The `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
     10Blog.objects.filter(
     11    Q(is_published=True) & ~Exist(Blog.objects.filter(translation=None, id=OuterRef("id")))
     12)
     13}}}
     14
     15In 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.
Back to Top