Printing window function OVER clauses in EXPLAIN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Printing window function OVER clauses in EXPLAIN
Date: 2025-03-08 21:39:15
Message-ID: 144530.1741469955@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

While thinking about the discussion at [1], I got annoyed about
how EXPLAIN still can't print a useful description of window
functions' window clauses (it just emits "OVER (?)"). The
difficulty is that there's no access to the original WindowClause
anymore; else we could re-use the ruleutils.c code that dumps
those. It struck me that we could fix that by making WindowAgg
plan nodes keep the WindowClause as a sub-node, replacing their
current habit of having most of the WindowClause's fields as
loose fields in the WindowAgg node. A little bit later I had
a working patch, as attached. I think this data structure change
is about a wash for performance outside of EXPLAIN. It requires
a few extra indirections during ExecInitWindowAgg, but there's
no change in code used during the plan's execution.

One thing that puzzled me a bit is that many of the outputs
show "ROWS UNBOUNDED PRECEDING" in window functions where that
definitely wasn't in the source query. Eventually I realized
that that comes from window_row_number_support() and cohorts
optimizing the query. While this isn't wrong, I suspect it
will cause a lot of confusion and questions. I wonder if we
should do something to hide the change?

regards, tom lane

[1] https://www.postgresql.org/message-id/flat/CABde6B5va2wMsnM79u_x%3Dn9KUgfKQje_pbLROEBmA9Ru5XWidw%40mail.gmail.com

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-03-08 21:57:25 Re: Clarification on Role Access Rights to Table Indexes
Previous Message Ayush Vatsa 2025-03-08 21:31:41 Re: Clarification on Role Access Rights to Table Indexes