Re: BUG #19761: btree_gist: "cannot subtract infinite dates" when inserting 'infinity' into a GiST index on date

From: Nitin Motiani <nitinmotiani(at)google(dot)com>
To: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Cc: alpkeles99(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19761: btree_gist: "cannot subtract infinite dates" when inserting 'infinity' into a GiST index on date
Date: 2026-10-25 11:35:39
Message-ID: CAH5HC96iozmO=H_sgihkb5F97evpjwb+4bCvY1RWVnxBK4a1hw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sun, Oct 25, 2026 at 11:51 AM Dilip Kumar <dilipbalaut(at)gmail(dot)com> wrote:
>
> I think we must fix date_dist as well otherwise it may cause
> inconsistent behavior between index scan and sequence scan, see below
> example
>
> CREATE TABLE t (d date);
> CREATE INDEX t_d_idx ON t USING gist (d);
> INSERT INTO t SELECT date '2000-01-01' + i FROM generate_series(1, 500) i;
> INSERT INTO t VALUES ('infinity');
> INSERT INTO t VALUES ('-infinity');
>
> postgres[3265593]=# SELECT d FROM t ORDER BY d <-> '2000-06-01' LIMIT 1;
> d
> ------------
> 2000-06-01
> (1 row)
>
> -- Now test by turning off the index scan
>
> postgres[3265593]=# set enable_indexscan =off;
> postgres[3265593]=# SELECT d FROM t ORDER BY d <-> '2000-06-01' LIMIT 1;
> 2026-10-25 06:15:58.591 UTC [3265593] ERROR: cannot subtract infinite dates
> 2026-10-25 06:15:58.591 UTC [3265593] STATEMENT: SELECT d FROM t
> ORDER BY d <-> '2000-06-01' LIMIT 1;
> ERROR: 22008: cannot subtract infinite dates
> LOCATION: date_mi, date.c:554
>
> --

Thanks for the review, Dilip. I'm attaching the v2 patch which makes
the change in date_dist also.

Regards,
Nitin Motiani
Google

Attachment Content-Type Size
v2-0001-btree_gist-Fix-cannot-subtract-infinite-dates-err.patch application/x-patch 7.2 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Nitin Motiani 2026-10-25 12:03:00 Re: BUG #19767: pg_get_viewdef prints ORDER BY (- '3'::int4) as (- 3), which reparses as column position -3
Previous Message Ludwig Kannicht 2026-10-25 09:34:52 ORCE ROW LEVEL SECURITY makes ADD/VALIDATE FOREIGN KEY skip rows hidden from the owner (RI_Initial_Check)