Skip to content

Commit 8b965c5

Browse files
committed
compute_bitmap_pages' loop_count parameter should be double not int.
The value was double in the original implementation of this logic. Commit da08a65 pulled it out into a subroutine, but carelessly declared the parameter as int when it should have been double. On most platforms, the only ill effect would be to clamp the value to be not more than INT_MAX, which would seldom be exceeded and probably wouldn't change the estimates too much anyway. Nonetheless, it's wrong and can cause complaints from ubsan. While here, improve the comments and parameter names. This is an ABI change in a globally exposed subroutine, so back-patching would create some risk of breaking extensions. The value of the fix doesn't seem high enough to warrant taking that risk, so fix in HEAD only. Per report from Alexander Lakhin. Discussion: https://postgr.es/m/f5e15fe1-202d-1936-f47c-f0c69a936b72@gmail.com
1 parent 64b1fb5 commit 8b965c5

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,12 +6393,20 @@ get_parallel_divisor(Path *path)
63936393

63946394
/*
63956395
* compute_bitmap_pages
6396+
* Estimate number of pages fetched from heap in a bitmap heap scan.
63966397
*
6397-
* compute number of pages fetched from heap in bitmap heap scan.
6398+
* 'baserel' is the relation to be scanned
6399+
* 'bitmapqual' is a tree of IndexPaths, BitmapAndPaths, and BitmapOrPaths
6400+
* 'loop_count' is the number of repetitions of the indexscan to factor into
6401+
* estimates of caching behavior
6402+
*
6403+
* If cost_p isn't NULL, the indexTotalCost estimate is returned in *cost_p.
6404+
* If tuples_p isn't NULL, the tuples_fetched estimate is returned in *tuples_p.
63986405
*/
63996406
double
6400-
compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual,
6401-
int loop_count, Cost *cost, double *tuple)
6407+
compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
6408+
Path *bitmapqual, double loop_count,
6409+
Cost *cost_p, double *tuples_p)
64026410
{
64036411
Cost indexTotalCost;
64046412
Selectivity indexSelectivity;
@@ -6488,10 +6496,10 @@ compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual,
64886496
(lossy_pages / heap_pages) * baserel->tuples);
64896497
}
64906498

6491-
if (cost)
6492-
*cost = indexTotalCost;
6493-
if (tuple)
6494-
*tuple = tuples_fetched;
6499+
if (cost_p)
6500+
*cost_p = indexTotalCost;
6501+
if (tuples_p)
6502+
*tuples_p = tuples_fetched;
64956503

64966504
return pages_fetched;
64976505
}

src/include/optimizer/cost.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel);
210210
extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
211211
extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target);
212212
extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
213-
Path *bitmapqual, int loop_count, Cost *cost, double *tuple);
213+
Path *bitmapqual, double loop_count,
214+
Cost *cost_p, double *tuples_p);
214215

215216
#endif /* COST_H */

0 commit comments

Comments
 (0)