summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-09-26 12:05:26 +0200
committerGitHub <noreply@github.com>2023-09-26 12:05:26 +0200
commitf9e9526800c921ae393ff58826daed51587b1727 (patch)
tree14d365bbaee49850faa7e64f9dc0f9b7f67b87a7
parent357365a64e1c756eabaaf0ee0404df87c15c6e9b (diff)
Fixed #34873 -- Added QuerySet.explain() support for GENERIC_PLAN option on PostgreSQL 16+.
-rw-r--r--django/db/backends/postgresql/features.py4
-rw-r--r--django/db/backends/postgresql/operations.py1
-rw-r--r--docs/ref/models/querysets.txt4
-rw-r--r--docs/releases/5.1.txt3
-rw-r--r--tests/queries/test_explain.py2
5 files changed, 13 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py
index c4398c9ad3..f2c3800307 100644
--- a/django/db/backends/postgresql/features.py
+++ b/django/db/backends/postgresql/features.py
@@ -134,6 +134,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
def is_postgresql_15(self):
return self.connection.pg_version >= 150000
+ @cached_property
+ def is_postgresql_16(self):
+ return self.connection.pg_version >= 160000
+
has_bit_xor = property(operator.attrgetter("is_postgresql_14"))
supports_covering_spgist_indexes = property(operator.attrgetter("is_postgresql_14"))
supports_unlimited_charfield = True
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 4a42126e81..06981bc094 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -31,6 +31,7 @@ class DatabaseOperations(BaseDatabaseOperations):
"ANALYZE",
"BUFFERS",
"COSTS",
+ "GENERIC_PLAN",
"SETTINGS",
"SUMMARY",
"TIMING",
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index b89341bc6a..3295e4ce7d 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -3076,6 +3076,10 @@ adverse effects on your database. For example, the ``ANALYZE`` flag supported
by MariaDB, MySQL 8.0.18+, and PostgreSQL could result in changes to data if
there are triggers or if a function is called, even for a ``SELECT`` query.
+.. versionchanged:: 5.1
+
+ Support for the ``generic_plan`` option on PostgreSQL 16+ was added.
+
.. _field-lookups:
``Field`` lookups
diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt
index 12e3c80ee2..1e2eb97557 100644
--- a/docs/releases/5.1.txt
+++ b/docs/releases/5.1.txt
@@ -168,7 +168,8 @@ Migrations
Models
~~~~~~
-* ...
+* :meth:`.QuerySet.explain` now supports the ``generic_plan`` option on
+ PostgreSQL 16+.
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
diff --git a/tests/queries/test_explain.py b/tests/queries/test_explain.py
index f04153754b..980e8e9621 100644
--- a/tests/queries/test_explain.py
+++ b/tests/queries/test_explain.py
@@ -85,6 +85,8 @@ class ExplainTests(TestCase):
{"settings": True},
{"analyze": True, "wal": True},
]
+ if connection.features.is_postgresql_16:
+ test_options.append({"generic_plan": True})
for options in test_options:
with self.subTest(**options), transaction.atomic():
with CaptureQueriesContext(connection) as captured_queries: