﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35294	Queryset explain can be truncated.	Gordon Wrigley	Adam Johnson	"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."	Bug	closed	Database layer (models, ORM)	4.2	Normal	fixed	explain	Gordon Wrigley	Ready for checkin	1	0	0	0	0	0
