#26172: Don't query the database when filtering an already empty queryset
-------------------------------------+-------------------------------------
Reporter: seddonym | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: orm, queryset | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by akaariai):
* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0
Comment:
I don't see this as possible. The reason is that the ORM can't know if the
queryset will be empty when the filter() clause is applied. Consider:
{{{
Foo.objects.all().delete()
qs = Foo.objects.filter(pk__gte=0)
bool(qs)
Foo.objects.create(pk=1)
qs = qs.filter(pk=1) # There is a match even if
Foo.objects.filter(pk__gte=0) didn't match anything!
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26172#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.1fc87cabcb7432775fd3ceff81bb6749%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.