[Django] #20127: Unify subquery generation in the ORM

8 views
Skip to first unread message

Django

unread,
Mar 24, 2013, 5:20:42 PM3/24/13
to django-...@googlegroups.com
#20127: Unify subquery generation in the ORM
----------------------------------------------+--------------------
Reporter: akaariai | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
There are some different ways for doing subqueries in the ORM currently.
Query.split_exclude(), subqueries in deletion, as_nested_sql() and
SubqueryConstraint seem to do something similar. Sometimes there are
duplicated code paths, sometimes upper layers do something the lower
layers will repeat later on.

I think every instance where a subquery constrain is needed should use the
SubqueryConstraint either directly, or through QuerySet.filter() or
sql.Query.build_filter(). This will allow doing all the somewhat
complicated setup in one place.

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

Django

unread,
Mar 24, 2013, 5:20:54 PM3/24/13
to django-...@googlegroups.com
#20127: Unify subquery generation in the ORM
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: | Status: new
Cleanup/optimization | Version: master
Component: Database layer | Resolution:
(models, ORM) | Triage Stage: Accepted
Severity: Normal | Needs documentation: 0
Keywords: | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by akaariai):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Oct 8, 2015, 7:27:43 PM10/8/15
to django-...@googlegroups.com
#20127: Unify subquery generation in the ORM
-------------------------------------+-------------------------------------
Reporter: akaariai | 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
-------------------------------------+-------------------------------------
Description changed by timgraham:

Old description:

> There are some different ways for doing subqueries in the ORM currently.
> Query.split_exclude(), subqueries in deletion, as_nested_sql() and
> SubqueryConstraint seem to do something similar. Sometimes there are
> duplicated code paths, sometimes upper layers do something the lower
> layers will repeat later on.
>
> I think every instance where a subquery constrain is needed should use
> the SubqueryConstraint either directly, or through QuerySet.filter() or
> sql.Query.build_filter(). This will allow doing all the somewhat
> complicated setup in one place.

New description:

There are some different ways for doing subqueries in the ORM currently.

`Query.split_exclude()`, subqueries in deletion, `as_nested_sql()` and


`SubqueryConstraint` seem to do something similar. Sometimes there are
duplicated code paths, sometimes upper layers do something the lower
layers will repeat later on.

I think every instance where a subquery constraint is needed should use
the `SubqueryConstraint` class either directly, or through
`QuerySet.filter()` or `sql.Query.build_filter()`. This will allow doing


all the somewhat complicated setup in one place.

--

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

Reply all
Reply to author
Forward
0 new messages