display of variables in EXPLAIN VERBOSE

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: display of variables in EXPLAIN VERBOSE
Date: 2019-04-22 07:49:19
Message-ID: b04a8d5d-2c79-f857-2e8d-3790e77dffe5@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

ISTM show_plan_tlist()'s rule of whether to the show range table prefix
with displayed variables contradicts the description of the VERBOSE option
in EXPLAIN documentation, which is as follows:

=======
VERBOSE

Display additional information regarding the plan. Specifically, include
the output column list for each node in the plan tree, schema-qualify
table and function names, always label variables in expressions with their
range table alias, and always print the name of each trigger for which
statistics are displayed. This parameter defaults to FALSE.
=======

Specifically, the current behavior contradicts the part of the sentence
that says "always label variables in expressions with their range table
alias". See this example:

create table foo (a int);
create table foo1 () inherits (foo);

-- "a" is not labeled here
explain verbose select * from only foo order by 1;
QUERY PLAN
────────────────────────────────────────────────────────────────
Sort (cost=0.01..0.02 rows=1 width=4)
Output: a
Sort Key: foo.a
-> Seq Scan on public.foo (cost=0.00..0.00 rows=1 width=4)
Output: a
(5 rows)

-- it's labeled in this case
explain verbose select * from foo order by 1;
QUERY PLAN
───────────────────────────────────────────────────────────────────────────
Sort (cost=192.60..198.98 rows=2551 width=4)
Output: foo.a
Sort Key: foo.a
-> Append (cost=0.00..48.26 rows=2551 width=4)
-> Seq Scan on public.foo (cost=0.00..0.00 rows=1 width=4)
Output: foo.a
-> Seq Scan on public.foo1 (cost=0.00..35.50 rows=2550 width=4)
Output: foo1.a
(8 rows)

Seeing that "Sort Key" is always displayed with the range table alias, I
checked explain.c to see why the discrepancy exists and it seems that
show_plan_tlist() (and show_tablesample()) use the following condition for
whether or not to use the range table prefix:

useprefix = list_length(es->rtable) > 1;

whereas other functions, including show_sort_group_keys() that prints the
"Sort Key", use the following condition:

useprefix = (list_length(es->rtable) > 1 || es->verbose);

I can think of two ways we could do:

1. Change show_plan_tlist() and show_tablesample() to use the same rule as
others

2. Change other functions to use the same rule as show_plan_tlist(), also
updating the documentation to note the exceptional case when column names
are not prefixed

Thoughts?

Thanks,
Amit

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2019-04-22 10:09:55 Re: Allow any[] as input arguments for sql/plpgsql functions to mimic format()
Previous Message Kyotaro HORIGUCHI 2019-04-22 07:40:27 Re: standby recovery fails (tablespace related) (tentative patch and discussion)