# Re: range_adjacent and discrete ranges

From: Florian Pflug Jeff Davis pgsql-hackers(at)postgresql(dot)org Re: range_adjacent and discrete ranges 2011-11-18 12:32:47 6E64B613-26C2-48EA-8456-E02DBC9E8CAA@phlo.org Raw Message | Whole Thread | Download mbox | Resend email 2011-11-18 08:25:24 from Jeff Davis  2011-11-18 12:32:47 from Florian Pflug   2011-11-18 15:33:13 from Tom Lane    2011-11-18 16:56:06 from Jeff Davis     2011-11-18 19:47:46 from Tom Lane      2011-11-19 18:52:22 from Jeff Davis       2011-11-19 21:03:01 from Tom Lane        2011-11-20 00:41:31 from Florian Pflug   2011-11-18 16:58:49 from Jeff Davis   2011-11-23 02:40:48 from Tom Lane 📎    2011-11-23 21:10:04 from Tom Lane     2011-11-23 21:39:35 from Tom Lane 📎 pgsql-hackers

On Nov18, 2011, at 09:25 , Jeff Davis wrote:
> 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.

Hm, the problem here is for range_adjacent to recognize that [1,2] is
adjacent to [3,4] when treated as integer ranges, but that they're not
adjacent when treated as float ranges. The reason being, of course, that
there's isn't any integer between 2 and 3, but there are floats between
2 and 3.

That information, however, *is* already contained in the canonical
functions, because those function know that (2,3) are empty as an integer
range, but non-empty as a float range.

For example, [1,2] is adjacent to [3,4] as integer ranges because (2,3)
is empty as an integer range. Conversely, since (2,3) is *not* empty as a
float range, [1,2] and [3,4] are *not* adjacent as float ranges.

More formally, let there be two arbitrary ranges
a,b,i_a,i_b
c,d,i_c,i_d
where the first two parameters are the lower respectively upper bound, and
the last two are booleans saying whether the lower respectively upper bound
is inclusive (true) or exclusive (false).

These ranges are then adjacent exactly if the range
b,c,!i_b,!i_c
is empty.

This definition does not depend on any specific canonical form of ranges,
only on the canonicalize function's ability to detect empty ranges.

best regards,
Florian Pflug

### Browse pgsql-hackers by date

From Date Subject
Next Message Albe Laurenz 2011-11-18 13:04:15 Review for "Add permission check on SELECT INTO"
Previous Message Shigeru Hanada 2011-11-18 12:00:10 Re: WIP: Collecting statistics on CSV file data