summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Fixed #32996 -- Cached PathInfos on relations.Keryn Knight2021-11-031-2/+5
| | | | | | PathInfo values are ostensibly static over the lifetime of the object for which they're requested, so the data can be memoized, quickly amortising the cost over the process' duration.
* Refs #25265 -- Allowed Query subclasses to build filters.Erik Cederstrand2021-10-131-1/+1
|
* Refs #26430 -- Removed unused branch in sql.Query.get_count().Simon Charette2021-10-061-4/+1
| | | | | | Now that sql.Query.get_aggregation() properly deals with empty result sets summary Count() annotations cannot result in None. Unused since 9f3cce172f6913c5ac74272fa5fc07f847b4e112.
* Fixed #33018 -- Fixed annotations with empty queryset.David Wobrock2021-09-291-0/+1
| | | | Thanks Simon Charette for the review and implementation idea.
* Fixed #33141 -- Renamed Expression.empty_aggregate_value to ↵David Wobrock2021-09-291-4/+4
| | | | empty_result_set_value.
* Fixed #33124 -- Avoided accessing the database connections when not necessary.Keryn Knight2021-09-241-4/+4
| | | | | | Follow up to bf5abf1bdcedb15e949db419c61eeec7c88414ea. This also caches the __getitem__ access.
* Refs #27624 -- Optimized Query.clone() for non-combined queries.Keryn Knight2021-09-201-1/+4
| | | | | This avoids constructing a generator expression and a new tuple if the Query has no combined queries.
* Refs #27624 -- Changed Query.explain_info to namedtuple.Adam Johnson2021-09-171-6/+5
|
* Optimized Query.clone() a bit.Adam Johnson2021-09-171-9/+3
| | | | | This removes unnecessary "if ... is None" branches, which are already shallow-copied in the __dict__.copy() call.
* Fixed #33073 -- Fixed queryset crash with aggregation and empty/extra ↵David Wobrock2021-09-011-1/+1
| | | | queryset annotation.
* Fixed #33025 -- Avoided accessing the database connections in ↵Keryn Knight2021-08-191-2/+5
| | | | | | | | | | | | Query.build_lookup() when not necessary. Of the built-in backends, only Oracle treats empty strings and nulls as equal, so avoid testing the default connection backend for interprets_empty_strings_as_nulls if it can be established from the lookup that it wouldn't affect the lookup instance returned. This improves performance a small amount for most lookups being built, because accessing the connections requires touching the thread critical `Local` which is an expensive operation.
* Refs #32946 -- Changed Query.add_filter() to take two arguments.Keryn Knight2021-07-281-8/+8
|
* Fixed #32951 -- Removed Query.where_class & co.Nick Pope2021-07-221-11/+11
| | | | Unused since 3caf957ed5eaa831a485abcb89f27266dbf3e82b.
* Fixed #32704 -- Fixed list of deferred fields when chaining QuerySet.defer() ↵David Wobrock2021-07-201-1/+6
| | | | after only().
* Fixed #32944 -- Avoided unnecessary WhereNode.add() calls.Keryn Knight2021-07-201-7/+3
| | | Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
* Refs #32508 -- Raised Type/ValueError instead of using "assert" in ↵Daniyal2021-07-151-6/+6
| | | | | | django.db.models. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
* Fixed #27021 -- Allowed lookup expressions in annotations, aggregations, and ↵Ian Foote2021-07-091-3/+3
| | | | | | | | QuerySet.filter(). Thanks Hannes Ljungberg and Simon Charette for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
* Refs #26430 -- Re-introduced empty aggregation optimization.Simon Charette2021-07-021-1/+8
| | | | | | | | | | | | The introduction of the Expression.empty_aggregate_value interface allows the compilation stage to enable the EmptyResultSet optimization if all the aggregates expressions implement it. This also removes unnecessary RegrCount/Count.convert_value() methods. Disabling the empty result set aggregation optimization when it wasn't appropriate prevented None returned for a Count aggregation value. Thanks Nick Pope for the review.
* Fixed #26430 -- Fixed coalesced aggregation of empty result sets.Simon Charette2021-07-021-5/+3
| | | | | Disable the EmptyResultSet optimization when performing aggregation as it might interfere with coalescence.
* Fixed #32786 -- Moved subquery ordering clearing optimization to the _in lookup.Hannes Ljungberg2021-06-301-6/+7
| | | | Co-Authored-By: Simon Charette <charette.s@gmail.com>
* Refs #32786 -- Made Query.clear_ordering() not to cause side effects by default.Hannes Ljungberg2021-06-301-13/+16
|
* Removed unnecessary reuse_with_filtered_relation argument from Query methods.Nick Pope2021-04-281-30/+9
| | | | | | | | | | | | | | | | In Query.join() the argument reuse_with_filtered_relation was used to determine whether to use == or .equals(). As this area of code is related to aliases, we only expect an instance of Join or BaseTable to be provided - the only two classes that provide .equals(). In both cases, the implementations of __eq__() and equals() are based on use of the "identity" property. __eq__() performs an isinstance() check first, returning NotImplemented if required. BaseTable.equals() then does a straightforward equality check on "identity". Join.equals() is a little bit different as it skips checking the last element of the "identity" property: filtered_relation. This was only included previously when the with_filtered_relation argument was True, impossible since bbf141bcdc31f1324048af9233583a523ac54c94.
* Removed unused with_filtered_relation argument from .equals()Nick Pope2021-04-281-1/+1
| | | | Unused since bbf141bcdc31f1324048af9233583a523ac54c94.
* Fixed #32632, Fixed #32657 -- Removed flawed support for Subquery ↵Simon Charette2021-04-281-9/+0
| | | | | | | | | | | | | | | | | | deconstruction. Subquery deconstruction support required implementing complex and expensive equality rules for sql.Query objects for little benefit as the latter cannot themselves be made deconstructible to their reference to model classes. Making Expression @deconstructible and not BaseExpression allows interested parties to conform to the "expression" API even if they are not deconstructible as it's only a requirement for expressions allowed in Model fields and meta options (e.g. constraints, indexes). Thanks Phillip Cutter for the report. This also fixes a performance regression in bbf141bcdc31f1324048af9233583a523ac54c94.
* Fixed #32650 -- Fixed handling subquery aliasing on queryset combination.Simon Charette2021-04-211-0/+4
| | | | | | | | | | This issue started manifesting itself when nesting a combined subquery relying on exclude() since 8593e162c9cb63a6c0b06daf045bc1c21eb4d7c1 but sql.Query.combine never properly handled subqueries outer refs in the first place, see QuerySetBitwiseOperationTests.test_subquery_aliases() (refs #27149). Thanks Raffaele Salmaso for the report.
* Refs #32508 -- Raised TypeError instead of using "assert" on unsupported ↵Mariusz Felisiak2021-03-101-2/+2
| | | | operations for sliced querysets.
* Fixed #32478 -- Included nested columns referenced by subqueries in GROUP BY ↵Simon Charette2021-02-241-3/+8
| | | | | | | | | | on aggregations. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Refs #31094, #31150. Thanks Igor Pejic for the report.
* Refs #7098 -- Removed support for passing raw column aliases to order_by().Mariusz Felisiak2021-01-141-11/+0
| | | | Per deprecation timeline.
* Refs #30158 -- Made alias argument required in signature of ↵Mariusz Felisiak2021-01-141-14/+3
| | | | | | Expression.get_group_by_cols() subclasses. Per deprecation timeline.
* Fixed #32231 -- Allowed passing None params to QuerySet.raw().Alexander Lyabah2021-01-051-2/+8
|
* Fixed #25534, Fixed #31639 -- Added support for transform references in ↵Ian Foote2020-11-271-4/+9
| | | | | | expressions. Thanks Mariusz Felisiak and Simon Charette for reviews.
* Fixed #31507 -- Added QuerySet.exists() optimizations to compound queries.David-Wobrock2020-11-161-3/+10
|
* Fixed #31496 -- Fixed QuerySet.values()/values_list() crash on combined ↵David-Wobrock2020-11-141-2/+2
| | | | querysets ordered by annotations.
* Fixed #31910 -- Fixed crash of GIS aggregations over subqueries.Simon Charette2020-11-041-11/+3
| | | | | | | | | | | | | | | | | | | | | | | Regression was introduced by fff5186 but was due a long standing issue. AggregateQuery was abusing Query.subquery: bool by stashing its compiled inner query's SQL for later use in its compiler which made select_format checks for Query.subquery wrongly assume the provide query was a subquery. This patch prevents that from happening by using a dedicated inner_query attribute which is compiled at a later time by SQLAggregateCompiler. Moving the inner query's compilation to SQLAggregateCompiler.compile had the side effect of addressing a long standing issue with aggregation subquery pushdown which prevented converters from being run. This is now fixed as the aggregation_regress adjustments demonstrate. Refs #25367. Thanks Eran Keydar for the report.
* Fixed #32152 -- Fixed grouping by subquery aliases.Christian Klus2020-10-291-1/+3
| | | | | | Regression in 42c08ee46539ef44f8658ebb1cbefb408e0d03fe. Thanks Simon Charette for the review.
* Fixed #32143 -- Used EXISTS to exclude multi-valued relationships.Simon Charette2020-10-281-18/+14
| | | | | | As mentioned in the pre-existing split_exclude() docstring EXISTS is easier to optimize for query planers and circumvents the IN (NULL) handling issue.
* Refs #27149 -- Fixed sql.Query identity.Simon Charette2020-10-281-0/+9
| | | | | | By making Query subclass BaseExpression in 35431298226165986ad07e91f9d3aca721ff38ec the former defined it's identity based off _construct_args which is not appropriate.
* Fixed #32134 -- Fixed crash of __range lookup with namedtuple.Adam Johnson2020-10-231-1/+5
| | | | | | Regression in 8be79984dce7d819879a6e594ca69c5f95a08378. Thanks Gordon Wrigley for the report.
* Fixed #31792 -- Made Exists() reuse QuerySet.exists() optimizations.Simon Charette2020-08-131-1/+7
| | | | | | The latter is already optimized to limit the number of results, avoid selecting unnecessary fields, and drop ordering if possible without altering the semantic of the query.
* Fixed #27719 -- Added QuerySet.alias() to allow creating reusable aliases.Alexandr Tatarinov2020-07-311-2/+15
| | | | | | | | QuerySet.alias() allows creating reusable aliases for expressions that don't need to be selected but are used for filtering, ordering, or as a part of complex expressions. Thanks Simon Charette for reviews.
* Fixed #29789 -- Added support for nested relations to FilteredRelation.matt ferrante2020-07-091-8/+31
|
* Fixed #31767 -- Fixed QuerySet.none() on combined queryset.Mariusz Felisiak2020-07-071-0/+3
|
* Fixed #23797 -- Fixed QuerySet.exclude() when rhs is a nullable column.Jacob Walls2020-07-061-6/+13
|
* Fixed #31664 -- Reallowed using non-expressions having filterable attribute ↵Nicolas Baccelli2020-06-081-1/+4
| | | | | | as rhs in queryset filters. Regression in 4edad1ddf6203326e0be4bdb105beecb0fe454c4.
* Fixed #30375 -- Added FOR NO KEY UPDATE support to ↵Manuel Weitzman2020-05-211-0/+1
| | | | QuerySet.select_for_update() on PostgreSQL.
* Fixed #31568 -- Fixed alias reference when aggregating over multiple subqueries.Simon Charette2020-05-141-1/+1
| | | | | | | | | | | | | 691def10a0197d83d2d108bd9043b0916d0f09b4 made all Subquery() instances equal to each other which broke aggregation subquery pushdown which relied on object equality to determine which alias it should select. Subquery.__eq__() will be fixed in an another commit but Query.rewrite_cols() should haved used object identity from the start. Refs #30727, #30188. Thanks Makina Corpus for the report.
* Fixed #31566 -- Fixed aliases crash when chaining values()/values_list() ↵Simon Charette2020-05-141-0/+9
| | | | | | | | | | | after annotate() with aggregations and subqueries. Subquery annotation references must be resolved if they are excluded from the GROUP BY clause by a following .values() call. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Thanks Makina Corpus for the report.
* Fixed #31426 -- Added proper field validation to QuerySet.order_by().Simon Charette2020-04-061-4/+14
| | | | | Resolve the field reference instead of using fragile regex based string reference validation.
* Refs #7098 -- Deprecated passing raw column aliases to order_by().Simon Charette2020-04-061-1/+10
| | | | | | | | Now that order_by() has expression support passing RawSQL() can achieve the same result. This was also already supported through QuerySet.extra(order_by) for years but this API is more or less deprecated at this point.
* Fixed #31420 -- Fixed crash when filtering subquery annotation against a ↵Hasan Ramezani2020-04-061-1/+2
| | | | | | SimpleLazyObject. Thanks Simon Charette for the solution and analysis.