summaryrefslogtreecommitdiff
path: root/django/db/backends
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2022-08-10 08:22:01 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-15 08:26:26 +0200
commitf387d024fc75569d2a4a338bfda76cc2f328f627 (patch)
tree61994be69d4dfa545158f7e887f0673ec281e479 /django/db/backends
parentf3f9d03edf17ccfa17263c7efa0b1350d1ac9278 (diff)
Refs #28333 -- Added partial support for filtering against window functions.
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.
Diffstat (limited to 'django/db/backends')
-rw-r--r--django/db/backends/mysql/compiler.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/django/db/backends/mysql/compiler.py b/django/db/backends/mysql/compiler.py
index a8ab03a55e..bd2715fb43 100644
--- a/django/db/backends/mysql/compiler.py
+++ b/django/db/backends/mysql/compiler.py
@@ -28,10 +28,13 @@ class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
# the SQLDeleteCompiler's default implementation when multiple tables
# are involved since MySQL/MariaDB will generate a more efficient query
# plan than when using a subquery.
- where, having = self.query.where.split_having()
- if self.single_alias or having:
- # DELETE FROM cannot be used when filtering against aggregates
- # since it doesn't allow for GROUP BY and HAVING clauses.
+ where, having, qualify = self.query.where.split_having_qualify(
+ must_group_by=self.query.group_by is not None
+ )
+ if self.single_alias or having or qualify:
+ # DELETE FROM cannot be used when filtering against aggregates or
+ # window functions as it doesn't allow for GROUP BY/HAVING clauses
+ # and the subquery wrapping (necessary to emulate QUALIFY).
return super().as_sql()
result = [
"DELETE %s FROM"