I have found several cases where a variable or C function argument was
declared as an integer but should be a floating-point type, or vice
versa. See attached patches. I think most of these are harmless in
practice. The one in gistbuild.c is technically a bug, but it's in
quite rare circumstances and there is no correctness issue, so it's
probably not worth bothering with backpatching.
From 027824b0807ff1c26150c5acfffef7668ed07dce Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 3 Dec 2026 11:52:57 +0100
Subject: [PATCH 1/5] gininsert: Fix variable type
numtuples is only used with the increment operator and then passed to
a function taking an int64. Declaring it as double was a mistake. To
fix, change to int64.
---
src/backend/access/gin/gininsert.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/backend/access/gin/gininsert.c
b/src/backend/access/gin/gininsert.c
index cc74b28d637..38c71c044ab 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -1665,7 +1665,7 @@ _gin_parallel_merge(GinBuildState *state, IndexInfo
*indexInfo)
GinBuffer *buffer;
/* GIN tuples from workers, merged by leader */
- double numtuples = 0;
+ int64 numtuples = 0;
/* wait for workers to scan table and produce partial results */
reltuples = _gin_parallel_heapscan(state,
&indexInfo->ii_BrokenHotChain);
--
2.56.0
From a0bbabe82503bf5ab2c5c3c4dc3ee0a3c33806a1 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
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
From cfb6f26f57421077bee6c34932cbabd7c4e86a3a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 3 Dec 2026 11:52:57 +0100
Subject: [PATCH 3/5] postgres_fdw: Fix function argument type
adjust_foreign_grouping_path_cost() argument "width" should be of type
int, not double. The input comes from an int variable and the value
is used to pass it to another function taking int, so using double
here was just a mistake.
---
contrib/postgres_fdw/postgres_fdw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/postgres_fdw/postgres_fdw.c
b/contrib/postgres_fdw/postgres_fdw.c
index ccc97d53286..c455bbb80c2 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -527,7 +527,7 @@ static void get_remote_estimate(const char *sql,
static void adjust_foreign_grouping_path_cost(PlannerInfo *root,
List *pathkeys,
double retrieved_rows,
-
double width,
+
int width,
double limit_tuples,
int *p_disabled_nodes,
Cost *p_startup_cost,
@@ -3963,7 +3963,7 @@ static void
adjust_foreign_grouping_path_cost(PlannerInfo *root,
List
*pathkeys,
double
retrieved_rows,
- double width,
+ int width,
double
limit_tuples,
int
*p_disabled_nodes,
Cost
*p_startup_cost,
--
2.56.0
From ec6adf1065870989a612e593c106260380bebd8a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 3 Dec 2026 11:52:57 +0100
Subject: [PATCH 4/5] Fix type of cost_agg() argument input_width
cost_agg() argument "input_width" should be of type int, not double.
All callers pass a PathTarget.width, which has type int, and the value
is only passed on to hash_agg_entry_size() and relation_byte_size(),
which take integers, so using double here was just a mistake.
---
src/backend/optimizer/path/costsize.c | 2 +-
src/include/optimizer/cost.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/optimizer/path/costsize.c
b/src/backend/optimizer/path/costsize.c
index f760ef9aa3a..ec7c54b15aa 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2802,7 +2802,7 @@ cost_agg(Path *path, PlannerInfo *root,
List *quals,
int disabled_nodes,
Cost input_startup_cost, Cost input_total_cost,
- double input_tuples, double input_width)
+ double input_tuples, int input_width)
{
double output_tuples;
Cost startup_cost;
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
index 19f8753e2d8..f62f6a291f5 100644
--- a/src/include/optimizer/cost.h
+++ b/src/include/optimizer/cost.h
@@ -137,7 +137,7 @@ extern void cost_agg(Path *path, PlannerInfo *root,
List *quals,
int disabled_nodes,
Cost input_startup_cost, Cost
input_total_cost,
- double input_tuples, double
input_width);
+ double input_tuples, int input_width);
extern void cost_windowagg(Path *path, PlannerInfo *root,
List *windowFuncs,
WindowClause *winclause,
int input_disabled_nodes,
--
2.56.0
From 6b2c3f3b26aeecbce15b10978473e506a026ba09 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 3 Dec 2026 11:52:57 +0100
Subject: [PATCH 5/5] ecpg: Fix type of dt2time() argument
The first argument of the ecpg version of dt2time() was of type
double, a leftover from when floating-point timestamps were supported.
The backend version has long taken a Timestamp. Change the ecpg
version to take a timestamp (int64) as well. The main caller in
timestamp2tm() already passes an int64. The caller that computes a
fractional Julian day now casts explicitly, as the backend already
did.
---
src/interfaces/ecpg/pgtypeslib/dt.h | 2 +-
src/interfaces/ecpg/pgtypeslib/dt_common.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h
b/src/interfaces/ecpg/pgtypeslib/dt.h
index 83e6cad167d..1ed51a2cd2c 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -328,7 +328,7 @@ void j2date(int jd, int *year, int *month,
int *day);
void GetCurrentDateTime(struct tm *tm);
int date2j(int y, int m, int d);
void TrimTrailingZeros(char *str);
-void dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec);
+void dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t
*fsec);
int PGTYPEStimestamp_defmt_scan(char **str, char *fmt,
timestamp * d,
int *year, int *month, int *day,
int *hour, int *minute, int *second,
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c
b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 8c1f485f70c..bd68ccd58f8 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -1069,7 +1069,7 @@ GetCurrentDateTime(struct tm *tm)
}
void
-dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
+dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
{
int64 time;
@@ -2071,7 +2071,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
return
-1;
tmask |=
DTK_TIME_M;
- dt2time((time *
USECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
+
dt2time((timestamp) (time * USECS_PER_DAY), &tm->tm_hour, &tm->tm_min,
&tm->tm_sec, fsec);
}
break;
--
2.56.0