From a0bbabe82503bf5ab2c5c3c4dc3ee0a3c33806a1 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 3 Dec 2026 11:52:57 +0100 Subject: [PATCH 2/5] gistbuild: Fix variable type itupAvgSize in gistInitBuffering() holds an average computed in double, but it was declared as Size, so the average was truncated, and avgIndexTuplesPerPage = pageFreeSpace / itupAvgSize becomes an integer division. The analogous variable in calculatePagesPerBuffer() is already declared as double, so declaring it as Size here was probably a mistake. This could also lead to a miscalculation further below in gistInitBuffering(): If itupAvgSize is larger than half of pageFreeSpace, then avgIndexTuplesPerPage becomes exactly 1, and the subtreesize calculation below has a division by zero, which becomes a NaN, and then the effective_cache_size limit is not applied as intended. --- src/backend/access/gist/gistbuild.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c index 07bad403b2d..dea31142f00 100644 --- a/src/backend/access/gist/gistbuild.c +++ b/src/backend/access/gist/gistbuild.c @@ -628,8 +628,8 @@ gistInitBuffering(GISTBuildState *buildstate) Relation index = buildstate->indexrel; int pagesPerBuffer; Size pageFreeSpace; - Size itupAvgSize, - itupMinSize; + double itupAvgSize; + Size itupMinSize; double avgIndexTuplesPerPage, maxIndexTuplesPerPage; int i; -- 2.56.0