diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c
index 06f836308d0..fd151c21815 100644
--- a/src/backend/optimizer/path/clausesel.c
+++ b/src/backend/optimizer/path/clausesel.c
@@ -526,6 +526,7 @@ find_single_rel_for_clauses(PlannerInfo *root, List *clauses)
 {
 	int			lastrelid = 0;
 	ListCell   *l;
+	Bitmapset  *clause_relids;
 
 	foreach(l, clauses)
 	{
@@ -560,12 +561,15 @@ find_single_rel_for_clauses(PlannerInfo *root, List *clauses)
 			continue;
 		}
 
-		if (!IsA(rinfo, RestrictInfo))
-			return NULL;
+		if (IsA(rinfo, RestrictInfo))
+			clause_relids = rinfo->clause_relids;
+		else
+			clause_relids = pull_varnos(root, (Node *) rinfo);
+
 
-		if (bms_is_empty(rinfo->clause_relids))
+		if (bms_is_empty(clause_relids))
 			continue;			/* we can ignore variable-free clauses */
-		if (!bms_get_singleton_member(rinfo->clause_relids, &relid))
+		if (!bms_get_singleton_member(clause_relids, &relid))
 			return NULL;		/* multiple relations in this clause */
 		if (lastrelid == 0)
 			lastrelid = relid;	/* first clause referencing a relation */
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index ca48395d5c5..90809fbcd8e 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -1560,8 +1560,6 @@ statext_is_compatible_clause(PlannerInfo *root, Node *clause, Index relid,
 							 Bitmapset **attnums, List **exprs)
 {
 	RangeTblEntry *rte = root->simple_rte_array[relid];
-	RestrictInfo *rinfo = (RestrictInfo *) clause;
-	int			clause_relid;
 	Oid			userid;
 
 	/*
@@ -1588,21 +1586,41 @@ statext_is_compatible_clause(PlannerInfo *root, Node *clause, Index relid,
 		return true;
 	}
 
-	/* Otherwise it must be a RestrictInfo. */
-	if (!IsA(rinfo, RestrictInfo))
-		return false;
+	/* */
+	if (IsA(clause, RestrictInfo))
+	{
+		RestrictInfo *rinfo = (RestrictInfo *) clause;
+		int			clause_relid;
 
-	/* Pseudoconstants are not really interesting here. */
-	if (rinfo->pseudoconstant)
-		return false;
+		/* Pseudoconstants are not really interesting here. */
+		if (rinfo->pseudoconstant)
+			return false;
 
-	/* Clauses referencing other varnos are incompatible. */
-	if (!bms_get_singleton_member(rinfo->clause_relids, &clause_relid) ||
-		clause_relid != relid)
-		return false;
+		/* Clauses referencing other varnos are incompatible. */
+		if (!bms_get_singleton_member(rinfo->clause_relids, &clause_relid) ||
+			clause_relid != relid)
+			return false;
+
+		clause = (Node *) rinfo->clause;
+	}
+	else
+	{
+		int			clause_relid;
+		Bitmapset  *relids = pull_varnos(root, clause);
+
+		/* Pseudoconstants are not really interesting here. */
+		if (bms_is_empty(relids) &&
+			!contain_volatile_functions(clause))
+			return false;
+
+		/* Clauses referencing other varnos are incompatible. */
+		if (!bms_get_singleton_member(relids, &clause_relid) ||
+			clause_relid != relid)
+			return false;
+	}
 
 	/* Check the clause and determine what attributes it references. */
-	if (!statext_is_compatible_clause_internal(root, (Node *) rinfo->clause,
+	if (!statext_is_compatible_clause_internal(root, clause,
 											   relid, attnums, exprs))
 		return false;
 
