Re: range_adjacent and discrete ranges

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: range_adjacent and discrete ranges
Date: 2011-11-18 12:32:47
Message-ID: 6E64B613-26C2-48EA-8456-E02DBC9E8CAA@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

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