Re: Printing window function OVER clauses in EXPLAIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Printing window function OVER clauses in EXPLAIN
Date: 2025-03-09 22:19:49
Message-ID: 616793.1741558789@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> I'll go try to code this up.

OK, here's v2 done like that. I do like this output better.
I backed off the idea of putting the WindowClause as such
into the plan, partly because I didn't feel like debugging
the setrefs.c problem that David discovered upthread.
This way does require a bit more code, but I think it's less
likely to have bugs.

A couple of notes:

* I made the Window: plan annotation come out unconditionally.
We could alternatively print it only in VERBOSE mode, which would
greatly reduce the number of regression test diffs. However, it seems
fairly comparable to the sort keys of a Sort node or the group keys of
a Group node, which we print unconditionally. Also, there are cases
where a higher-level node unconditionally prints a reference to a
window function output, which would mean that that output's reference
to "windowN" would have no referent in the displayed data.

* In passing, I editorialized on the order in which the Run Condition
annotation comes out:

case T_WindowAgg:
+ show_window_def(castNode(WindowAggState, planstate), ancestors, es);
show_upper_qual(plan->qual, "Filter", planstate, ancestors, es);
+ show_upper_qual(((WindowAgg *) plan)->runConditionOrig,
+ "Run Condition", planstate, ancestors, es);
if (plan->qual)
show_instrumentation_count("Rows Removed by Filter", 1,
planstate, es);
- show_upper_qual(((WindowAgg *) plan)->runConditionOrig,
- "Run Condition", planstate, ancestors, es);
show_windowagg_info(castNode(WindowAggState, planstate), es);
break;

It seemed quite weird to me to have the Run Condition plan property
come out in the middle of properties that only appear in EXPLAIN
ANALYZE mode. Maybe there's a reason for this other than "people
added new properties at the end", but I don't see it.

regards, tom lane

Attachment Content-Type Size
v2-show-window-clauses-in-EXPLAIN.patch text/x-diff 77.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-03-09 22:23:49 Re: Parallel CREATE INDEX for GIN indexes
Previous Message Tomas Vondra 2025-03-09 22:17:29 Re: Parallel CREATE INDEX for GIN indexes