From 7113a4d0b45a4cf00b78076d55570ade60ff9841 Mon Sep 17 00:00:00 2001 From: "Andrei V. Lepikhov" Date: Wed, 5 Mar 2025 09:38:30 +0100 Subject: [PATCH] Introduce selectivity hook. --- src/backend/optimizer/path/clausesel.c | 5 +++++ src/backend/utils/adt/selfuncs.c | 1 + src/include/utils/selfuncs.h | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c index 5d51f97f219..6b5d49d0786 100644 --- a/src/backend/optimizer/path/clausesel.c +++ b/src/backend/optimizer/path/clausesel.c @@ -128,6 +128,11 @@ clauselist_selectivity_ext(PlannerInfo *root, ListCell *l; int listidx; + if (clauselist_selectivity_hook) + return clauselist_selectivity_hook(root, clauses, varRelid, jointype, + sjinfo, &estimatedclauses, + use_extended_stats); + /* * If there's exactly one clause, just go directly to * clause_selectivity_ext(). None of what we might do below is relevant. diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index c2918c9c831..e66346ef6b4 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -147,6 +147,7 @@ /* Hooks for plugins to get control when we ask for stats */ get_relation_stats_hook_type get_relation_stats_hook = NULL; get_index_stats_hook_type get_index_stats_hook = NULL; +clauselist_selectivity_hook_type clauselist_selectivity_hook = NULL; static double eqsel_internal(PG_FUNCTION_ARGS, bool negate); static double eqjoinsel_inner(Oid opfuncoid, Oid collation, diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h index d35939651f3..ce4ba27d183 100644 --- a/src/include/utils/selfuncs.h +++ b/src/include/utils/selfuncs.h @@ -149,6 +149,17 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root, VariableStatData *vardata); extern PGDLLIMPORT get_index_stats_hook_type get_index_stats_hook; +/* Hooks for plugins to get control when we ask for selectivity estimation */ +typedef Selectivity (*clauselist_selectivity_hook_type) ( + PlannerInfo *root, + List *clauses, + int varRelid, + JoinType jointype, + SpecialJoinInfo *sjinfo, + Bitmapset **estimatedclauses, + bool use_extended_stats); +extern PGDLLIMPORT clauselist_selectivity_hook_type clauselist_selectivity_hook; + /* Functions in selfuncs.c */ extern void examine_variable(PlannerInfo *root, Node *node, int varRelid, -- 2.48.1