From 0b0998dc151feb77068e2387c34cc50ef6b356ae Mon Sep 17 00:00:00 2001 From: 4the4ryushin Date: Fri, 28 Apr 2023 02:33:25 +0530 Subject: Fixed #33759 -- Avoided unnecessary subquery in QuerySet.delete() with self-referential subqueries if supported. --- django/db/models/sql/compiler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'django/db/models/sql') diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 07393e7605..a7a8c98b99 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1890,7 +1890,10 @@ class SQLDeleteCompiler(SQLCompiler): Create the SQL for this query. Return the SQL string and list of parameters. """ - if self.single_alias and not self.contains_self_reference_subquery: + if self.single_alias and ( + self.connection.features.delete_can_self_reference_subquery + or not self.contains_self_reference_subquery + ): return self._as_sql(self.query) innerq = self.query.clone() innerq.__class__ = Query -- cgit v1.3