pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Katsuya Okizaki <miotsukushi0800@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: How do a user-defined function that returns a table executes a query?
Date: Wed, 08 Feb 2023 11:18:00 +0100
Message-ID: <dc3596ca4e75b29f8ee74a4fa218c2ad4c6ced2e.camel@cybertec.at> (raw)
In-Reply-To: <CAAe6QrDV884w99u1z8r6ybyi55iir4+Z-YU+ZBNHT6rKi+oBTg@mail.gmail.com>
References: <CAAe6QrDV884w99u1z8r6ybyi55iir4+Z-YU+ZBNHT6rKi+oBTg@mail.gmail.com>

On Wed, 2023-02-08 at 08:49 +0900, Katsuya Okizaki wrote:
> In a normal SQL, we can use the EXPLAIN command to view the execution plan.
> However, in this case, I am not sure how a user-defined function work.
> 
> If anyone has faced a similar situation and found a way to view the execution plan,
> I would greatly appreciate your insights and suggestions.

I am not sure which of the following you want:

1. Get the execution plan of SQL statements run inside a function:

   For that, you would use "auto_explain" with "auto_explain.log_nested_statements = on".

2. Get a trace of the execution of the function code itself:

   For PL/pgSQL, there is "pldebugger" (https://github.com/EnterpriseDB/pldebugger),
   which can be used together with pgAdmin.

   I usually sprinkle the code with RAISE NOTICE statements.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com





view thread (5+ messages)  latest in thread

Message-ID: <dc3596ca4e75b29f8ee74a4fa218c2ad4c6ced2e.camel@cybertec.at>
Permalink:  ../dc3596ca4e75b29f8ee74a4fa218c2ad4c6ced2e.camel@cybertec.at/
Also on:    postgresql.org/message-id/dc3596ca4e75b29f8ee74a4fa218c2ad4c6ced2e.camel@cybertec.at

 · 

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: laurenz.albe@cybertec.at, miotsukushi0800@gmail.com
  Subject: Re: How do a user-defined function that returns a table executes a query?
  In-Reply-To: <dc3596ca4e75b29f8ee74a4fa218c2ad4c6ced2e.camel@cybertec.at>
  References: <CAAe6QrDV884w99u1z8r6ybyi55iir4+Z-YU+ZBNHT6rKi+oBTg@mail.gmail.com> <dc3596ca4e75b29f8ee74a4fa218c2ad4c6ced2e.camel@cybertec.at>

* 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