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 1lsBvg-0005dh-3B for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jun 2021 22:16:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lsBvd-0002J6-GZ for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jun 2021 22:16:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lsBvc-0002Iy-I0 for pgsql-hackers@lists.postgresql.org; Sat, 12 Jun 2021 22:16:33 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lsBva-0005zu-Q0 for pgsql-hackers@lists.postgresql.org; Sat, 12 Jun 2021 22:16:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=4KHpihVSEaTej0am7q3VRPZnc9OxnDe+0FSTP6KEbos=; b=rN7dtaOtbvJt3R0Qzqm4ox5iMD aoFj/cS4hagDW0fC1JNxML8OZYNqEtm6XUTSMD55sI7hG30Nf1+0uEkrbElNoTXX1z84ISIkAtM1o Clmx9YDOnAe+zESDMlwtiFG7yProFg6I8FNOyR4oqCFGxA02u2s5RX/WLLxhKg6Avr4sR5rs2RPNJ SynSwzjUX46/48FmWrOJIFHaAUE4oS2DuEPWgT0eqgSw7eag7Zey0sKONthQN4gQu7iPCdGJRSHVk fF3NHFgAd8h/D4BS8Zot86a4mS9pD6Zi95RsGP10Mx477qXkLvSdOMspPWIOoHI/TUVnKA9s4NSCR KAH43eSw==; Received: from [2600:380:597d:e922:581d:42a5:55a4:9cd5] (helo=Ph33rHippo.local) by meldrar.postgresql.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lsBvY-0002SP-DM; Sat, 12 Jun 2021 22:16:30 +0000 Subject: Re: unnesting multirange data types To: Alexander Korotkov , Justin Pryzby Cc: Alvaro Herrera , Tom Lane , PostgreSQL Hackers References: <202106092056.qitkvnvmpadu@alvherre.pgsql> <95432464-1b63-bc84-6f84-e9e9d79f9687@postgresql.org> <20210610220416.GJ16435@telsasoft.com> <20210611233017.GO16435@telsasoft.com> From: "Jonathan S. Katz" Message-ID: <3648e50c-eb0d-4d16-7194-1a1c62893726@postgresql.org> Date: Sat, 12 Jun 2021 18:16:24 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="aQX9U5s19MELLc2UDfPIDv71czlTrE4Cn" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2600:380:597d:e922:581d:42a5:55a4:9cd5 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --aQX9U5s19MELLc2UDfPIDv71czlTrE4Cn Content-Type: multipart/mixed; boundary="OklhbzJZaFTvRYgXRFTx3iMNUvcyA0LPF"; protected-headers="v1" From: "Jonathan S. Katz" To: Alexander Korotkov , Justin Pryzby Cc: Alvaro Herrera , Tom Lane , PostgreSQL Hackers Message-ID: <3648e50c-eb0d-4d16-7194-1a1c62893726@postgresql.org> Subject: Re: unnesting multirange data types References: <202106092056.qitkvnvmpadu@alvherre.pgsql> <95432464-1b63-bc84-6f84-e9e9d79f9687@postgresql.org> <20210610220416.GJ16435@telsasoft.com> <20210611233017.GO16435@telsasoft.com> In-Reply-To: --OklhbzJZaFTvRYgXRFTx3iMNUvcyA0LPF Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 6/12/21 5:57 PM, Alexander Korotkov wrote: > On Sat, Jun 12, 2021 at 2:44 AM Alexander Korotkov wrote: >> ()On Sat, Jun 12, 2021 at 2:30 AM Justin Pryzby = wrote: >>> On Fri, Jun 11, 2021 at 11:37:58PM +0300, Alexander Korotkov wrote: >>>> On Fri, Jun 11, 2021 at 1:04 AM Justin Pryzby = wrote: >>>>> >>>>> +{ oid =3D> '1293', descr =3D> 'expand mutlirange to set of ranges'= , >>>>> >>>>> typo: mutlirange >>>> >>>> Fixed, thanks. >>>> >>>> The patch with the implementation of both unnest() and cast to array= >>>> is attached. It contains both tests and docs. >>> >>> |+ The multirange could be explicitly cast to the array of correspo= nding >>> should say: "can be cast to an array of corresponding.." >>> >>> |+ * Cast multirange to the array of ranges. >>> I think should be: *an array of ranges >> >> Thank you for catching this. >> >>> Per sqlsmith, this is causing consistent crashes. >>> I took one of its less appalling queries and simplified it to this: >>> >>> select >>> pg_catalog.multirange_to_array( >>> cast(pg_catalog.int8multirange() as int8multirange)) as c2 >>> from (select 1)x; >> >> It seems that multirange_to_array() doesn't handle empty multiranges. >> I'll post an updated version of the patch tomorrow. >=20 > A revised patch is attached. Now empty multiranges are handled > properly (and it's covered by tests). Typos are fixed as well. Tested both against my original cases using both SQL + PL/pgSQL. All worked well. I also tested the empty multirange case as well. Overall the documentation seems to make sense, I'd suggest: + + The multirange can be cast to an array of corresponding ranges. + becomes: + + A multirange can be cast to an array of ranges of the same type. + Again, I'll defer to others on the code, but this seems to solve the use case I presented. Thanks for the quick turnaround! Jonathan --OklhbzJZaFTvRYgXRFTx3iMNUvcyA0LPF-- --aQX9U5s19MELLc2UDfPIDv71czlTrE4Cn Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEE+oS2la8r95ogZD/x8QSccp8cZScFAmDFMjkFAwAAAAAACgkQ8QSccp8cZSfP Dg//VQQqM1iS5oo0sqPCy9LTds0DTwNItsEKWaIJSHpSHUDUBru91+z3z+sYFqDAFWCrVE2OPEdN +lK46YJpBeub00hT2TqsdAtsiK8a7XeWN5shlwXXGv57mjjvZs/oAy7AH/rM6v4Q7hDr7G0jBOb6 5NtWMTk7BBv9aW1S9IXfZeQg+2TG6WDxmdZVmHpF6tO6jwSqFd8vnPbEPRI6hH92tGYoMJMTD01u rgeletHVc0L+ZRKHjCh9Rjrq9A5FKR86WZ2HsFkzRNHcQT4ZAy6dA/huPqMzLCiupzjPR6w5wuLt h82xkelSV0qpLKYCrSWHTczyuWzzEiMxbmWpRU8TKBzpXVsuPfboGduFVzcUWMryW0ewYhjkkaKl 8y+XeG3cIizalx8Akx2RSIZ5VGwliuHB530uVkgE+2LH5JZPrqN3hjy/BDiSXw4U+l7qHoIGmsra nYQSsHwNPmkoJZoWByFome1U6s0j8VrawNODF0ZGdgd1czDocPsm3gD+ylnLyHn19deumyRxrD/T ijYVtgl0NupAFjEOhB+2ygrQOyjoo9iMsfVcELuWH0M96J52GUEOWFTUjBjoOEqQTzkr5gvNvJxF ZMVRYAKaAk1EvIWLGBucq4av/BKDkxJ3281tTr8UEOdig4qbWBKSx34CTG56nsJtnUOP4uZmQjOQ 7J4= =rAXg -----END PGP SIGNATURE----- --aQX9U5s19MELLc2UDfPIDv71czlTrE4Cn--