Clarify planner_hook calling convention
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t45320psql -h localhost -U postgresBuilt from patchset v1 (message #1), September 20, 2026 at 11:37 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t45320_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t45320_1 && git checkout t45320_1Patchset v1 (message #1) is on t45320_1
Hi,
planner hook is frequently used in monitoring and advising extensions.
The call to this hook is implemented in the way, that the
standard_planner routine must be called at least once in the hook's call
chain.
But, as I see in [1]/messages/by-id/27516.1180053940@sss.pgh.pa.us, it should allow us "... replace the planner
altogether".
In such situation it haven't sense to call standard_planner at all.
Moreover, if an extension make some expensive planning activity,
monitoring tools, like pg_stat_statements, can produce different
results, depending on a hook calling order.
I thought about additional hooks, explicit hook priorities and so on.
But, maybe more simple solution is to describe requirements to such kind
of extensions in the code and documentation (See patch in attachment)?
It would allow an extension developer legally check and log a situation,
when the extension doesn't last in the call chain.
[1]: /messages/by-id/27516.1180053940@sss.pgh.pa.us
/messages/by-id/27516.1180053940@sss.pgh.pa.us
--
regards,
Andrey Lepikhov
Postgres Professional
"Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru> writes:
planner hook is frequently used in monitoring and advising extensions.
Yeah.
The call to this hook is implemented in the way, that the
standard_planner routine must be called at least once in the hook's call
chain.
But, as I see in [1], it should allow us "... replace the planner
altogether".
In such situation it haven't sense to call standard_planner at all.
That's possible in theory, but who's going to do it in practice?
There is a monstrous amount of code you'd have to replace.
Moreover, if you felt compelled to do it, it's likely because you
are making fundamental changes elsewhere too, which means you are
more likely going to end up with a fork not an extension.
But, maybe more simple solution is to describe requirements to such kind of extensions in the code and documentation (See patch in attachment)? + * 2. If your extension implements some planning activity, write in the extension + * docs a requirement to set the extension at the begining of shared libraries list.
This advice seems pretty unhelpful. If more than one extension is
getting into the planner_hook, they can't all be first.
(Also, largely the same issue applies to very many of our other
hooks.)
regards, tom lane
On 1/3/22 8:59 PM, Tom Lane wrote:
"Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru> writes:
planner hook is frequently used in monitoring and advising extensions.
Yeah.
The call to this hook is implemented in the way, that the
standard_planner routine must be called at least once in the hook's call
chain.
But, as I see in [1], it should allow us "... replace the planner
altogether".
In such situation it haven't sense to call standard_planner at all.That's possible in theory, but who's going to do it in practice?
We use it in an extension that freezes a plan for specific parameterized
query (using plancache + shared storage) - exactly the same technique as
extended query protocol does, but spreading across all backends.
As I know, the community doesn't like such features, and we use it in
enterprise code only.
But, maybe more simple solution is to describe requirements to such kind of extensions in the code and documentation (See patch in attachment)? + * 2. If your extension implements some planning activity, write in the extension + * docs a requirement to set the extension at the begining of shared libraries list.This advice seems pretty unhelpful. If more than one extension is
getting into the planner_hook, they can't all be first.
I want to check planner_hook on startup and log an error if it isn't
NULL and give a user an advice how to fix it. I want to legalize this
logic, if permissible.
(Also, largely the same issue applies to very many of our other
hooks.)
Agreed. Interference between extensions is a very annoying issue now.
--
regards,
Andrey Lepikhov
Postgres Professional