@@ -264,6 +264,7 @@ cost_index(IndexPath *path, PlannerInfo *root,
264264
265265if (!enable_indexscan )
266266startup_cost += disable_cost ;
267+ /* we don't need to check enable_indexonlyscan; indxpath.c does that */
267268
268269/*
269270 * Call index-access-method-specific code to estimate the processing cost
@@ -345,7 +346,8 @@ cost_index(IndexPath *path, PlannerInfo *root,
345346(double )index -> pages ,
346347root );
347348
348- pages_fetched = ceil (pages_fetched * visibility_fraction );
349+ if (indexonly )
350+ pages_fetched = ceil (pages_fetched * visibility_fraction );
349351
350352max_IO_cost = (pages_fetched * spc_random_page_cost ) /num_scans ;
351353
@@ -366,7 +368,8 @@ cost_index(IndexPath *path, PlannerInfo *root,
366368(double )index -> pages ,
367369root );
368370
369- pages_fetched = ceil (pages_fetched * visibility_fraction );
371+ if (indexonly )
372+ pages_fetched = ceil (pages_fetched * visibility_fraction );
370373
371374min_IO_cost = (pages_fetched * spc_random_page_cost ) /num_scans ;
372375}
@@ -381,15 +384,17 @@ cost_index(IndexPath *path, PlannerInfo *root,
381384(double )index -> pages ,
382385root );
383386
384- pages_fetched = ceil (pages_fetched * visibility_fraction );
387+ if (indexonly )
388+ pages_fetched = ceil (pages_fetched * visibility_fraction );
385389
386390/* max_IO_cost is for the perfectly uncorrelated case (csquared=0) */
387391max_IO_cost = pages_fetched * spc_random_page_cost ;
388392
389393/* min_IO_cost is for the perfectly correlated case (csquared=1) */
390394pages_fetched = ceil (indexSelectivity * (double )baserel -> pages );
391395
392- pages_fetched = ceil (pages_fetched * visibility_fraction );
396+ if (indexonly )
397+ pages_fetched = ceil (pages_fetched * visibility_fraction );
393398
394399min_IO_cost = spc_random_page_cost ;
395400if (pages_fetched > 1 )