[Django] #20939: Convert QuerySet to Query when filtering

21 views
Skip to first unread message

Django

unread,
Aug 19, 2013, 6:18:49 AM8/19/13
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: Database | Keywords:
layer (models, ORM) | Has patch: 0
Severity: Normal | Needs tests: 0
Triage Stage: Accepted | Easy pickings: 0
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
The current ORM coding has very similar, yet not equivalent paths for
using QuerySet and the internal Query when doing
filter(something=queryset_or_query). It seems that converting a QuerySet
to Query early on would lead to cleaner implementation. Proof of concept
here: https://github.com/akaariai/django/tree/queryset_to_query_in_filter

There are two problems in the current implementation:
- The way user-defined .values() and Django issued .values() in
build_filter() is detected is ugly
- There is no multidb protection (test_subquery in
multiple_database.tests.QueryTestCase) fails).

I'll mark this as accepted directly in the sense of "worth doing if above
problems can be addressed).

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

Django

unread,
Sep 23, 2016, 8:21:19 PM9/23/16
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I rebased and updated this to see if it's still worth doing and to learn
something in the process. It's still incomplete and tests aren't passing:
[https://github.com/django/django/pull/7289 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/20939#comment:1>

Django

unread,
Oct 28, 2016, 11:20:35 AM10/28/16
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"1bc249c2a67c24fcd28436c85388eff1d826e305" 1bc249c]:
{{{
#!CommitTicketReference repository=""
revision="1bc249c2a67c24fcd28436c85388eff1d826e305"
Fixed #20939 -- Simplified query generation by converting QuerySet to
Query.

Thanks Anssi Kääriäinen for the initial patch and Anssi, Simon Charette,
and Josh Smeaton for review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20939#comment:2>

Django

unread,
Apr 26, 2017, 12:02:45 AM4/26/17
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette <charette.s@…>):

In [changeset:"ec50937bcbe160e658ef881021402e156beb0eaf" ec50937]:
{{{
#!CommitTicketReference repository=""
revision="ec50937bcbe160e658ef881021402e156beb0eaf"
Refs #20939 -- Removed the Query._forced_pk hack.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20939#comment:3>

Django

unread,
Apr 26, 2017, 12:02:46 AM4/26/17
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette <charette.s@…>):

In [changeset:"c9159a082ebe41a1f735f8d01720e746fb43c41e" c9159a08]:
{{{
#!CommitTicketReference repository=""
revision="c9159a082ebe41a1f735f8d01720e746fb43c41e"
Refs #20939 -- Removed the Query._prepare_as_filter_value() hack.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20939#comment:4>

Django

unread,
Apr 27, 2017, 6:42:16 PM4/27/17
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette <charette.s@…>):

In [changeset:"e62ea0bb9cbb54c1eef848871fe3eab2bad268dc" e62ea0bb]:
{{{
#!CommitTicketReference repository=""
revision="e62ea0bb9cbb54c1eef848871fe3eab2bad268dc"
Refs #20939 -- Moved subquery ordering clearing optimization to the __in
lookup.

Queries could potentially be resolved in cases where ordering matter.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20939#comment:5>

Django

unread,
Apr 28, 2017, 9:30:58 AM4/28/17
to django-...@googlegroups.com
#20939: Convert QuerySet to Query when filtering
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"eb4724a0632928bda2a512a9117a91260096e457" eb4724a0]:
{{{
#!CommitTicketReference repository=""
revision="eb4724a0632928bda2a512a9117a91260096e457"
Reverted "Refs #20939 -- Moved subquery ordering clearing optimization to
the __in lookup."

This reverts commit e62ea0bb9cbb54c1eef848871fe3eab2bad268dc since it
broke multi-column __in lookups and _meta.order_wrt on Oracle.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20939#comment:6>

Reply all
Reply to author
Forward
0 new messages