+ quote_value(&buf, indexname);
+ }
+
+ break;
+ }
+ }
+
+ /*
+ * to make the index a candidate when definition of this index is
+ * matched with the index's definition of current_hint.
+ */
+ if (OidIsValid(relationObjectId) && !use_index)
+ {
+ foreach(l, current_hint->parent_index_infos)
+ {
+ int i;
+ HeapTuple ht_idx;
+ ParentIndexInfo *p_info = (ParentIndexInfo *)lfirst(l);
+
+ /* check to match the parameter of unique */
+ if (p_info->indisunique != info->unique)
+ continue;
+
+ /* check to match the parameter of index's method */
+ if (p_info->method != info->relam)
+ continue;
+
+ /* to check to match the indexkey's configuration */
+ if ((list_length(p_info->column_names)) !=
+ info->ncolumns)
+ continue;
+
+ /* check to match the indexkey's configuration */
+ for (i = 0; i < info->ncolumns; i++)
+ {
+ char *c_attname = NULL;
+ char *p_attname = NULL;
+
+ p_attname =
+ list_nth(p_info->column_names, i);
+
+ /* both are expressions */
+ if (info->indexkeys[i] == 0 && !p_attname)
+ continue;
+
+ /* one's column is expression, the other is not */
+ if (info->indexkeys[i] == 0 || !p_attname)
+ break;
+
+ c_attname = get_attname(relationObjectId,
+ info->indexkeys[i]);
+
+ if (strcmp(p_attname, c_attname) != 0)
+ break;
+
+ if (p_info->indcollation[i] != info->indexcollations[i])
+ break;
+
+ if (p_info->opclass[i] != info->opcintype[i])
+ break;
+
+ if (((p_info->indoption[i] & INDOPTION_DESC) != 0) !=
+ info->reverse_sort[i])
+ break;
+
+ if (((p_info->indoption[i] & INDOPTION_NULLS_FIRST) != 0) !=
+ info->nulls_first[i])
+ break;
+
+ }
+
+ if (i != info->ncolumns)
+ continue;
+
+ if ((p_info->expression_str && (info->indexprs != NIL)) ||
+ (p_info->indpred_str && (info->indpred != NIL)))
+ {
+ /*
+ * Fetch the pg_index tuple by the Oid of the index
+ */
+ ht_idx = SearchSysCache1(INDEXRELID,
+ ObjectIdGetDatum(info->indexoid));
+
+ /* check to match the expression's parameter of index */
+ if (p_info->expression_str &&
+ !heap_attisnull(ht_idx, Anum_pg_index_indexprs))
+ {
+ Datum exprsDatum;
+ bool isnull;
+ Datum result;
+
+ /*
+ * to change the expression's parameter of child's
+ * index to strings
+ */
+ exprsDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
+ Anum_pg_index_indexprs,
+ &isnull);
+
+ result = DirectFunctionCall2(pg_get_expr,
+ exprsDatum,
+ ObjectIdGetDatum(
+ relationObjectId));
+
+ if (strcmp(p_info->expression_str,
+ text_to_cstring(DatumGetTextP(result))) != 0)
+ {
+ /* Clean up */
+ ReleaseSysCache(ht_idx);
+
+ continue;
+ }
+ }
+
+ /* Check to match the predicate's parameter of index */
+ if (p_info->indpred_str &&
+ !heap_attisnull(ht_idx, Anum_pg_index_indpred))
+ {
+ Datum predDatum;
+ bool isnull;
+ Datum result;
+
+ /*
+ * to change the predicate's parameter of child's
+ * index to strings
+ */
+ predDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
+ Anum_pg_index_indpred,
+ &isnull);
+
+ result = DirectFunctionCall2(pg_get_expr,
+ predDatum,
+ ObjectIdGetDatum(
+ relationObjectId));
+
+ if (strcmp(p_info->indpred_str,
+ text_to_cstring(DatumGetTextP(result))) != 0)
+ {
+ /* Clean up */
+ ReleaseSysCache(ht_idx);
+
+ continue;
+ }
+ }
+
+ /* Clean up */
+ ReleaseSysCache(ht_idx);
+ }
+ else if (p_info->expression_str || (info->indexprs != NIL))
+ continue;
+ else if (p_info->indpred_str || (info->indpred != NIL))
+ continue;
+
+ use_index = true;
+
+ /* to log the candidate of index */
+ if (pg_hint_plan_debug_print)
+ {
+ appendStringInfoCharMacro(&buf, ' ');
+ quote_value(&buf, indexname);