Every database that is supported in core supports this, usually by adding
`EXPLAIN` before the query. Simply returning whatever the database gives
you (which is vastly different per vendor and even version) could be a
good improvement.
--
Ticket URL: <https://code.djangoproject.com/ticket/28574>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Srinivas Reddy Thatiparthy):
+1 for this .
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:1>
* stage: Unreviewed => Accepted
Comment:
It looks reasonable at first glance.
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:2>
* cc: Tom (added)
* owner: nobody => Tom
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:3>
Comment (by Tom):
PR: https://github.com/django/django/pull/9053
On any select queryset you can do `print(qs.explain())` and it will print
the databases EXPLAIN output. There is a `verbose` and a `format` flag for
backends that support it, e.g on Mysql/Postgres
`print(qs.explain(verbose=True, format='json'))`
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:4>
* has_patch: 0 => 1
Comment:
I've updated the patch to include documentation. This works well on all
databases except MySQL, which returns a table structure rather than a
human-readable strings like PostgreSQL. Without the pseudo-table headers
it's not very useful, but it could be a lot more effort to add support for
this (we would have to deal with lining up the column headers with the
values, add support for returning the column names from the `execute_sql`
function).
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:7>
* stage: Accepted => Ready for checkin
Comment:
Patch looks good.
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:8>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
Comment:
The new tests fail on Oracle. Needs resolving. (Hopefully good to go
then.)
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:9>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:10>
Comment (by Tom Forbes):
I don't see how we can add support for Oracle, the way explaining query
plans works is significantly different from any other implementation,
including the fact that you cannot use SQL parameterized queries.
I've modified the patch to simply disable this feature on Oracle for now.
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:11>
* stage: Accepted => Ready for checkin
Comment:
This looks ready to go. Good work Tom!
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:12>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"c1c163b42717ed5e051098ebf0e2f5c77810f20e" c1c163b4]:
{{{
#!CommitTicketReference repository=""
revision="c1c163b42717ed5e051098ebf0e2f5c77810f20e"
Fixed #28574 -- Added QuerySet.explain().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:13>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"a5c5ae7d9120cba3206a0e31d23c22f4a14a10df" a5c5ae7d]:
{{{
#!CommitTicketReference repository=""
revision="a5c5ae7d9120cba3206a0e31d23c22f4a14a10df"
Refs #28574 -- Used feature flag for PostgreSQL version check.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:14>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"b3b04ad2111f1e3eb0640cd5d51d4391655317ce" b3b04ad2]:
{{{
#!CommitTicketReference repository=""
revision="b3b04ad2111f1e3eb0640cd5d51d4391655317ce"
Refs #28574 -- Added test for XML format output to Queryset.explain().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28574#comment:15>