summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorKeryn Knight <keryn@kerynknight.com>2021-08-14 15:30:54 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-08-19 13:28:59 +0200
commitbf5abf1bdcedb15e949db419c61eeec7c88414ea (patch)
treead3354a181a6a2d8cb75cab7e9dc4087ce72990f /django/db/models/sql/query.py
parentfaf6d48590386987a08178ca0d7154b1500560b8 (diff)
Fixed #33025 -- Avoided accessing the database connections in Query.build_lookup() when not necessary.
Of the built-in backends, only Oracle treats empty strings and nulls as equal, so avoid testing the default connection backend for interprets_empty_strings_as_nulls if it can be established from the lookup that it wouldn't affect the lookup instance returned. This improves performance a small amount for most lookups being built, because accessing the connections requires touching the thread critical `Local` which is an expensive operation.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 181d4419fa..1258eb61a9 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1192,8 +1192,11 @@ class Query(BaseExpression):
# stage because join promotion can't be done in the compiler. Using
# DEFAULT_DB_ALIAS isn't nice but it's the best that can be done here.
# A similar thing is done in is_nullable(), too.
- if (connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls and
- lookup_name == 'exact' and lookup.rhs == ''):
+ if (
+ lookup_name == 'exact' and
+ lookup.rhs == '' and
+ connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls
+ ):
return lhs.get_lookup('isnull')(lhs, True)
return lookup