summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/operations.py
diff options
context:
space:
mode:
authorRoman <roman1972@gmail.com>2021-10-11 23:53:53 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-11-02 21:30:21 +0100
commit407fe95cb116599adeb4b9ed01df5673aa5cb1db (patch)
treeced14903df06d08c69586229e6f989ffb955e500 /django/db/backends/mysql/operations.py
parentaaf9b558583d9bb75a0c9d53b135dc8c1b75b6a2 (diff)
downloaddjango-407fe95cb116599adeb4b9ed01df5673aa5cb1db.tar.gz
Fixed #32691 -- Made Exact lookup on BooleanFields compare directly to a boolean value on MySQL.
Performance regression in 37e6c5b79bd0529a3c85b8c478e4002fd33a2a1d. Thanks Todor Velichkov for the report. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r--django/db/backends/mysql/operations.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index 89730cee29..d5cd374cc5 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -2,6 +2,7 @@ import uuid
from django.conf import settings
from django.db.backends.base.operations import BaseDatabaseOperations
+from django.db.models import Exists, ExpressionWrapper, Lookup
from django.utils import timezone
from django.utils.encoding import force_str
@@ -378,3 +379,14 @@ class DatabaseOperations(BaseDatabaseOperations):
):
lookup = 'JSON_UNQUOTE(%s)'
return lookup
+
+ def conditional_expression_supported_in_where_clause(self, expression):
+ # MySQL ignores indexes with boolean fields unless they're compared
+ # directly to a boolean value.
+ if isinstance(expression, (Exists, Lookup)):
+ return True
+ if isinstance(expression, ExpressionWrapper) and expression.conditional:
+ return self.conditional_expression_supported_in_where_clause(expression.expression)
+ if getattr(expression, 'conditional', False):
+ return False
+ return super().conditional_expression_supported_in_where_clause(expression)