Skip to content

Commit 23e1a01

Browse files
authored
[BABEL] Add hook to enable index matching through type casts (#774)
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#4868 Task: BABEL-6814 Authored-by: Rucha Kulkarni ruchask@amazon.com
1 parent 372667e commit 23e1a01

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
@@ -35,6 +35,8 @@
3535
#include "utils/lsyscache.h"
3636
#include "utils/selfuncs.h"
3737

38+
/* Hook for extensions to provide index clauses for unmatched OpExpr */
39+
match_opclause_to_indexcol_hook_type match_opclause_to_indexcol_hook = NULL;
3840

3941
/* XXX see PartCollMatchesExprColl */
4042
#define IndexCollMatchesExprColl(idxcollation, exprcollation) \
@@ -2451,12 +2453,17 @@ match_opclause_to_indexcol(PlannerInfo *root,
24512453
* function for the operator's underlying function.
24522454
*/
24532455
set_opfuncid(clause); /* make sure we have opfuncid */
2454-
return get_index_clause_from_support(root,
2456+
iclause = get_index_clause_from_support(root,
24552457
rinfo,
24562458
clause->opfuncid,
24572459
0, /* indexarg on left */
24582460
indexcol,
24592461
index);
2462+
if (iclause)
2463+
return iclause;
2464+
if (match_opclause_to_indexcol_hook)
2465+
return match_opclause_to_indexcol_hook(root, rinfo, indexcol, index);
2466+
return NULL;
24602467
}
24612468

24622469
if (match_index_to_operand(rightop, indexcol, index) &&
@@ -2491,12 +2498,17 @@ match_opclause_to_indexcol(PlannerInfo *root,
24912498
* function for the operator's underlying function.
24922499
*/
24932500
set_opfuncid(clause); /* make sure we have opfuncid */
2494-
return get_index_clause_from_support(root,
2501+
iclause = get_index_clause_from_support(root,
24952502
rinfo,
24962503
clause->opfuncid,
24972504
1, /* indexarg on right */
24982505
indexcol,
24992506
index);
2507+
if (iclause)
2508+
return iclause;
2509+
if (match_opclause_to_indexcol_hook)
2510+
return match_opclause_to_indexcol_hook(root, rinfo, indexcol, index);
2511+
return NULL;
25002512
}
25012513

25022514
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)