diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 7bf67a0529..480fd250e9 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -2941,8 +2941,13 @@ final_cost_mergejoin(PlannerInfo *root, MergePath *path, if (rescannedtuples < 0) rescannedtuples = 0; } - /* We'll inflate various costs this much to account for rescanning */ - rescanratio = 1.0 + (rescannedtuples / inner_path_rows); + + /* + * We'll inflate various costs this much to account for rescanning. Note + * that this is to be multiplied by something involving inner_rows, or + * another number related to the portion of the inner rel we'll scan. + */ + rescanratio = 1.0 + (rescannedtuples / inner_rows); /* * Decide whether we want to materialize the inner input to shield it from @@ -2969,7 +2974,7 @@ final_cost_mergejoin(PlannerInfo *root, MergePath *path, * of the generated Material node. */ mat_inner_cost = inner_run_cost + - cpu_operator_cost * inner_path_rows * rescanratio; + cpu_operator_cost * inner_rows * rescanratio; /* * If we don't need mark/restore at all, we don't need materialization.