1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-19 15:49:24 +03:00

Add planner_setup_hook and planner_shutdown_hook.

These hooks allow plugins to get control at the earliest point at
which the PlannerGlobal object is fully initialized, and then just
before it gets destroyed. This is useful in combination with the
extendable plan state facilities (see extendplan.h) and perhaps for
other purposes as well.

Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: http://postgr.es/m/CA+TgmoYWKHU2hKr62Toyzh-kTDEnMDeLw7gkOOnjL-TnOUq0kQ@mail.gmail.com
This commit is contained in:
Robert Haas
2025-10-08 09:05:38 -04:00
parent c83ac02ec7
commit 94f3ad3961
2 changed files with 27 additions and 0 deletions

View File

@@ -73,6 +73,12 @@ bool enable_distinct_reordering = true;
/* Hook for plugins to get control in planner() */
planner_hook_type planner_hook = NULL;
/* Hook for plugins to get control after PlannerGlobal is initialized */
planner_setup_hook_type planner_setup_hook = NULL;
/* Hook for plugins to get control before PlannerGlobal is discarded */
planner_shutdown_hook_type planner_shutdown_hook = NULL;
/* Hook for plugins to get control when grouping_planner() plans upper rels */
create_upper_paths_hook_type create_upper_paths_hook = NULL;
@@ -456,6 +462,10 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
tuple_fraction = 0.0;
}
/* Allow plugins to take control after we've initialized "glob" */
if (planner_setup_hook)
(*planner_setup_hook) (glob, parse, query_string, &tuple_fraction, es);
/* primary planning entry point (may recurse for subqueries) */
root = subquery_planner(glob, parse, NULL, NULL, false, tuple_fraction,
NULL);
@@ -635,6 +645,10 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
result->jitFlags |= PGJIT_DEFORM;
}
/* Allow plugins to take control before we discard "glob" */
if (planner_shutdown_hook)
(*planner_shutdown_hook) (glob, parse, query_string, result);
if (glob->partition_directory != NULL)
DestroyPartitionDirectory(glob->partition_directory);

View File

@@ -32,6 +32,19 @@ typedef PlannedStmt *(*planner_hook_type) (Query *parse,
ExplainState *es);
extern PGDLLIMPORT planner_hook_type planner_hook;
/* Hook for plugins to get control after PlannerGlobal is initialized */
typedef void (*planner_setup_hook_type) (PlannerGlobal *glob, Query *parse,
const char *query_string,
double *tuple_fraction,
ExplainState *es);
extern PGDLLIMPORT planner_setup_hook_type planner_setup_hook;
/* Hook for plugins to get control before PlannerGlobal is discarded */
typedef void (*planner_shutdown_hook_type) (PlannerGlobal *glob, Query *parse,
const char *query_string,
PlannedStmt *pstmt);
extern PGDLLIMPORT planner_shutdown_hook_type planner_shutdown_hook;
/* Hook for plugins to get control when grouping_planner() plans upper rels */
typedef void (*create_upper_paths_hook_type) (PlannerInfo *root,
UpperRelationKind stage,