Обсуждение: add a new explain option including_query for include query string inside the json plan output

Поиск
Список
Период
Сортировка
for json format, add a new option to let the explain json output also
include the actual query string.

it can make json usage more convenient.
Now you only need to grab the json output, no need to
collect another explain statement and extract the actual query from
the explain statement.

including_query name is so far what i can come up with, if people have
better ideas, then we can change.

example:
explain (analyze,including_query on, format json) select 1;
             QUERY PLAN
-------------------------------------
 [                                  +
   {"Query": "select 1"},           +
   {                                +
     "Plan": {                      +
       "Node Type": "Result",       +
       "Parallel Aware": false,     +
       "Async Capable": false,      +
       "Startup Cost": 0.00,        +
       "Total Cost": 0.01,          +
       "Plan Rows": 1,              +
       "Plan Width": 4,             +
       "Actual Startup Time": 0.001,+
       "Actual Total Time": 0.001,  +
       "Actual Rows": 1,            +
       "Actual Loops": 1            +
     },                             +
     "Planning Time": 0.119,        +
     "Triggers": [                  +
     ],                             +
     "Execution Time": 0.033        +
   }                                +
 ]
(1 row)



On Tue, 25 Jun 2024 at 10:55, jian he <jian.universality@gmail.com> wrote:
>
> for json format, add a new option to let the explain json output also
> include the actual query string.

How would this cooperate with e.g. EXPLAIN (...) EXECUTE
my_prepared_statement? Would this query be the prepared statement's
query, or the top-level EXECUTE statement?

> it can make json usage more convenient.
> Now you only need to grab the json output, no need to
> collect another explain statement and extract the actual query from
> the explain statement.

Wouldn't the user be able to keep track of the query they wanted
explained by themselves? If not, why?

> example:
> explain (analyze,including_query on, format json) select 1;
>              QUERY PLAN
> -------------------------------------
>  [                                  +
>    {"Query": "select 1"},           +
>    {                                +
>      "Plan": {                      +

If we were to add the query to the explain output, I think it should
be a top-level key in the same JSON object that holds the "Plan",
Triggers, and "Execution Time" keys.

Kind regards,

Matthias van de Meent
Neon (https://neon.tech)



Matthias van de Meent <boekewurm+postgres@gmail.com> writes:
> On Tue, 25 Jun 2024 at 10:55, jian he <jian.universality@gmail.com> wrote:
>> for json format, add a new option to let the explain json output also
>> include the actual query string.

> Wouldn't the user be able to keep track of the query they wanted
> explained by themselves? If not, why?

Indeed.  I do not think this is a good idea at all, even if the
question of "where did you get the query string from" could be
resolved satisfactorily.

            regards, tom lane