mirror of
https://github.com/django/django.git
synced 2025-08-22 03:24:21 +00:00
Refs #26430 -- Re-introduced empty aggregation optimization.
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.
This commit is contained in:
parent
f3112fde98
commit
9f3cce172f
8 changed files with 101 additions and 34 deletions
|
@ -153,6 +153,7 @@ class BaseExpression:
|
|||
# aggregate specific fields
|
||||
is_summary = False
|
||||
_output_field_resolved_to_none = False
|
||||
empty_aggregate_value = NotImplemented
|
||||
# Can the expression be used in a WHERE clause?
|
||||
filterable = True
|
||||
# Can the expression can be used as a source expression in Window?
|
||||
|
@ -795,6 +796,10 @@ class Value(SQLiteNumericMixin, Expression):
|
|||
if isinstance(self.value, UUID):
|
||||
return fields.UUIDField()
|
||||
|
||||
@property
|
||||
def empty_aggregate_value(self):
|
||||
return self.value
|
||||
|
||||
|
||||
class RawSQL(Expression):
|
||||
def __init__(self, sql, params, output_field=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue