pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Bad canonicalization for dateranges with 'infinity' bounds
Date: Thu, 02 May 2019 14:49:23 +0200
Message-ID: <539fbfe416eb3d7ebf72268eb839163a68aed9ef.camel@cybertec.at> (raw)
In-Reply-To: <77f24ea19ab802bc9bc60ddbb8977ee2d646aec1.camel@cybertec.at>
References: <77f24ea19ab802bc9bc60ddbb8977ee2d646aec1.camel@cybertec.at>

I wrote:
> I propose the attached patch which fixes the problem.

I forgot to attach the patch.  Here it is.

Yours,
Laurenz Albe

Attachments:

0001-Don-t-canonicalize-dateranges-with-infinity-bounds.patch (text/x-patch, 3.4K) download From 6bbad0acf3baae3a08d1f911b7017642c8a8afe9 Mon Sep 17 00:00:00 2001 From: Laurenz Albe <laurenz.albe@cybertec.at> Date: Thu, 2 May 2019 14:32:27 +0200 Subject: [PATCH] Don't canonicalize dateranges with 'infinity' bounds Since adding one to infinity doesn't change the value, canonicalization of dateranges with an explicit '-infinity' as exclusive lower bound would make it an inclusive bound, while dateranges with 'infinity' as inclusive upper bound would turn it into an exclusive bound. --- src/backend/utils/adt/rangetypes.c | 4 ++-- src/test/regress/expected/rangetypes.out | 24 ++++++++++++++++++++++++ src/test/regress/sql/rangetypes.sql | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c index 72c450c70e..a98f17bb66 100644 --- a/src/backend/utils/adt/rangetypes.c +++ b/src/backend/utils/adt/rangetypes.c @@ -1431,13 +1431,13 @@ daterange_canonical(PG_FUNCTION_ARGS) if (empty) PG_RETURN_RANGE_P(r); - if (!lower.infinite && !lower.inclusive) + if (!(lower.infinite || DATE_NOT_FINITE(lower.val)) && !lower.inclusive) { lower.val = DirectFunctionCall2(date_pli, lower.val, Int32GetDatum(1)); lower.inclusive = true; } - if (!upper.infinite && upper.inclusive) + if (!(upper.infinite || DATE_NOT_FINITE(upper.val)) && upper.inclusive) { upper.val = DirectFunctionCall2(date_pli, upper.val, Int32GetDatum(1)); upper.inclusive = false; diff --git a/src/test/regress/expected/rangetypes.out b/src/test/regress/expected/rangetypes.out index accf1e0d9e..60d875e898 100644 --- a/src/test/regress/expected/rangetypes.out +++ b/src/test/regress/expected/rangetypes.out @@ -652,6 +652,30 @@ select daterange('2000-01-10'::date, '2000-01-11'::date, '(]'); [01-11-2000,01-12-2000) (1 row) +select daterange('-infinity'::date, '2000-01-01'::date, '()'); + daterange +------------------------ + (-infinity,01-01-2000) +(1 row) + +select daterange('-infinity'::date, '2000-01-01'::date, '[)'); + daterange +------------------------ + [-infinity,01-01-2000) +(1 row) + +select daterange('2000-01-01'::date, 'infinity'::date, '[)'); + daterange +----------------------- + [01-01-2000,infinity) +(1 row) + +select daterange('2000-01-01'::date, 'infinity'::date, '[]'); + daterange +----------------------- + [01-01-2000,infinity] +(1 row) + -- test GiST index that's been built incrementally create table test_range_gist(ir int4range); create index test_range_gist_idx on test_range_gist using gist (ir); diff --git a/src/test/regress/sql/rangetypes.sql b/src/test/regress/sql/rangetypes.sql index 55638a85ee..9fdb1953df 100644 --- a/src/test/regress/sql/rangetypes.sql +++ b/src/test/regress/sql/rangetypes.sql @@ -165,6 +165,10 @@ select daterange('2000-01-10'::date, '2000-01-20'::date, '(]'); select daterange('2000-01-10'::date, '2000-01-20'::date, '()'); select daterange('2000-01-10'::date, '2000-01-11'::date, '()'); select daterange('2000-01-10'::date, '2000-01-11'::date, '(]'); +select daterange('-infinity'::date, '2000-01-01'::date, '()'); +select daterange('-infinity'::date, '2000-01-01'::date, '[)'); +select daterange('2000-01-01'::date, 'infinity'::date, '[)'); +select daterange('2000-01-01'::date, 'infinity'::date, '[]'); -- test GiST index that's been built incrementally create table test_range_gist(ir int4range); -- 2.20.1

view thread (10+ messages)  latest in thread

Message-ID: <539fbfe416eb3d7ebf72268eb839163a68aed9ef.camel@cybertec.at>
Permalink:  ../539fbfe416eb3d7ebf72268eb839163a68aed9ef.camel@cybertec.at/
Also on:    postgresql.org/message-id/539fbfe416eb3d7ebf72268eb839163a68aed9ef.camel@cybertec.at

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: laurenz.albe@cybertec.at, pgsql-hackers@lists.postgresql.org
  Subject: Re: Bad canonicalization for dateranges with 'infinity' bounds
  In-Reply-To: <539fbfe416eb3d7ebf72268eb839163a68aed9ef.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox