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 1mKwvq-00081P-4N for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Aug 2021 06:07:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mKwvo-00050e-W8 for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Aug 2021 06:07:36 +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 1mKwvo-00050S-N7 for pgsql-hackers@lists.postgresql.org; Tue, 31 Aug 2021 06:07:36 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mKwvj-0008Am-BL for pgsql-hackers@lists.postgresql.org; Tue, 31 Aug 2021 06:07:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=vGQxRFZwLAEuBrZr8a+EVDYMX6wiH9qgQvga7obDaWA=; b=B1TQzKOkRdkKfP2O9uLrD0FsOD 9tAn3X25GmRtGLN75EPqyUfmc3BxXYk3D53scy46f53lsjCgjVD4oZJB4E7+ds/+tBZUlNXGqOSio 6vZlsdMkT0wzqFhtv9GoszNWg5CXCBBx4ppFOoYLpGG9GsBTeR0nO2QO+y3oovBHBOj0=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mKwvf-0003Du-JL; Tue, 31 Aug 2021 08:07:27 +0200 Date: Tue, 31 Aug 2021 08:07:27 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Tom Lane Cc: Laurenz Albe , pgsql-hackers@lists.postgresql.org Subject: Re: Can we get rid of repeated queries from pg_dump? Message-ID: <20210831060727.GA32253@depesz.com> Reply-To: depesz@depesz.com References: <20210826084430.GA26282@depesz.com> <648517.1629986527@sss.pgh.pa.us> <20210826140827.GA15868@depesz.com> <649446.1629987629@sss.pgh.pa.us> <20210826160644.GA3120@depesz.com> <896732.1630099403@sss.pgh.pa.us> <1484548.1630368660@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1484548.1630368660@sss.pgh.pa.us> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Aug 30, 2021 at 08:11:00PM -0400, Tom Lane wrote: > [ redirecting to -hackers ] > > I wrote: > > I experimented with the attached, very quick-n-dirty patch to collect > > format_type results during the initial scan of pg_type, instead. On the > > regression database in HEAD, it reduces the number of queries pg_dump > > issues from 3260 to 2905; but I'm having a hard time detecting any net > > performance change. > > I decided that that patch wasn't too safe, because it applies > format_type() to pg_type rows that we have no reason to trust the > longevity of. I think it could fall over if some concurrent process > were busy dropping a temp table, for example. > > So here's a version that just does plain caching of the results > of retail getFormattedTypeName() calls. This visibly adds no > queries that were not done before, so it should be safe enough. > And there can't be any cases that it makes slower, either. Hi, tested it in my case, and it reduced query count to 4261. Which is great. But, I also looked closer into the pg_proc queries and extensions. And - most functions come from relatively standard extensions: - postgis 1246 functions - btree_gist 179 functions - btree_gin 87 functions - hstore 58 functions My point in here is that potential optimizations regarding queries for pg_proc might speed up dumps for more people - as they might use things like postgis, but never realized that it can be much faster. Best regards, depesz