Re: range_agg - Mailing list pgsql-hackers

From Paul A Jungwirth
Subject Re: range_agg
Date
Msg-id CA+renyXwdgfJJVgAFBK2vfvrXrseLy6pq-mnhvKAdfazwEB30w@mail.gmail.com
Whole thread Raw
In response to Re: range_agg  (David Fetter <david@fetter.org>)
Responses Re: range_agg  (Paul A Jungwirth <pj@illuminatedcomputing.com>)
Re: range_agg  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-hackers
On Fri, Jul 5, 2019 at 10:45 AM David Fetter <david@fetter.org> wrote:
> If I understand the cases correctly, the combination of covering_range
> and multi_range types covers all cases. To recap, covering_range_agg
> assigns a weight, possibly 0, to each non-overlapping sub-range.  A
> cast from covering_range to multi_range would meld adjacent ranges
> with non-zero weights into single ranges in O(N) (N sub-ranges) time
> and some teensy amount of memory for tracking progress of adjacent
> ranges of non-zero weight.  Gaps would just be multi_range consisting
> of the sub-ranges of the covering_range with weight 0, and wouldn't
> require any tracking.

I take it that a multirange contains of *disjoint* ranges, so instead
of {[1,2), [2,3), [6,7)} you'd have {[1,3), [6,7)}. Jeff does that
match your expectation?

I just realized that since weighted_range_agg and covering_range_agg
return tuples of (anyrange, integer) (maybe other numeric types too?),
their elements are *not ranges*, so they couldn't return a multirange.
They would have to return an array of those tuples.

I agree that if you had a pre-sorted list of weighted ranges (with or
without zero-weight elements), you could convert it to a multirange in
O(n) very easily.

Paul



pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: range_agg
Next
From: Paul A Jungwirth
Date:
Subject: Re: range_agg