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 1lsRzD-00042S-Gd for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Jun 2021 15:25:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lsRzB-0002fC-VV for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Jun 2021 15:25: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 1lsRzB-0002f3-EO for pgsql-hackers@lists.postgresql.org; Sun, 13 Jun 2021 15:25:17 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lsRz7-0007Nf-7Q for pgsql-hackers@lists.postgresql.org; Sun, 13 Jun 2021 15:25:15 +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=Yrm+bW9edCi6qP0QRmrU5Eblfqz2NxppPlTcpPRh77g=; b=ClOtoUSt1v+TxQxBSHQVQ8gozm FSGUeQJjXHTiNM9T+GmdRFIku/3p2IxJ2TyGTwc8eNiwXSl4wvLXKFc+QGqSHE5rfFxHyq8Pdp072 lDdb0QBK3p4UYGN4dtygMSk4RZsMy6kM7lZA+S9Z6FN09b+d/3okAIh1FlxyAffO7O5IgqABwWkc9 rWY6nTM/MIQtL27UL7Gkki3FQEYdp1G3Uv10lgPmvqIK4RZhbHFJemO5c1SIvvGAg1+nMXfCd+Azh 8KWdZ8sCk7KeWQ9oEenlxd4jQqeRpYvsNK6dOz00kZW5yLRMcur/yMrRyQdzjp2UFDS0SX0ZW/MTD lB0DRfdw==; Received: from pool-71-105-8-149.nycmny.fios.verizon.net ([71.105.8.149] helo=[192.168.1.153]) by meldrar.postgresql.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lsRz3-0000tB-RP; Sun, 13 Jun 2021 15:25:11 +0000 Subject: Re: unnesting multirange data types To: Zhihong Yu , Alexander Korotkov Cc: Justin Pryzby , 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> <3648e50c-eb0d-4d16-7194-1a1c62893726@postgresql.org> From: "Jonathan S. Katz" Message-ID: Date: Sun, 13 Jun 2021 11:25:05 -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="OW4N5UEXxf4uYHPD7rRxC4dUK8EzdxYMa" 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) --OW4N5UEXxf4uYHPD7rRxC4dUK8EzdxYMa Content-Type: multipart/mixed; boundary="nlcxFY5OhWGIvKpWoD2DAgIV6oo0UwUn7"; protected-headers="v1" From: "Jonathan S. Katz" To: Zhihong Yu , Alexander Korotkov Cc: Justin Pryzby , Alvaro Herrera , Tom Lane , PostgreSQL Hackers Message-ID: 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> <3648e50c-eb0d-4d16-7194-1a1c62893726@postgresql.org> In-Reply-To: --nlcxFY5OhWGIvKpWoD2DAgIV6oo0UwUn7 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 6/13/21 10:57 AM, Zhihong Yu wrote: >=20 >=20 > On Sat, Jun 12, 2021 at 4:58 PM Alexander Korotkov > wrote: >=20 > On Sun, Jun 13, 2021 at 1:16 AM Jonathan S. Katz > > wrote: > > 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.=C2=A0 It contains both tests and docs. > > >>> > > >>> |+=C2=A0 =C2=A0The multirange could be explicitly cast to the= array of > corresponding > > >>> 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( > > >>>=C2=A0 =C2=A0 =C2=A0cast(pg_catalog.int8multirange() as int8mu= ltirange)) 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. > > > > > > A revised patch is attached.=C2=A0 Now empty multiranges are ha= ndled > > > properly (and it's covered by tests).=C2=A0 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: > > > > +=C2=A0 > > +=C2=A0 =C2=A0The multirange can be cast to an array of correspon= ding ranges. > > +=C2=A0 > > > > becomes: > > > > +=C2=A0 > > +=C2=A0 =C2=A0A multirange can be cast to an array of ranges of t= he same type. > > +=C2=A0 >=20 > Thank you. This change is incorporated in the attached revision of > the patch. >=20 > This thread gave me another lesson about English articles.=C2=A0 Ho= pefully, > I would be able to make progress in future patches :) >=20 > > Again, I'll defer to others on the code, but this seems to solve > the use > > case I presented. Thanks for the quick turnaround! >=20 > Thank you for the feedback! >=20 > ------ > Regards, > Alexander Korotkov >=20 >=20 > Hi, > + =C2=A0 A multirange can be cast to an array of ranges of the same typ= e. >=20 > I think 'same type' is not very accurate. It should be 'of the subtype'= =2E I think that's more technically correct, but it could be confusing to the user. There is an example next to it that shows how this function works, i.e. it returns the type of range that is represented by the multirange. > + =C2=A0 ObjectAddress myself, >=20 > nit: myself -> self >=20 > +/* Turn multirange into a set of ranges */ >=20 > set of ranges: sequence of ranges I believe "set of ranges" is accurate here, as the comparable return is a "SETOF rangetype". Sequences are objects unto themselves. Jonathan --nlcxFY5OhWGIvKpWoD2DAgIV6oo0UwUn7-- --OW4N5UEXxf4uYHPD7rRxC4dUK8EzdxYMa 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/x8QSccp8cZScFAmDGI1EFAwAAAAAACgkQ8QSccp8cZSdR lhAAj9X6dkm6hTKPGZnNE+hcLkLKMYf/IAngdue3WkpjBdn8kfDzCrwxG/rgdO0WS8hbPhmzpgbQ uy3kdaCGqID69sR33PzImiCd1cMToT8rl2P8qHySdTDajl+AYTnQKISOz4xSz+zDPHHW9kjDgRCj XBDc4RcYZDSuNX9hzp80nblnpB8JulrHq2kvIAbc4E0GPm8b7IFbl2OfUJpKJrlGCVX/3QuIKGYX +k3e9xhNNfo7wnF0HNLvcIUPc6pAhRjKYDCbAoV+DybYLBBnUUwQTwsWzJ5FpwRh8pI+T+ZloWdt k2rg7krZgg1cvEbQvOl+lJ3z1YWRWj40woyoXVSTdZAgIQeCsj6YForyj/TlcdnELf6Syxwd58wI Omw5yFi0oI8whpGz8BETLnS/6IitsE4XUSj28Cwm97gKtrUZeOOLaLFYTXaNBPCPIt9TI/qyPDyT x72fcxJ8Q9GtBQPTni+SJRIufSbnpi86o9iio7w6jeFE7xCt78OLe7nZqRw6mRU7e4B0HgkFgypl XTzLoQ2g5y6yNSt0U8Y9EXCqjoZT1Q3c/tNhNzT7IJhL71wNIRdgeEiYjkfeojZYYcYQG6aOrocP 2e59Rpppn741Q6ofxRBb26QbpsSlpY7/8c+FAD9Epon+2R4dhOkp6OCJ/g5SAZ7jf1g64fD7yYHB eHM= =/xsR -----END PGP SIGNATURE----- --OW4N5UEXxf4uYHPD7rRxC4dUK8EzdxYMa--