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.89) (envelope-from ) id 1h7CVE-0008IK-Ma for pgsql-committers@arkaria.postgresql.org; Fri, 22 Mar 2019 05:14:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h7CVD-0002ep-C6 for pgsql-committers@arkaria.postgresql.org; Fri, 22 Mar 2019 05:13:59 +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 1h7CVD-0002Z2-45 for pgsql-committers@lists.postgresql.org; Fri, 22 Mar 2019 05:13:59 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7CVA-0002kD-Tc for pgsql-committers@lists.postgresql.org; Fri, 22 Mar 2019 05:13:58 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8D76021D3C; Fri, 22 Mar 2019 01:13:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 22 Mar 2019 01:13:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=z5CFm1341lUdBr1NCFj0PRLOVCA MPoSU9uIJrgw00Cc=; b=YxCu3/s90BcwKeKomDVNDucJX1iF4/unZ1yBNougXqF 85yF2uJKS7u4CbNF1FkuZe9VOG3XCMdxwAGmmtnZ7n3AtRPXmehC/6+QLb22axDv zdaRdK5FhQ51ePIHaK8vr+Xih/V5SM5bmpspNtSPVZh+tpnnOD2o+Az+DEG6EA6q eLrrowDtQsLfAp/B3wXYOP4qKoeiMHyEvSiMPRFBTx3z/vb9otM5v2Sje2MYr957 EDS9P/wowKCVHOD6g4uihW+OfWwdYphSL4kj9CArPVk3s58zI9UNY/hEvqeepPCG mg4LIZWYA1r8ZipEFiUzLXPb4a4o1XGIKanXCqzUSoQ== 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:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=z5CFm1 341lUdBr1NCFj0PRLOVCAMPoSU9uIJrgw00Cc=; b=j29OXDu1T0IwrnskdSrBV0 4LqUVnuVTcXbgq4FYUpy9ktlAcPd7BGlacjGZ3+brUuDZ7PMh4iFAYHBrHxwnOSk aUcAh2lXiomcZLzqJdVfy7BHaHbLXRkAopJCBiZQHBhVwRDpSJtM9EKoCLtKrTAy +0Ga2D9+fmxZhb5V+CgSFIE6LuYew6OnT49QiUKWdMlrXM6n3EmMh2c2Y/ugXelS zRFjNmZD6ua8rDiRGcaPTcGrT4aFLbpeXw0qllW/KJUqdrjgoePRS8Jv9U2AxAgn HUI6Bs5hATlJNaJFIMvC9pYaglu1wxPhuoqUiUyQHovAO2/IJuS7KRvChIfwlgDg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrjedtgdekvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecukfhppeeiuddrvdduhedrudefjedrudeivdenucfrrghrrghm pehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id B999310310; Fri, 22 Mar 2019 01:13:52 -0400 (EDT) Date: Fri, 22 Mar 2019 14:13:49 +0900 From: Michael Paquier To: Amit Langote Cc: Alvaro Herrera , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Add pg_partition_root to display top-most parent of a partition Message-ID: <20190322051349.GU20192@paquier.xyz> References: <20190322032612.GA323@alvherre.pgsql> <20190322035538.GO20192@paquier.xyz> <06be11a6-fd8d-b68b-1b97-1bafb1d3185c@lab.ntt.co.jp> <20190322041225.GS20192@paquier.xyz> <27e4501a-ae56-94e4-1524-d509f048d61c@lab.ntt.co.jp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="f8lmXUvqnCdFQPaI" Content-Disposition: inline In-Reply-To: <27e4501a-ae56-94e4-1524-d509f048d61c@lab.ntt.co.jp> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --f8lmXUvqnCdFQPaI Content-Type: multipart/mixed; boundary="c6YcJYqqMhegfX14" Content-Disposition: inline --c6YcJYqqMhegfX14 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 22, 2019 at 01:28:19PM +0900, Amit Langote wrote: > It looked fine before, but the new lines added by patch makes it look > wrong/misplaced somehow. Okay, what do you think about the attached then? -- Michael --c6YcJYqqMhegfX14 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="partition-root-fix-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt= /partitionfuncs.c index 98c8ef77f1..17211888dd 100644 --- a/src/backend/utils/adt/partitionfuncs.c +++ b/src/backend/utils/adt/partitionfuncs.c @@ -189,8 +189,16 @@ pg_partition_root(PG_FUNCTION_ARGS) if (!check_rel_can_be_partition(relid)) PG_RETURN_NULL(); =20 - /* Fetch the top-most parent */ + /* fetch the list of ancestors */ ancestors =3D get_partition_ancestors(relid); + + /* + * If the input relation is already the top-most parent, just + * return itself. + */ + if (ancestors =3D=3D NIL) + PG_RETURN_OID(relid); + rootrelid =3D llast_oid(ancestors); list_free(ancestors); =20 diff --git a/src/test/regress/expected/partition_info.out b/src/test/regres= s/expected/partition_info.out index 92aa6abe3f..42b6bc77ca 100644 --- a/src/test/regress/expected/partition_info.out +++ b/src/test/regress/expected/partition_info.out @@ -46,6 +46,31 @@ CREATE TABLE ptif_test2 PARTITION OF ptif_test -- This partitioned table should remain with no partitions. CREATE TABLE ptif_test3 PARTITION OF ptif_test FOR VALUES FROM (200) TO (maxvalue) PARTITION BY list (b); +-- Test pg_partition_root for tables +SELECT pg_partition_root('ptif_test'); + pg_partition_root=20 +------------------- + ptif_test +(1 row) + +SELECT pg_partition_root('ptif_test0'); + pg_partition_root=20 +------------------- + ptif_test +(1 row) + +SELECT pg_partition_root('ptif_test01'); + pg_partition_root=20 +------------------- + ptif_test +(1 row) + +SELECT pg_partition_root('ptif_test3'); + pg_partition_root=20 +------------------- + ptif_test +(1 row) + -- Test index partition tree CREATE INDEX ptif_test_index ON ONLY ptif_test (a); CREATE INDEX ptif_test0_index ON ONLY ptif_test0 (a); @@ -60,6 +85,31 @@ CREATE INDEX ptif_test2_index ON ptif_test2 (a); ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test2_index; CREATE INDEX ptif_test3_index ON ptif_test3 (a); ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test3_index; +-- Test pg_partition_root for indexes +SELECT pg_partition_root('ptif_test_index'); + pg_partition_root=20 +------------------- + ptif_test_index +(1 row) + +SELECT pg_partition_root('ptif_test0_index'); + pg_partition_root=20 +------------------- + ptif_test_index +(1 row) + +SELECT pg_partition_root('ptif_test01_index'); + pg_partition_root=20 +------------------- + ptif_test_index +(1 row) + +SELECT pg_partition_root('ptif_test3_index'); + pg_partition_root=20 +------------------- + ptif_test_index +(1 row) + -- List all tables members of the tree SELECT relid, parentrelid, level, isleaf FROM pg_partition_tree('ptif_test'); diff --git a/src/test/regress/sql/partition_info.sql b/src/test/regress/sql= /partition_info.sql index adaca23232..b5060bec7f 100644 --- a/src/test/regress/sql/partition_info.sql +++ b/src/test/regress/sql/partition_info.sql @@ -22,6 +22,12 @@ CREATE TABLE ptif_test2 PARTITION OF ptif_test CREATE TABLE ptif_test3 PARTITION OF ptif_test FOR VALUES FROM (200) TO (maxvalue) PARTITION BY list (b); =20 +-- Test pg_partition_root for tables +SELECT pg_partition_root('ptif_test'); +SELECT pg_partition_root('ptif_test0'); +SELECT pg_partition_root('ptif_test01'); +SELECT pg_partition_root('ptif_test3'); + -- Test index partition tree CREATE INDEX ptif_test_index ON ONLY ptif_test (a); CREATE INDEX ptif_test0_index ON ONLY ptif_test0 (a); @@ -37,6 +43,12 @@ ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test2_= index; CREATE INDEX ptif_test3_index ON ptif_test3 (a); ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test3_index; =20 +-- Test pg_partition_root for indexes +SELECT pg_partition_root('ptif_test_index'); +SELECT pg_partition_root('ptif_test0_index'); +SELECT pg_partition_root('ptif_test01_index'); +SELECT pg_partition_root('ptif_test3_index'); + -- List all tables members of the tree SELECT relid, parentrelid, level, isleaf FROM pg_partition_tree('ptif_test'); --c6YcJYqqMhegfX14-- --f8lmXUvqnCdFQPaI Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlyUbw0ACgkQnvQgOdby QH2uwxAAphbUiKlCEZALD2WWEN55PbwKemI8ckc5HMkIo6B8JahWgycCWhCzhaC7 S55EhtLx4Fz/3HeuPSE0egpMovd1mKYlGe+s4c1iui9BlOv9JC/DTrS/NBWna3e6 l4YknxX2ex19z7KydgT6yPlETrKST2iu5EiZv7knaSO2hlR4ogdGV1sVWOo6Dv4m 0ugagxQGEDtqgBVyHCpBbZ3lmMDysyumKYbzF/Je3ZVeOyWyxs3eZW4SSjnoDEYR R1tDFy00APMXQb2osvepn09PJvGo4BGvasZlakvs3z9ml8W6pswPXUL9Pwin6/7f OASfD765V63RUicBb9Q8ZmdyDeq1h+WoH7QEggMiGITSFDCizD0JPvclOSxNSNtU O8BfUFkLKKw4aafLytLNM5lVlDBdXJxAoNgO4XVNqe2L2O9pyzdniWgRMc1Pm7Tm CTn+1Fv+7VGH7Jl/qT2f7knc+QNVPQVD4b+WSGh9EsKElEjLTndPF+QwokhZD2Qr hgcw6AEB0dKpzCgIdBOcDx3k3BXVGH78CCVPknEwnxdicNQMbaPyT/l/14zKmUIY WVHsgn/0V/m+w3RL12xV+TymRM28KyBem0aG0w+0HuMyrxhuwFptfQcuoulNRgm2 MXki34i6mEooNEuxDl0BVQVODvuVlbR0ApgEOzKVxV4rv4WKmOE= =JxmK -----END PGP SIGNATURE----- --f8lmXUvqnCdFQPaI--