Re: [PATCH] Optionally record Plan IDs to track plan changes for a query
Lukas Fittl <lukas@fittl.com>
From: Lukas Fittl <lukas@fittl.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Андрей Казачков <andrey.kazachkov@tantorlabs.ru>, Sami Imseih <samimseih@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Marko M <marko@pganalyze.com>
Date: 2026-03-19T07:15:07Z
Lists: pgsql-hackers
On Thu, Dec 25, 2025 at 3:02 PM Michael Paquier <michael@paquier.xyz> wrote:
> + /*
> + * COMPUTE_PLAN_ID_REGRESS means COMPUTE_PLAN_ID_YES, but we don't show
> + * the queryid in any of the EXPLAIN plans to keep stable the results
> + * generated by regression test suites.
> + */
> + if (es->verbose && queryDesc->plannedstmt->planId != UINT64CONST(0) &&
> + compute_plan_id != COMPUTE_PLAN_ID_REGRESS)
> + {
> + /*
> + * Output the queryid as an int64 rather than a uint64 so we match
> + * what would be seen in the BIGINT pg_stat_activity.plan_id column.
> + */
> + ExplainPropertyInteger("Plan Identifier", NULL,
> + queryDesc->plannedstmt->planId, es);
> + }
>
> Now, looking at this block of code, I am wondering if you don't have a
> point here even without compute_plan_id.. Could there be merit in
> showing this information for an EXPLAIN if this field is not zero?
> With EXPLAIN being pluggable in a hook, I doubt that it matters much,
> but I am wondering if providing this information could make the work
> of some extensions easier.
I missed this at the time, but happened to run across this by coincidence.
Consider this a late +1 on the idea, i.e. I do think that emitting the
plan ID as "plan identifier" in EXPLAIN seems reasonable when a plugin
sets it - the cost is negligible, and it'd make it easier to work with
extensions like pg_stat_plans.
Thanks,
Lukas
--
Lukas Fittl
Commits
-
doc: Update header file mention for CompareType
- b39013b7b1b1 19 (unreleased) cited
-
Allow plugins to set a 64-bit plan identifier in PlannedStmt
- 2a0cd38da5cc 18.0 landed
-
Fix indentation of comment in plannodes.h
- c9238ad85325 18.0 landed
-
Reformat node comments in plannodes.h
- 3d17d7d7fb7a 18.0 landed
-
injection_points: Add routine able to drop all stats
- a632cd354d35 18.0 landed
-
Add pgstat_drop_matching_entries() to pgstats
- ce5c620fb625 18.0 landed
-
Move pg_stat_statements query jumbling to core.
- 5fd9dfa5f50e 14.0 cited