Re: range_adjacent and discrete ranges
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Florian Pflug <fgp@phlo.org>
Cc: Jeff Davis <pgsql@j-davis.com>, pgsql-hackers@postgresql.org
Date: 2011-11-23T02:40:48Z
Lists: pgsql-hackers
Attachments
- range_adjacent_reimplementation.patch (text/x-patch) patch
Florian Pflug <fgp@phlo.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