Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jAhhE-0004S8-9q for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2020 22:13:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAhhC-0000Pj-Tn for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2020 22:13:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jAhhC-0000Pc-6e for pgsql-hackers@lists.postgresql.org; Sat, 07 Mar 2020 22:13:22 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jAhh5-0001uq-85 for pgsql-hackers@postgresql.org; Sat, 07 Mar 2020 22:13:18 +0000 Received: by fetter.org (Postfix, from userid 1001) id 41FE640BD0; Sat, 7 Mar 2020 23:13:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fetter.org; s=default; t=1583619193; bh=AtKQdLd+jy/BXMCEXhYvDmwa7dUSB6EmgOAOa8BEoqQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=5LUWYLnc4y3J6hrXbV47ywwrkoy1LEHElSsDK3Sn6KfzK4Yw2W2/av8/ACA2XnZja b4UEZH4IKuKmbU/aLxGZKbXDjcecI5Po5fgMFxVhzdRaFnsKxkgg6MCN8TnBxscv+Q gnyTxMtZWHRQB7SWrMuAwTyhKUy9nb060MoGB3oZyNdFC927PYsB2Kcuqne/aamXiM HmsgGbemRFa3+G9JGnFt18AP70q+GFTYuoozQeJOvxNB3WnKd7OkaKykmNwYCVgbC5 n4ZmQnNpxo1EB+HpDGVZOb+Ys7KWPeGDWsHNoaUFaP5ovSsfOqTUlru8E5GOU4HtIA yejkrhkbiD+CA== Date: Sat, 7 Mar 2020 23:13:13 +0100 From: David Fetter To: Tom Lane Cc: Paul A Jungwirth , Alvaro Herrera , Pavel Stehule , Jeff Davis , Pgsql Hackers Subject: Re: range_agg Message-ID: <20200307221312.GV13804@fetter.org> References: <20200304022849.GA5402@alvherre.pgsql> <13800.1583612399@sss.pgh.pa.us> <15764.1583615192@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15764.1583615192@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Mar 07, 2020 at 04:06:32PM -0500, Tom Lane wrote: > I wrote: > > However, what I'm on about right at the moment is that I don't think > > there should be any delta in that test at all. As far as I can see, > > the design idea here is that multiranges will be automatically created > > over range types, and the user doesn't need to do that. To my mind, > > that means that they're an implementation detail and should not show up as > > separately-owned objects, any more than an autogenerated array type does. > > Actually ... have you given any thought to just deciding that ranges and > multiranges are the same type? That is, any range can now potentially > contain multiple segments? That would eliminate a whole lot of the > tedious infrastructure hacking involved in this patch, and let you focus > on the actually-useful functionality. If we're changing range types rather than constructing a new multi-range layer atop them, I think it would be helpful to have some way to figure out quickly whether this new range type was contiguous. One way to do that would be to include a "range cardinality" in the data structure which be the number of left ends in it. One of the things I'd pictured doing with multiranges was along the lines of a "full coverage" constraint like "During a shift, there can be no interval that's not covered," which would correspond to a "range cardinality" of 1. I confess I'm getting a little twitchy about the idea of eliding the cases of "one" and "many", though. > Assuming that that's ok, it seems like we could consider the traditional > range functions like lower() and upper() to report on the first or last > range bound in a multirange --- essentially, they ignore any "holes" > that exist inside the range. And the new functions for multiranges > act much like array slicing, in that they give you back pieces of a range > that aren't actually of a distinct type. So new functions along the lines of lowers(), uppers(), opennesses(), etc.? I guess this could be extended as needs emerge. There's another use case not yet covered here that could make this even more complex, we should probably plan for it: multi-ranges with weights. For example, SELECT weighted_range_union(r) FROM (VALUES('[0,1)'::float8range), ('[0,3)'), '('[2,5)')) AS t(r) would yield something along the lines of: (([0,1),1), ([1,3),2), ([3,5),1)) and wedging that into the range type seems messy. Each range would then have a cardinality, and each range within would have a weight, all of which would be an increasingly heavy burden on the common case where there's just a single range. Enhancing a separate multirange type to have weights seems like a cleaner path forward. Given that, I'm -1 on mushing multi-ranges into a special case of ranges, or /vice versa/. Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate