Skip to content

Commit b154696

Browse files
authored
[BABEL] Add hook to enable index matching through type casts (babelfish-for-postgresql#762)
Adding a hook in match_opclause_to_indexcol() that allows babelfish to provide index clauses when the built-in logic cannot match an OpExpr to an index column. This enables extensions to handle type-cast patterns that prevent index usage due to operator family mismatches. Extension PR: babelfish-for-postgresql/babelfish_extensions#4829 Issues Resolved Task: BABEL-6814 Authored-by: Rucha Kulkarni ruchask@amazon.com
1 parent cd314d6 commit b154696

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/backend/optimizer/path/indxpath.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "utils/lsyscache.h"
3838
#include "utils/selfuncs.h"
3939

40+
/* Hook for extensions to provide index clauses for unmatched OpExpr */
41+
match_opclause_to_indexcol_hook_type match_opclause_to_indexcol_hook = NULL;
4042

4143
/* XXX see PartCollMatchesExprColl */
4244
#define IndexCollMatchesExprColl(idxcollation, exprcollation) \
@@ -2963,12 +2965,17 @@ match_opclause_to_indexcol(PlannerInfo *root,
29632965
* function for the operator's underlying function.
29642966
*/
29652967
set_opfuncid(clause); /* make sure we have opfuncid */
2966-
return get_index_clause_from_support(root,
2968+
iclause = get_index_clause_from_support(root,
29672969
rinfo,
29682970
clause->opfuncid,
29692971
0, /* indexarg on left */
29702972
indexcol,
29712973
index);
2974+
if (iclause)
2975+
return iclause;
2976+
if (match_opclause_to_indexcol_hook)
2977+
return match_opclause_to_indexcol_hook(root, rinfo, indexcol, index);
2978+
return NULL;
29722979
}
29732980

29742981
if (match_index_to_operand(rightop, indexcol, index) &&
@@ -3003,12 +3010,17 @@ match_opclause_to_indexcol(PlannerInfo *root,
30033010
* function for the operator's underlying function.
30043011
*/
30053012
set_opfuncid(clause); /* make sure we have opfuncid */
3006-
return get_index_clause_from_support(root,
3013+
iclause = get_index_clause_from_support(root,
30073014
rinfo,
30083015
clause->opfuncid,
30093016
1, /* indexarg on right */
30103017
indexcol,
30113018
index);
3019+
if (iclause)
3020+
return iclause;
3021+
if (match_opclause_to_indexcol_hook)
3022+
return match_opclause_to_indexcol_hook(root, rinfo, indexcol, index);
3023+
return NULL;
30123024
}
30133025

30143026
return NULL;

src/include/optimizer/paths.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ typedef RelOptInfo *(*join_search_hook_type) (PlannerInfo *root,
4848
List *initial_rels);
4949
extern PGDLLIMPORT join_search_hook_type join_search_hook;
5050

51+
/* Hook for plugins to provide index clauses for unmatched OpExpr */
52+
typedef IndexClause *(*match_opclause_to_indexcol_hook_type) (PlannerInfo *root,
53+
RestrictInfo *rinfo,
54+
int indexcol,
55+
IndexOptInfo *index);
56+
extern PGDLLIMPORT match_opclause_to_indexcol_hook_type match_opclause_to_indexcol_hook;
57+
5158

5259
extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist);
5360
extern RelOptInfo *standard_join_search(PlannerInfo *root, int levels_needed,

0 commit comments

Comments
 (0)