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 1rrmTB-002h13-WB for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Apr 2024 22:19:06 +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 1rrmTB-00ClmQ-5v for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Apr 2024 22:19:05 +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 1rrmTA-00ClmA-SU for pgsql-hackers@lists.postgresql.org; Tue, 02 Apr 2024 22:19:04 +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.94.2) (envelope-from ) id 1rrmT6-000G1T-A4 for pgsql-hackers@lists.postgresql.org; Tue, 02 Apr 2024 22:19:03 +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 432MIrqA1846404; Tue, 2 Apr 2024 18:18:53 -0400 From: Tom Lane To: Jeff Davis cc: Corey Huinker , Magnus Hagander , Stephen Frost , Ashutosh Bapat , Matthias van de Meent , Peter Smith , PostgreSQL Hackers , Tomas Vondra Subject: Re: Statistics Import and Export In-reply-to: <06286ee47fa4b06b6e7f08da21958d7e35525ed4.camel@j-davis.com> References: <54f190b6c757da2a33cce811949e9dd9601fcba7.camel@j-davis.com> <1632327b74a734f8c434eb75e824160d2b06a697.camel@j-davis.com> <16412b8b7ae443cb7470006beff3011927048860.camel@j-davis.com> <1b1bd1ec39ab3de09a17bf7b241021067e5bd63c.camel@j-davis.com> <2bce855db8259c5672a09f863a307ca07b967b68.camel@j-davis.com> <5e94c358caedf2a231dd71624c3578db7227a265.camel@j-davis.com> <718fa933c2c58d0ecc61995ab5c7ca1fe78d6369.camel@j-davis.com> <790773.1711910899@sss.pgh.pa.us> <8bc6ffe1e5abeac0fdde1a83d95409f0463af013.camel@j-davis.com> <1141637.1711994977@sss.pgh.pa.us> <1215956.1711999455@sss.pgh.pa.us> <1321788.1712005745@sss.pgh.pa.us> <1328631.1712008078@sss.pgh.pa.us> <7d37175cd5b56ab04940ed6b5a72354ae90783ee.camel@j-davis.com> <95a34a5131611e1a987a6fe538a! 44! 1c33ca52842.camel@j-davis.com> <1841621.1712093467@sss.pgh.pa.us> <06286ee47fa4b06b6e7f08da21958d7e35525ed4.camel@j-davis.com> Comments: In-reply-to Jeff Davis message dated "Tue, 02 Apr 2024 14:59:12 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1846402.1712096333.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 02 Apr 2024 18:18:53 -0400 Message-ID: <1846403.1712096333@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jeff Davis writes: > We need to get the original element type on the import side somehow, > right? Otherwise it will be hard to tell whether '{1, 2, 3, 4}' has > element type "int4" or "text", which affects the binary representation > of the anyarray value in pg_statistic. Yeah, but that problem exists no matter what. I haven't read enough of the patch to find where it's determining that, but I assume there's code in there to intuit the statistics storage type depending on the table column's data type and the statistics kind. > Either we need to get it at export time (which seems the most reliable > in principle, but problematic for older versions) and pass it as an > argument to pg_set_attribute_stats(); or we need to derive it reliably > from the table schema on the destination side, right? We could not trust the exporting side to tell us the correct answer; for one reason, it might be different across different releases. So "derive it reliably on the destination" is really the only option. I think that it's impossible to do this in the general case, since type-specific typanalyze functions can store pretty nearly whatever they like. However, the pg_stats view isn't going to show nonstandard statistics kinds anyway, so we are going to be lossy for custom statistics kinds. regards, tom lane