pg_py_plan_forwarding
Forward PostgreSQL planner and executor data to embedded Python callbacks
pg_py_plan_forwarding · Forward PostgreSQL planner and executor data to embedded Python callbacks
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101082 | pg_py_plan_forwarding | pg_py_plan_forwarding | 0.1 | FEAT | BSD-3-Clause | C |
Usage
Sources:
- pg_py_plan_forwarding README at the reviewed commit
- pg_py_plan_forwarding.control at the reviewed commit
- Empty version 0.1 install SQL
- Planner and executor hook implementation
- Example Python callbacks
- Build configuration
pg_py_plan_forwarding is optimizer-learning code that installs planner, executor_start, and executor_end hooks backed by embedded Python. It serializes PostgreSQL internal nodes with nodeToString, passes the strings to Python, and reconstructs the returned plan with stringToNode.
The version 0.1 install SQL is empty, so creating the extension only records it. In a disposable backend built for the source’s exact Python and PostgreSQL versions, the library can be activated explicitly for a planner-only experiment:
The example Python callback logs the parse tree and plan and returns the plan unchanged.
Caveats
- The build hard-codes Python 3.9 headers, while initialization hard-codes
/home/vagrant/pg_py_plan_forwardingas the module path. It is not a portable Python environment integration. - A Python callback can return malformed or version-incompatible PostgreSQL internal-node text. Reconstructing that as a plan can crash a backend or corrupt execution semantics.
- The reviewed executor-hook fallback does not call the standard executor when no earlier hook exists, and its Python reference management contains unsafe paths. Do not run ordinary statements after activation without repairing and auditing the C code.
- This is not a stable SQL API or a production plan-management feature. PostgreSQL internal plan representations and hook signatures change between releases.