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

Re: range_adjacent and discrete ranges

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Florian Pflug <fgp(at)phlo(dot)org>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: range_adjacent and discrete ranges
Date: 2011-11-23 02:40:48
Message-ID: 11024.1322016048@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Florian Pflug <fgp(at)phlo(dot)org> writes:
> 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.

I tried to implement this, and I think it has a small bug.  It works as
stated if we have b < c.  However, if we have b == c, then we want to
consider the ranges adjacent if i_b != i_c (ie, only one of them claims
the common boundary point).  But a singleton range is empty unless it's
inclusive on both sides.  So we have to have a special case when the
bounds are equal.

(If b > c, then of course we have to consider the two ranges in the
opposite order.)

Attached is a draft patch for this.  It passes regression tests but I've
not tried to exercise it with a canonical function that actually does
something different.  It's going to be a bit slower than Jeff's
original, because it does not only range_cmp_bound_values but also a
make_range cycle (in most cases).  So I guess the question is how much
we care about supporting canonical functions with non-default policies.
Thoughts?

			regards, tom lane


Attachment: range_adjacent_reimplementation.patch
Description: text/x-patch (2.8 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2011-11-23 03:28:14
Subject: Re: Permissions checks for range-type support functions
Previous:From: Peter GeogheganDate: 2011-11-23 01:09:23
Subject: Re: Inlining comparators as a performance optimisation

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