#35294: Queryset explain truncated
-------------------------------------+-------------------------------------
Reporter: Gordon | Owner: nobody
Wrigley |
Type: | Status: new
Uncategorized |
Component: Database | Version: 4.2
layer (models, ORM) |
Severity: Normal | Keywords: explain
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django 4.2.10
Python 3.10.13
Postgres 15.6
Psycopg2 2.9.9
I have some very complex querysets I'm trying to optimize and what I've
run into is explain output is being truncated at 100 lines. As far as I
can tell this is because of this function on
django.db.models.sql.compiler.SQLCompiler.
{{{#!python
def explain_query(self):
result = list(self.execute_sql())
# Some backends return 1 item tuples with strings, and others
return
# tuples with integers and strings. Flatten them out into strings.
format_ = self.query.explain_info.format
output_formatter = json.dumps if format_ and format_.lower() ==
"json" else str
for row in result[0]:
if not isinstance(row, str):
yield " ".join(output_formatter(c) for c in row)
else:
yield row
}}}
Where `result[0]` is ignoring additional results. Monkey patching it to
{{{#!python
def explain_query(self):
results = list(self.execute_sql())
# Some backends return 1 item tuples with strings, and others
return
# tuples with integers and strings. Flatten them out into strings.
format_ = self.query.explain_info.format
output_formatter = json.dumps if format_ and format_.lower() ==
"json" else str
for result in results:
for row in result:
if not isinstance(row, str):
yield " ".join(output_formatter(c) for c in row)
else:
yield row
}}}
Gets me the full explain output.
--
Ticket URL: <https://code.djangoproject.com/ticket/35294>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018e332e02be-4752f9d4-b015-498e-a09d-2078fff945ca-000000%40eu-central-1.amazonses.com.