From c15e060a4744f2284f9fc1a9ef9d4d339d21f57e Mon Sep 17 00:00:00 2001 From: Rucha Kulkarni Date: Wed, 20 May 2026 13:49:20 +0000 Subject: [PATCH 1/2] Adding hook to enable index matching through type casts Signed-off-by: Rucha Kulkarni --- src/backend/optimizer/path/indxpath.c | 9 ++++++++- src/include/optimizer/paths.h | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 4fe8e5164c7..c262b62d010 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -36,6 +36,8 @@ #include "utils/lsyscache.h" #include "utils/selfuncs.h" +/* Hook for extensions to provide index clauses for unmatched OpExpr */ +match_opclause_to_indexcol_hook_type match_opclause_to_indexcol_hook = NULL; /* XXX see PartCollMatchesExprColl */ #define IndexCollMatchesExprColl(idxcollation, exprcollation) \ @@ -2964,12 +2966,17 @@ match_opclause_to_indexcol(PlannerInfo *root, * function for the operator's underlying function. */ set_opfuncid(clause); /* make sure we have opfuncid */ - return get_index_clause_from_support(root, + iclause = get_index_clause_from_support(root, rinfo, clause->opfuncid, 0, /* indexarg on left */ indexcol, index); + if (iclause) + return iclause; + if (match_opclause_to_indexcol_hook) + return match_opclause_to_indexcol_hook(root, rinfo, indexcol, index); + return NULL; } if (match_index_to_operand(rightop, indexcol, index) && diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h index 70380276c84..944e9fde662 100644 --- a/src/include/optimizer/paths.h +++ b/src/include/optimizer/paths.h @@ -48,6 +48,13 @@ typedef RelOptInfo *(*join_search_hook_type) (PlannerInfo *root, List *initial_rels); extern PGDLLIMPORT join_search_hook_type join_search_hook; +/* Hook for plugins to provide index clauses for unmatched OpExpr */ +typedef IndexClause *(*match_opclause_to_indexcol_hook_type) (PlannerInfo *root, + RestrictInfo *rinfo, + int indexcol, + IndexOptInfo *index); +extern PGDLLIMPORT match_opclause_to_indexcol_hook_type match_opclause_to_indexcol_hook; + extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist); extern RelOptInfo *standard_join_search(PlannerInfo *root, int levels_needed, From bd900b901feb4ff9489c059314dab147c8898ec4 Mon Sep 17 00:00:00 2001 From: Rucha Kulkarni Date: Sat, 23 May 2026 09:38:33 +0000 Subject: [PATCH 2/2] Adding hook check for right operand also Signed-off-by: Rucha Kulkarni --- src/backend/optimizer/path/indxpath.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index c262b62d010..92bdd87035f 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -3011,12 +3011,17 @@ match_opclause_to_indexcol(PlannerInfo *root, * function for the operator's underlying function. */ set_opfuncid(clause); /* make sure we have opfuncid */ - return get_index_clause_from_support(root, + iclause = get_index_clause_from_support(root, rinfo, clause->opfuncid, 1, /* indexarg on right */ indexcol, index); + if (iclause) + return iclause; + if (match_opclause_to_indexcol_hook) + return match_opclause_to_indexcol_hook(root, rinfo, indexcol, index); + return NULL; } return NULL;