diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index ed07e2f..727d115 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -4520,13 +4520,13 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
 	RangeTblEntry *rte PG_USED_FOR_ASSERTS_ONLY;
 	ListCell   *lc;
 
-	/* Should only be applied to base relations that are subqueries */
-	Assert(rel->relid > 0);
 #ifdef USE_ASSERT_CHECKING
 	rte = planner_rt_fetch(rel->relid, root);
-	Assert(rte->rtekind == RTE_SUBQUERY);
 #endif
 
+	/* Should only be applied to base relations that are subqueries */
+	Assert(rel->relid > 0 && rte->rtekind == RTE_SUBQUERY);
+
 	/*
 	 * Copy raw number of output rows from subquery.  All of its paths should
 	 * have the same output rowcount, so just look at cheapest-total.
@@ -4639,13 +4639,13 @@ set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
 {
 	RangeTblEntry *rte PG_USED_FOR_ASSERTS_ONLY;
 
-	/* Should only be applied to base relations that are functions */
-	Assert(rel->relid > 0);
 #ifdef USE_ASSERT_CHECKING
 	rte = planner_rt_fetch(rel->relid, root);
-	Assert(rte->rtekind == RTE_TABLEFUNC);
 #endif
 
+	/* Should only be applied to base relations that are functions */
+	Assert(rel->relid > 0 && rte->rtekind == RTE_TABLEFUNC);
+
 	rel->tuples = 100;
 
 	/* Now estimate number of output rows, etc */
