Skip to content

Commit 704f32d

Browse files
amitlanCommitfest Bot
authored andcommitted
Avoid using SPI in RI trigger functions
Currently, ri_PlanCheck() uses SPI_prepare() to create an SPI plan containing a CachedPlanSource for the SQL query used in RI checks. Similarly, ri_PerformCheck() calls SPI_execute_snapshot() to execute the query with a specific snapshot. This commit introduces ri_PlanCreate() and ri_PlanExecute() to replace SPI_prepare() and SPI_execute_snapshot(), respectively. * ri_PlanCreate() Creates an "RI plan" for a query using a caller-specified callback function, such as ri_SqlStringPlanCreate(), which produces a CachedPlanSource for the input SQL string. This mirrors SPI_prepare() functionality. * ri_PlanExecute() Executes an "RI plan" using a callback saved within the "RI plan" (struct RIPlan). For example, ri_SqlStringPlanExecute() fetches a CachedPlan from the CachedPlanSource and executes its PlannedStmt using the executor. Snapshot handling is now fully managed by ri_PerformCheck(), eliminating dependence on SPI's snapshot logic. These changes make ri_PlanCreate() and ri_PlanExecute() pluggable, laying the groundwork for future commits to replace SQL-based RI checks with optimized C functions for direct table/index scans. Note: This only addresses RI_* functions addressed from RI triggers and not those called from tablecmds.c, such as RI_Initial_Check() and RI_PartitionRemove_Check(), which still use SPI_prepare() and SPI_execute_snapshot(). Reviewed-by: Robert Haas Discussion: https://postgr.es/m/CA+HiwqGkfJfYdeq5vHPh6eqPKjSbfpDDY+j-kXYFePQedtSLeg@mail.gmail.com Discussion: https://postgr.es/m/CA+HiwqG5e8pk8s7+7zhr1Nc_PGyhEdM5f=pHkMOdK1RYWXfJsg@mail.gmail.com
1 parent 7c8bd58 commit 704f32d

File tree

2 files changed

+488
-109
lines changed

2 files changed

+488
-109
lines changed

src/backend/executor/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params,
765765
* end of the command.
766766
*
767767
* This is currently not documented in spi.sgml because it is only intended
768-
* for use by RI triggers.
768+
* for use by some functions in ri_triggers.c.
769769
*
770770
* Passing snapshot == InvalidSnapshot will select the normal behavior of
771771
* fetching a new snapshot for each query.

0 commit comments

Comments
 (0)