diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index e200dcf472..d345522866 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -1704,10 +1704,10 @@ cost_mergejoin(MergePath *path, PlannerInfo *root, SpecialJoinInfo *sjinfo) innerendsel; Path sort_path; /* dummy for result of cost_sort */ - /* Protect some assumptions below that rowcounts aren't zero */ - if (outer_path_rows <= 0) + /* Protect some assumptions below that rowcounts aren't zero or NaN */ + if (outer_path_rows <= 0 || isnan(outer_path_rows)) outer_path_rows = 1; - if (inner_path_rows <= 0) + if (inner_path_rows <= 0 || isnan(inner_path_rows)) inner_path_rows = 1; if (!enable_mergejoin)