Re: Range Types, discrete and/or continuous

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Range Types, discrete and/or continuous
Date: 2010-10-25 17:00:36
Message-ID: AANLkTiks_x93_k82b4f_ga634wCi0oeb9fTrUrF28EGM@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Oct 25, 2010 at 12:51 PM, Jeff Davis <pgsql(at)j-davis(dot)com> wrote:
> On Sun, 2010-10-24 at 18:59 -0400, Tom Lane wrote:
>> Jeff Davis <pgsql(at)j-davis(dot)com> writes:
>> > Last development cycle, one of the questions that was unresolved was
>> > whether to handle ranges like a discrete set (that is, [1,5) = [1,4] )
>> > or continuous or both.
>>
>> Put me in the camp that says you need both.  I really seriously dislike
>> the idea of representing [1, 2) as [1, 2-epsilon], mainly because there
>> is often no portable value for epsilon.  Dump-and-restore would be quite
>> hazardous.
>>
>
> OK. I tried to present a couple approaches for achieving that. To
> summarize:
>
> The most obvious way would be different code paths and DDL options that
> let postgresql know whether it's continuous or discrete. That may make
> it easier to create new range types with just DDL and without defining
> any low-level functions, and postgresql may be able to take care of
> representational issues.
>
> Another way, suggested by Nathan Boley, is to require the type
> definition to do a lot of work and define its own representation that's
> opaque to postgres. Then, postgres would ask for information through
> accessors like min (null if open at beginning), max (null if open at
> end), upper bound, lower bound, and flags (to indicate null or infinite
> boundaries). This requires more work to define a new range type, and it
> certainly couldn't be done with DDL only. However, it seems to allow
> discrete and continuous ranges to work together more seamlessly and
> share more code. I am leaning toward this approach.

I'm still confused. It seems to me (and maybe I'm full of it) that
the distinction between continuous ranges and discrete ranges is
pretty minor. Suppose you have continuous ranges done, and working.
The only thing you need to add for discrete ranges (I think) is a
canonicalization function that converts a range with one or both ends
open to a range with both ends closed. Then you just apply this
canonicalization functions to every value supplied by the user before
doing anything else with it. Poof, discrete ranges! What am I
missing?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-10-25 17:08:38 Re: add label to enum syntax
Previous Message Peter Eisentraut 2010-10-25 16:51:26 Re: O_DSYNC broken on MacOS X?