summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
Commit message (Collapse)AuthorAgeFilesLines
* Fixed #33759 -- Avoided unnecessary subquery in QuerySet.delete() with ↵4the4ryushin2023-05-011-1/+4
| | | | self-referential subqueries if supported.
* Fixed #34368 -- Made subquery raise NotSupportedError when referencing outer ↵Simon Charette2023-02-271-1/+1
| | | | | | | | window expression. Regression in f387d024fc75569d2a4a338bfda76cc2f328f627. Co-authored-by: Jannis Vajen <jvajen@gmail.com>
* Fixed #34372 -- Fixed queryset crash on order by aggregation using OrderBy.Simon Charette2023-02-271-0/+2
| | | | | | Regression in 278881e37619278789942513916acafaa88d26f3 caused by a lack of expression copying when an OrderBy expression is explicitly provided. Thanks Jannis Vajen for the report and regression test.
* Fixed #34346 -- Ordered selected expressions by position.Simon Charette2023-02-201-8/+35
| | | | | | | | | Used the same approach as for #34176 by using selected expressions position to prevent ambiguous aliases in collisions. Thanks henribru for the report. Regression in 04518e310d4552ff7595a34f5a7f93487d78a406.
* Refs #34176 -- Adjusted group by position variables naming to follow SQL spec.Simon Charette2023-02-181-5/+5
| | | | This avoids conceptual collisions with the notion of indices.
* Fixed #34227 -- Fixed QuerySet.select_related() with multi-level ↵朱穆穆2023-01-241-1/+8
| | | | FilteredRelation.
* Fixed #34267 -- Fixed sliced QuerySet.union() crash.Francesco Panico2023-01-201-3/+0
| | | | | | Regression in 3d734c09ff0138441dfe0a59010435871d17950f. Thanks Raphaël Stefanini for the report.
* Fixed #34176 -- Fixed grouping by ambiguous aliases.Simon Charette2023-01-091-15/+24
| | | | | | | | | | | | | | | Regression in b7b28c7c189615543218e81319473888bc46d831. Refs #31377. Thanks Shai Berger for the report and reviews. test_aggregation_subquery_annotation_values_collision() has been updated as queries that are explicitly grouped by a subquery should always be grouped by it and not its outer columns even if its alias collides with referenced table columns. This was not possible to accomplish at the time 10866a10 landed because we didn't have compiler level handling of colliding aliases.
* Simplified SQLCompiler.get_group_by() a bit.Simon Charette2023-01-041-4/+2
|
* Fixed #34226 -- Fixed QuerySet.select_related() with multiple ↵朱穆穆2022-12-271-2/+2
| | | | FilteredRelations to the OneToOneField.
* Refs #34226 -- Renamed local field variables in ↵Mariusz Felisiak2022-12-241-12/+16
| | | | SQLCompiler.get_related_selections() to avoid redefinition.
* Refs #33308 -- Deprecated support for passing encoded JSON string literals ↵Simon Charette2022-12-011-9/+3
| | | | | | | to JSONField & co. JSON should be provided as literal Python objects an not in their encoded string literal forms.
* Fixed #34171 -- Fixed QuerySet.bulk_create() on fields with db_column in ↵DevilsAutumn2022-11-221-2/+2
| | | | | | | | unique_fields/update_fields. Bug in 0f6946495a8ec955b471ca1baaf408ceb53d4796. Thanks Joshua Brooks for the report.
* Fixed #34123 -- Fixed combinator order by alias when using select_related().Simon Charette2022-11-151-10/+20
| | | | | | | | Regression in c58a8acd413ccc992dd30afd98ed900897e1f719. Thanks to Shai Berger for the report and tests. Co-Authored-By: David Sanders <shang.xiao.sanders@gmail.com>
* Avoided unnecessary usage of RawSQL.Simon Charette2022-11-151-4/+4
| | | | This ensures proper alias quoting.
* Refs #33374 -- Adjusted full match condition handling.Simon Charette2022-11-071-12/+25
| | | | | | Adjusting WhereNode.as_sql() to raise an exception when encoutering a full match just like with empty matches ensures that all case are explicitly handled.
* Refs #17144 -- Removed support for grouping by primary key.Simon Charette2022-11-071-35/+4
| | | | | No core backend require the feature anymore as it was only added to support a MySQL'ism that has been deprecated since then.
* Fixed #31331 -- Switched MySQL to group by selected primary keys.Simon Charette2022-11-071-1/+3
| | | | | | MySQL 5.7.15 supports group by functional dependences so there is no need to special case group by main table primary key anymore and special case the ONLY_FULL_GROUP_BY sql mode.
* Used more augmented assignment statements.Nick Pope2022-10-311-1/+1
| | | | | | Identified using the following command: $ git grep -I '\(\<[_a-zA-Z0-9]\+\>\) *= *\1 *[-+/*^%&|<>@]'
* Fixed #34125 -- Fixed sliced QuerySet.union() crash on a single non-empty ↵Simon Charette2022-10-291-1/+5
| | | | | | | | | queryset. The bug existed since sliced query union was added but was elevated to query union slices by moving the .exists() optimization to the compiler in 3d734c09ff0138441dfe0a59010435871d17950f. Thanks Stefan Hammer for the report.
* Used Query.is_sliced in SQLCompiler.as_sql().Simon Charette2022-10-281-3/+1
|
* Fixed #34105 -- Fixed crash of ordering by nested selected expression.Simon Charette2022-10-181-6/+1
| | | | | | | | This stops ordering by nested selected references. It's not supported on PostgreSQL and not required to support psycopg3. Regression in 04518e310d4552ff7595a34f5a7f93487d78a406. Thanks Matt Westcott for the report.
* Refs #31150 -- Enabled implicit GROUP BY aliases.Simon Charette2022-10-061-4/+8
| | | | | | | This ensures implicit grouping from aggregate function annotations groups by uncollapsed selected aliases if supported. The feature is disabled on Oracle because it doesn't support it.
* Refs #33992 -- Refactored subquery grouping logic.Simon Charette2022-10-061-2/+7
| | | | | | | | | | | This required moving the combined queries slicing logic to the compiler in order to allow Query.exists() to be called at expression resolving time. It allowed for Query.exists() to be called at Exists() initialization time and thus ensured that get_group_by_cols() was operating on the terminal representation of the query that only has a single column selected.
* Refs #33308 -- Enabled explicit GROUP BY and ORDER BY aliases.Simon Charette2022-10-061-5/+18
| | | | | | | This ensures explicit grouping from using values() before annotating an aggregate function groups by selected aliases if supported. The GROUP BY feature is disabled on Oracle because it doesn't support it.
* Fixed #33768 -- Fixed ordering compound queries by nulls_first/nulls_last on ↵Simon Charette2022-10-051-10/+11
| | | | | | | | | | | MySQL. Columns of the left outer most select statement in a combined query can be referenced by alias just like by index. This removes combined query ordering by column index and avoids an unnecessary usage of RawSQL which causes issues for backends that specialize the treatment of null ordering.
* Avoided unnecessary call to .get_source_expressions().Simon Charette2022-10-041-2/+2
| | | | | The SQLCompiler._order_by_pairs() generator method yields instances of OrderBy and not Expression.
* Fixed #34012 -- Made QuerySet.order_by() apply transforms on related fields ↵David Sanders2022-10-041-1/+3
| | | | | | | | | | | for models with Meta.ordering. This makes QuerySet.order_by() no longer ignore trailing transforms for models with Meta.ordering. As a consequence, FieldError is raised in such cases for non-existent fields. Thanks to Klaas van Schelven for the report and Mariusz Felisiak for the review and advice.
* Refs #28333 -- Explicitly ordered outer qualify query on window filtering.Simon Charette2022-09-151-14/+42
| | | | | While most backends will propagate derived table ordering as long as the outer query doesn't perform additional processing the SQL specs doesn't explicitly state the ordering must be maintained.
* Fixed #33992 -- Fixed queryset crash when aggregating over a group ↵Simon Charette2022-09-081-1/+4
| | | | | | | | | | | | | containing Exists. A more in-depth solution is likely to make sure that we always GROUP BY selected annotations or revisit how we use Query.exists() in the Exists expression but that requires extra work that isn't suitable for a backport. Regression in e5a92d400acb4ca6a8e1375d1ab8121f2c7220be. Thanks Fernando Flores Villaça for the report.
* Fixed #21204 -- Tracked field deferrals by field instead of models.Simon Charette2022-08-301-24/+28
| | | | | This ensures field deferral works properly when a model is involved more than once in the same query with a distinct deferral mask.
* Refs #28333 -- Added partial support for filtering against window functions.Simon Charette2022-08-151-1/+75
| | | | | | | | | | | | | | | | | | | | Adds support for joint predicates against window annotations through subquery wrapping while maintaining errors for disjointed filter attempts. The "qualify" wording was used to refer to predicates against window annotations as it's the name of a specialized Snowflake extension to SQL that is to window functions what HAVING is to aggregates. While not complete the implementation should cover most of the common use cases for filtering against window functions without requiring the complex subquery pushdown and predicate re-aliasing machinery to deal with disjointed predicates against columns, aggregates, and window functions. A complete disjointed filtering implementation should likely be deferred until proper QUALIFY support lands or the ORM gains a proper subquery pushdown interface.
* Refs #28333 -- Moved SQLCompiler's forced column aliasing logic to get_select().Simon Charette2022-08-111-15/+14
| | | | | This extends query composability possibilities when dealing with subqueries which is necessary to implement window function filtering.
* Used AND, OR, XOR constants instead of hard-coded values.Nick Pope2022-07-271-1/+2
|
* Fixed #33796 -- Fixed ordered combined queryset crash when used in subquery ↵Mariusz Felisiak2022-06-271-0/+5
| | | | | | | | on PostgreSQL and MySQL. Thanks Shai Berger for the report. Regression in 30a01441347d5a2146af2944b29778fa0834d4be.
* Fixed #29538 -- Fixed crash of ordering by related fields when Meta.ordering ↵Ed Rivas2022-05-121-2/+7
| | | | | | contains expressions. Thanks Simon Charette for the review.
* Refs #32226 -- Fixed JSON format of QuerySet.explain() on PostgreSQL when ↵Mariusz Felisiak2022-04-191-3/+2
| | | | | format is uppercased. Follow up to aba9c2de669dcc0278c7ffde7981be91801be00b.
* Made select_for_update() don't raise TransactionManagementError on databases ↵Mariusz Felisiak2022-04-141-1/+6
| | | | that don't support transactions.
* Removed unnecessary tuple call in SQLInsertCompiler.David Smith2022-04-131-1/+1
|
* Fixed #33618 -- Fixed MTI updates outside of primary key chain.Simon Charette2022-04-071-2/+21
|
* Removed unnecessary Query.get_loaded_field_names_cb() and ↵Mariusz Felisiak2022-03-311-1/+1
| | | | Query.deferred_to_data()'s callback argument.
* Refs #24020 -- Removed redundant Query.get_loaded_field_names().Mariusz Felisiak2022-03-311-1/+1
| | | | | | get_loaded_field_names() is no longer called in multiple places (see 0c7633178fa9410f102e4708cef979b873bccb76) and it's redundant with SQLCompiler.deferred_to_columns().
* Refs #30581 -- Allowed sql.Query to be used without model.Gagaro2022-03-161-4/+9
|
* Refs #33476 -- Refactored code to strictly match 88 characters line length.Mariusz Felisiak2022-02-071-21/+10
|
* Refs #33476 -- Reformatted code with Black.django-bot2022-02-071-283/+487
|
* Fixed #31685 -- Added support for updating conflicts to QuerySet.bulk_create().sean_c_hsu2022-01-191-9/+14
| | | | | Thanks Florian Apolloner, Chris Jerdonek, Hannes Ljungberg, Nick Pope, and Mariusz Felisiak for reviews.
* Fixed #29338 -- Allowed using combined queryset in Subquery.Mariusz Felisiak2022-01-171-2/+7
| | | | Thanks Eugene Kovalev for the initial patch, Simon Charette for the review, and Chetan Khanna for help.
* Fixed #33309 -- Fixed QuerySet.distinct() crash on mixed case annotation.arsalan.ghassemi2021-11-231-1/+1
|
* Refs #24121 -- Added __repr__() to BaseDatabaseWrapper, JoinPromoter, and ↵Jonny Park2021-11-191-0/+7
| | | | SQLCompiler.
* Fixed #33260 -- Fixed crash when chaining QuerySet.exists() after ↵Hannes Ljungberg2021-11-031-0/+2
| | | | select_for_update(of=()).