diff options
| author | Simon Charette <charette.s@gmail.com> | 2023-05-21 16:59:56 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-05-22 05:47:29 +0200 |
| commit | 98f6ada0e2058d67d91fb6c16482411ec2ca0967 (patch) | |
| tree | e34d4fb7841605fa4fad6e055463d30b7ea2ba25 /django/db/models/sql/compiler.py | |
| parent | 00f5d2d110712af84fae2c5f9183a2ea48ce0a4a (diff) | |
Fixed #34580 -- Avoided unnecessary computation of selected expressions in SQLCompiler.
Performance regression in 278881e37619278789942513916acafaa88d26f3.
Co-authored-by: David Smith <smithdc@gmail.com>
Diffstat (limited to 'django/db/models/sql/compiler.py')
| -rw-r--r-- | django/db/models/sql/compiler.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index a7a8c98b99..b28dc925ba 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -331,7 +331,9 @@ class SQLCompiler: default_order, _ = ORDER_DIR["DESC"] selected_exprs = {} - if select := self.select: + # Avoid computing `selected_exprs` if there is no `ordering` as it's + # relatively expensive. + if ordering and (select := self.select): for ordinal, (expr, _, alias) in enumerate(select, start=1): pos_expr = PositionRef(ordinal, alias, expr) if alias: |
