pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chantal Keller <chantal.keller@universite-paris-saclay.fr>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Explain and filter over subplans
Date: Thu, 18 Jan 2024 12:55:40 -0500
Message-ID: <2289721.1705600540@sss.pgh.pa.us> (raw)
In-Reply-To: <149c5c2f-4267-44e3-a177-d1fd24c53f6d@universite-paris-saclay.fr>
References: <149c5c2f-4267-44e3-a177-d1fd24c53f6d@universite-paris-saclay.fr>

Chantal Keller <chantal.keller@universite-paris-saclay.fr> writes:
> I would like "explain" to output formulas for filtering over
> subplans. Is it possible?

No, and that's been a to-do item for a long time.

Currently, EXPLAIN just ignores the "testexpr" field of SubPlan
nodes, which is what you are after.  We could print it, if we
could figure out an intelligible representation.  In the example
you give, the testexpr would probably render as "t.a >= $0"
where $0 represents the subplan's output column.

A very rough sketch, perhaps, is that instead of just
"(SubPlan 1)", we could print "(ALL t.a >= $0 FROM SubPlan 1)".
Some of the other SubLinkTypes might be harder to represent
in a way that makes sense to users.

I made a quick-hack patch to play with, if you're interested.

			regards, tom lane

Attachments:

wip-show-subplan-testexpr-in-explain.patch (text/x-diff, 1.8K) download diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 0b2a164057..5b81e2c4cf 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -8869,12 +8869,43 @@ get_rule_expr(Node *node, deparse_context *context, * We cannot see an already-planned subplan in rule deparsing, * only while EXPLAINing a query plan. We don't try to * reconstruct the original SQL, just reference the subplan - * that appears elsewhere in EXPLAIN's result. + * that appears elsewhere in EXPLAIN's result. It does seem + * useful to show the testexpr, however, and we also note + * whether the subplan will be hashed. */ + switch (subplan->subLinkType) + { + case EXISTS_SUBLINK: + appendStringInfoString(buf, "(EXISTS"); + break; + case ALL_SUBLINK: + appendStringInfoString(buf, "(ALL "); + break; + case ANY_SUBLINK: + appendStringInfoString(buf, "(ANY "); + break; + case ROWCOMPARE_SUBLINK: + appendStringInfoString(buf, "(ROWCOMPARE "); + break; + case EXPR_SUBLINK: + appendStringInfoString(buf, "(EXPR"); + break; + case MULTIEXPR_SUBLINK: + appendStringInfoString(buf, "(MULTIEXPR"); + break; + case ARRAY_SUBLINK: + appendStringInfoString(buf, "(ARRAY"); + break; + case CTE_SUBLINK: + /* This case is probably unreachable */ + appendStringInfoString(buf, "(CTE"); + break; + } + get_rule_expr(subplan->testexpr, context, showimplicit); if (subplan->useHashTable) - appendStringInfo(buf, "(hashed %s)", subplan->plan_name); + appendStringInfo(buf, " FROM hashed %s)", subplan->plan_name); else - appendStringInfo(buf, "(%s)", subplan->plan_name); + appendStringInfo(buf, " FROM %s)", subplan->plan_name); } break; =

view thread (3+ messages)  latest in thread

Message-ID: <2289721.1705600540@sss.pgh.pa.us>
Permalink:  ../2289721.1705600540@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2289721.1705600540@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, chantal.keller@universite-paris-saclay.fr
  Subject: Re: Explain and filter over subplans
  In-Reply-To: <2289721.1705600540@sss.pgh.pa.us>
  References: <149c5c2f-4267-44e3-a177-d1fd24c53f6d@universite-paris-saclay.fr> <2289721.1705600540@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox