diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 4283ce9f96..e62219e350 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3509,7 +3509,7 @@ estimate_path_cost_size(PlannerInfo *root,
 					   fpinfo->stage == UPPERREL_GROUP_AGG);
 				adjust_foreign_grouping_path_cost(root, pathkeys,
 												  retrieved_rows, width,
-												  fpextra->limit_tuples,
+												  fpextra ? fpextra->limit_tuples : 0.0,
 												  &disabled_nodes,
 												  &startup_cost, &run_cost);
 			}
 
