#25113: Field lookup for __not_in
-------------------------------------+-------------------------------------
     Reporter:  Evan Tschuy          |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Dmitry Mugtasimov):

 It produce SQL like:
 {{{
 NOT ("jobs_job"."id" IN (SELECT U0."id" FROM "jobs_jobstatus" U0))
 }}}

 which may not be equivalent to

 {{{
 "jobs_job"."id" NOT IN (SELECT U0."id" FROM "jobs_jobstatus" U0)
 }}}

 regarding performance.

 Also because of "weird" chained filter() behavior (
 https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-
 valued-relationships ) you will have to do something like

 {{{
 Job.objects.filter(
             ~Q(id__in=JobStatus.objects.values_list('id',
 flat=True).all()),
             ...
         )
 }}}

 instead of

 {{{
 Job.objects.filter(...).exclude(id__in=JobStatus.objects.values_list('id',
 flat=True).all()).delete()
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/25113#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.e892df0cf2ab4e935fde9dbb0f3d8882%40djangoproject.com.

Reply via email to