diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index e24e718..609182e 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -45,6 +45,7 @@ int			constraint_exclusion = CONSTRAINT_EXCLUSION_PARTITION;
 /* Hook for plugins to get control in get_relation_info() */
 get_relation_info_hook_type get_relation_info_hook = NULL;
 
+is_fictitious_index_hook_type is_fictitious_index_hook = NULL;
 
 static List *get_relation_constraints(PlannerInfo *root,
 						 Oid relationObjectId, RelOptInfo *rel,
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index c837fb6..57ee37c 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4561,7 +4561,7 @@ get_actual_variable_range(PlannerInfo *root, VariableStatData *vardata,
 		 * The index list might include fictitious indexes inserted by a
 		 * get_relation_info hook --- don't try to access them.
 		 */
-		if (!OidIsValid(index->indexoid))
+		if (is_fictitious_index_hook && (*is_fictitious_index_hook) (index->indexoid))
 			continue;
 
 		/*
diff --git a/src/include/optimizer/plancat.h b/src/include/optimizer/plancat.h
index 9316c9e..050cce0 100644
--- a/src/include/optimizer/plancat.h
+++ b/src/include/optimizer/plancat.h
@@ -24,6 +24,9 @@ typedef void (*get_relation_info_hook_type) (PlannerInfo *root,
 														 RelOptInfo *rel);
 extern PGDLLIMPORT get_relation_info_hook_type get_relation_info_hook;
 
+typedef bool (*is_fictitious_index_hook_type) (Oid index_oid);
+
+extern PGDLLIMPORT is_fictitious_index_hook_type is_fictitious_index_hook;
 
 extern void get_relation_info(PlannerInfo *root, Oid relationObjectId,
 				  bool inhparent, RelOptInfo *rel);
