From ec3a019382d8ed81ef1747fcf94f84955ad9c1a3 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 12 Oct 2026 03:09:18 -0400 Subject: [PATCH v1 1/2] btree_gin: Fix timestamptz lower bound in repeated DST hour. A timestamptz bound inside the repeated hour of the autumn clock change was converted to a local key that was too late. The index scan then skipped rows that match. If the key maps back to a later instant than the bound, move it earlier by the difference. --- contrib/btree_gin/btree_gin.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c index 8dfbaa4781d..3431b56977f 100644 --- a/contrib/btree_gin/btree_gin.c +++ b/contrib/btree_gin/btree_gin.c @@ -513,6 +513,21 @@ cvt_timestamptz_timestamp(Datum input) result = timestamptz2timestamp_safe(val, (Node *) &escontext); /* We can ignore errors, since result is useful as-is */ + + /* + * In the repeated hour at the end of DST, the comparison operators map a + * local timestamp to the later of its two instants. The result must not + * map to a later instant than "val", or entries in between are skipped. + */ + if (!escontext.error_occurred && !TIMESTAMP_NOT_FINITE(result)) + { + TimestampTz back; + + back = timestamp2timestamptz_safe(result, (Node *) &escontext); + if (!escontext.error_occurred && back > val && + back - val <= result - MIN_TIMESTAMP) + result -= back - val; + } return TimestampGetDatum(result); } -- 2.37.1 (Apple Git-137.1)