Skip site navigation (1) Skip section navigation (2)

range_adjacent and discrete ranges

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: range_adjacent and discrete ranges
Date: 2011-11-18 08:25:24
Message-ID: 1321604724.11794.41.camel@jdavis (view raw or flat)
Thread:
Lists: pgsql-hackers
While thinking about range_cmp_bounds, I started to think that the way
range_adjacent works is wrong.

range_adjacent() depends on the bounds of two ranges to match up, such
that the boundary values are equal, but one is exclusive and the other
inclusive, and one is a lower bound and the other an upper bound.

That makes perfect sense for continuous ranges because that is the only
way they can possibly be adjacent. It also works for the discrete ranges
as defined so far, because they use a canonical function that translates
the values to [) form. But if someone were to write a canonical function
that translates the ranges to [] or () form, range_adjacent would be
useless.

There are a few approaches to solving it:

1. Make the canonical function accept a "format" argument much like the
constructor, and have an output format stored in the catalog that would
be passed in under most circumstances. However, range_adjacent could
pass in its own form that would be useful for its purposes.

2. Replace the canonical function with "inc" and "dec" functions, or
some variation thereof. We'd still need some kind of output format to
match the current behavior, otherwise every range would always be output
in [) form (I don't necessarily object to that, but it would be a
behavior difference for user-defined range types).

3. Remove range_adjacent.

4. Do nothing, and document that the canonical function should translate
to either [) or (] if you want range_adjacent to work.

Thoughts?

Regards,
	Jeff Davis


Responses

pgsql-hackers by date

Next:From: Simon RiggsDate: 2011-11-18 08:53:09
Subject: Re: Inlining comparators as a performance optimisation
Previous:From: Jeff DavisDate: 2011-11-18 08:14:16
Subject: Re: Are range_before and range_after commutator operators?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group