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 1pNC2n-0001CU-C1 for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 12:16:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNC2l-0005JA-Jf for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 12:16:51 +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 1pNC2l-0005J1-A5 for pgsql-hackers@lists.postgresql.org; Wed, 01 Feb 2023 12:16:51 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNC2i-0003aQ-QM for pgsql-hackers@lists.postgresql.org; Wed, 01 Feb 2023 12:16:50 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id B4D2E320046E; Wed, 1 Feb 2023 07:16:46 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 01 Feb 2023 07:16:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1675253806; x=1675340206; bh=Z MxwoKmYCoI884OkNOYlLdtj3pCHuueYnyIpKncjGnU=; b=nAA9PxbtBDrzJp/mh aSYNLlxS9pAi7kPILINslgz40X1LFDiEn34Cv/esq8Zq5r00UaaIJg4SLVt3Bv0n Z1YoSpuhwgg40jexiP1yUtac8mq0reVLvUOP9upHnqS8N7Y22rWmUxuVAHydHgtE kw0JRbtGj9KL9vvHrEyGZhuGNLh5zYdNU1YlgIQxs1OIBNDBLJuqsJQS9/HOyW7G EP6C81zhrWPLPwCyNHDmLDBRDHorR2Wh4BbN/xETj6nBUEvCn9fgjkAQE4Qm4W96 Qp1tmWw4J5ZXM6+ikm3uVECEpT+thiC9YO8lkwM3xEOexZC680wtRaJX+de/rxdz G5/3g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudefiedgfeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepgfdtgeelgefgffdtieduudffhfevkefgudefteehgfet hfekvdegjeelhfethedvnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh dpphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Feb 2023 07:16:45 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id D790C9B; Wed, 1 Feb 2023 13:01:26 +0100 (CET) Date: Wed, 1 Feb 2023 13:01:26 +0100 From: Alvaro Herrera To: Ilya Gladyshev Cc: Justin Pryzby , Tomas Vondra , pgsql-hackers@lists.postgresql.org Subject: Re: Progress report of CREATE INDEX for nested partitioned tables Message-ID: <20230201120126.wrkiohouhdohzac5@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hmm, count_leaf_partitions has to scan pg_inherits and do a syscache lookup for every single element therein ... this sounds slow. In one of the callsites, we already have the partition descriptor available. We could just scan partdesc->is_leaf[] and add one for each 'true' value we see there. In the other callsite, we had the table open just a few lines before the place you call count_leaf_partitions. Maybe we can rejigger things by examining its state before closing it: if relkind is not partitioned we know leaf_partitions=0, and only if partitioned we count leaf partitions. I think that would save some work. I also wonder if it's worth writing a bespoke function for counting leaf partitions rather than relying on find_all_inheritors. I think there's probably not much point optimizing it further than that. If there was, then we could think about creating a data representation that we can build for the entire partitioning hierarchy in a single pass with the count of leaf partitions that sit below each specific non-leaf; but I think that's just over-engineering. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "After a quick R of TFM, all I can say is HOLY CR** THAT IS COOL! PostgreSQL was amazing when I first started using it at 7.2, and I'm continually astounded by learning new features and techniques made available by the continuing work of the development team." Berend Tober, http://archives.postgresql.org/pgsql-hackers/2007-08/msg01009.php