Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v9B2h-00BYvR-MG for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Oct 2025 23:36:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v9B2g-008qsq-9P for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Oct 2025 23:36:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v9B2g-008qsh-0n for pgsql-bugs@lists.postgresql.org; Wed, 15 Oct 2025 23:36:25 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v9B2d-001z9p-0s for pgsql-bugs@lists.postgresql.org; Wed, 15 Oct 2025 23:36:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 59FNaKoN1334978; Wed, 15 Oct 2025 19:36:20 -0400 From: Tom Lane To: David Rowley cc: Nathan Bossart , andrewbille@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19086: pg_dump --data-only selects and do not uses index definitions for the dumped tables. In-reply-to: References: <19086-871ff11017d03dc5@postgresql.org> <1000041.1760471415@sss.pgh.pa.us> <1324003.1760565328@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Thu, 16 Oct 2025 12:07:24 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1334976.1760571380.1@sss.pgh.pa.us> Date: Wed, 15 Oct 2025 19:36:20 -0400 Message-ID: <1334977.1760571380@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Thu, 16 Oct 2025 at 10:55, Tom Lane wrote: >> I wonder how much win could be had by postponing those function calls >> so that they only act on indexes we're going to dump. It might be >> a net loss in the default dump-everything case, though. > Just to make sure I understand correctly, that means run a query in > dumpIndex() specifically just for the index being dumped to call > pg_get_indexdef()? We could do it like that, but it's probably better to keep the single-query approach. A way that could work is (1) Drop pg_get_indexdef and pg_get_constraintdef from getIndexes' initial query. (2) As we scan the results of that query, build new OID-list strings listing just the index OIDs and constraint OIDs that we require definition strings for. (3) Still within getIndexes, run those queries and insert the results into the arrays built in step 1. On its face, this will be slower than doing it all in one query, at least in the normal case where we need most or all indexes. But what I'm hoping is that we need at most one of the two function calls for any one index, depending on whether it's a constraint or not. That could buy back enough to justify the extra overhead, perhaps. (Hmm ... but on the third hand, if we only need one of the two strings, couldn't we mechanize that by wrapping the pg_get_indexdef call in CASE WHEN c.contype IS DISTINCT FROM 'x' ?) regards, tom lane