mirror of
https://github.com/django/django.git
synced 2025-11-28 14:37:59 +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
|
|
@ -65,6 +65,14 @@ class Coalesce(Func):
|
|||
raise ValueError('Coalesce must take at least two expressions')
|
||||
super().__init__(*expressions, **extra)
|
||||
|
||||
@property
|
||||
def empty_aggregate_value(self):
|
||||
for expression in self.get_source_expressions():
|
||||
result = expression.empty_aggregate_value
|
||||
if result is NotImplemented or result is not None:
|
||||
return result
|
||||
return None
|
||||
|
||||
def as_oracle(self, compiler, connection, **extra_context):
|
||||
# Oracle prohibits mixing TextField (NCLOB) and CharField (NVARCHAR2),
|
||||
# so convert all fields to NCLOB when that type is expected.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue