| From: | Mohamed ALi <moali(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] Add NESTED_STATEMENTS option to EXPLAIN |
| Date: | 2026-05-16 14:52:48 |
| Message-ID: | CAGnOmWofX8ru+AnOTkeLjLF6eMjFUsQLYzV_sf1D70FqNHAApQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Zsolt,
Thanks for testing! I've identified the root causes and am working on
v2 with the fixes. Will share soon.
-- Mohamed Ali
On Sat, May 16, 2026 at 4:15 AM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
>
> Hello!
>
> With some initial testing I was able to find 2 server crashes with the patch.
>
> 1: error during explain
>
> CREATE OR REPLACE FUNCTION divz_plpgsql(x int) RETURNS int LANGUAGE
> plpgsql AS $$
> DECLARE r int;
> BEGIN
> SELECT 1/x INTO r;
> RETURN r;
> END;
> $$;
> -- error during explain
> EXPLAIN (ANALYZE, NESTED_STATEMENTS) SELECT divz_plpgsql(0);
> -- run another explain
> EXPLAIN (ANALYZE, NESTED_STATEMENTS) SELECT 1;
> -- any next query crashes the server
> SELECT 1;
>
> 2: any nested explain
>
> CREATE FUNCTION f() RETURNS void LANGUAGE plpgsql AS $$
> DECLARE r record;
> BEGIN
> FOR r IN EXECUTE 'EXPLAIN (ANALYZE, NESTED_STATEMENTS) SELECT 1'
> LOOP NULL; END LOOP;
> END;
> $$;
>
> EXPLAIN (ANALYZE, NESTED_STATEMENTS) SELECT f();
>
>
> + /*
> + * Switch to TopMemoryContext so the captured plan text survives
> + * until we print it.
> + */
> + oldcxt = MemoryContextSwitchTo(TopMemoryContext);
> ...
> + ExplainBeginOutput(nes);
> + ExplainPrintPlan(nes, queryDesc);
> + ExplainEndOutput(nes);
> ...
> + plan_info->query_text = queryDesc->sourceText ?
> + pstrdup(queryDesc->sourceText) : pstrdup("<unknown>");
>
> When is queryDesc freed? This seems like a memory leak.
>
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Srinath Reddy Sadipiralla | 2026-05-16 15:21:54 | Re: pg_recvlogical: honor source cluster file permissions for output files |
| Previous Message | Daniel Gustafsson | 2026-05-16 14:36:33 | Re: Simplify signature of ProcessStartupPacket() |