Re: range_adjacent and discrete ranges - Mailing list pgsql-hackers

From Florian Pflug
Subject Re: range_adjacent and discrete ranges
Date
Msg-id 6E64B613-26C2-48EA-8456-E02DBC9E8CAA@phlo.org
Whole thread Raw
In response to range_adjacent and discrete ranges  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: range_adjacent and discrete ranges
Re: range_adjacent and discrete ranges
Re: range_adjacent and discrete ranges
List 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



pgsql-hackers by date:

Previous
From: Shigeru Hanada
Date:
Subject: Re: WIP: Collecting statistics on CSV file data
Next
From: "Albe Laurenz"
Date:
Subject: Review for "Add permission check on SELECT INTO"