From 5bb255348a3da7cd5c85f12958166259fa0d722c Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 12 Oct 2026 03:09:18 -0400 Subject: [PATCH v2 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. Move the key back an hour at a time until it no longer compares as later than the bound. --- contrib/btree_gin/btree_gin.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/btree_gin/btree_gin.c b/contrib/btree_gin/btree_gin.c index 8dfbaa4781d..54cef55c66e 100644 --- a/contrib/btree_gin/btree_gin.c +++ b/contrib/btree_gin/btree_gin.c @@ -513,6 +513,15 @@ 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 result can compare as later + * than val, and the scan would then start past matching entries. Back up + * until it does not. + */ + while (!TIMESTAMP_NOT_FINITE(result) && + timestamp_cmp_timestamptz_internal(result, val) > 0) + result -= USECS_PER_HOUR; return TimestampGetDatum(result); } -- 2.37.1 (Apple Git-137.1)