Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmQR0-0003BW-CV for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Dec 2020 00:00:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kmQQT-0007xe-6u for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Dec 2020 00:00:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmQQT-0007xX-0L for pgsql-hackers@lists.postgresql.org; Tue, 08 Dec 2020 00:00:17 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kmQQQ-0000al-EI for pgsql-hackers@postgresql.org; Tue, 08 Dec 2020 00:00:16 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id AF2B75C0278; Mon, 7 Dec 2020 19:00:13 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 07 Dec 2020 19:00:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=kL0sIwqWqJfsUzF1V +ncJBauuzQXdhJHqOwl9UtVMTY=; b=JTqwFO2gTpJ/YGAjD1qktSiB9OUwbuIkv I4P0gm7lPxTUWuvBqf4I7WJAmZ2CEvFYH1QDDr1A5lymJHPFgzZRZiQERCZSIaQP PL/vkfIwj2ToVSi7tMvT6/Ws7OHOfVTQnEGY/6ipLrE16D82fslN8cTFt8LWA3W9 y7VFoqYW+WZYhEiZ569fwJ3RjFzXcH4b5A9Yiy4Om75ADnNFwtQTagip2f1oxAi8 kRSR8J/wX2/o0GWuwksjmF/nyJhBTdUaIZwbGWhHTXpXCUAxwgy/ktBVXANgmJnS hoBo08zYyX3Zr7465AdlSKaMWyc2FNjQNSsUBdUe1YiY7qA7/+4tA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudejhedgudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggujggfsehttdertddtredvnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpeevgfelveegueejgefhgeetgefhgeehieefheehleetteei udeiiefhgffgheffteenucfkphepudeltddrleehrddukedrjeelnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhv hhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.18.79]) by mail.messagingengine.com (Postfix) with ESMTPA id 010F224005E; Mon, 7 Dec 2020 19:00:12 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 0AEF12A154D; Mon, 7 Dec 2020 21:00:10 -0300 (-03) Date: Mon, 7 Dec 2020 21:00:10 -0300 From: Alvaro Herrera To: Alexander Korotkov Cc: Paul A Jungwirth , Justin Pryzby , Tom Lane , PostgreSQL-development , Jeff Davis , Pavel Stehule , David Fetter Subject: Re: range_agg Message-ID: <20201208000010.GA2786@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Dec-08, Alexander Korotkov wrote: > I also found a problem in multirange types naming logic. Consider the > following example. > > create type a_multirange AS (x float, y float); > create type a as range(subtype=text, collation="C"); > create table tbl (x __a_multirange); > drop type a_multirange; > > If you dump this database, the dump couldn't be restored. The > multirange type is named __a_multirange, because the type named > a_multirange already exists. However, it might appear that > a_multirange type is already deleted. When the dump is restored, a > multirange type is named a_multirange, and the corresponding table > fails to be created. The same thing doesn't happen with arrays, > because arrays are not referenced in dumps by their internal names. > > I think we probably should add an option to specify multirange type > names while creating a range type. Then dump can contain exact type > names used in the database, and restore wouldn't have a names > collision. Hmm, good point. I agree that a dump must preserve the name, since once created it is user-visible. I had not noticed this problem, but it's obvious in retrospect. > In general, I wonder if we can make the binary format of multiranges > more efficient. It seems that every function involving multiranges > from multirange_deserialize(). I think we can make functions like > multirange_contains_elem() much more efficient. Multirange is > basically an array of ranges. So we can pack it as follows. > 1. Typeid and rangecount > 2. Tightly packed array of flags (1-byte for each range) > 3. Array of indexes of boundaries (4-byte for each range). Or even > better we can combine offsets and lengths to be compression-friendly > like jsonb JEntry's do. > 4. Boundary values > Using this format, we can implement multirange_contains_elem(), > multirange_contains_range() without deserialization and using binary > search. That would be much more efficient. What do you think? I also agree. I spent some time staring at the I/O code a couple of months back but was unable to focus on it for long enough. I don't know JEntry's format, but I do remember that the storage format for JSONB was widely discussed back then; it seems wise to apply similar logic or at least similar reasoning.