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 1tpWnq-007Dsh-KH for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 18:15:38 +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 1tpWno-004MvX-MR for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 18:15:36 +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 1tpWnn-004Mlb-T9 for pgsql-hackers@lists.postgresql.org; Tue, 04 Mar 2025 18:15:36 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpWnl-000xDM-32 for pgsql-hackers@lists.postgresql.org; Tue, 04 Mar 2025 18:15:35 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-22328dca22fso90128675ad.1 for ; Tue, 04 Mar 2025 10:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1741112133; x=1741716933; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=RPR5/gkRFnVQMJMbVsn46mzB6kS1cj5/8xTNdJ4J+00=; b=gZ6LUUlkIXPA8mj+wXPS/yCFf/+dE5kFtiMSor2EwBVI50dk2NPa7AopRe3vZ9HRFk 3hSa96YBr/rCclPreZDU2VB2EV3eKQoWdwY2mGFJw7l2b8eKb7V4tTEzu1oukBsRWTi8 jvPtlxjaU9nhOrp7TyHXjS+QoV8tH717dEcmXm8GXoCmAtk+33LK5VGvKcSQFYE5iAso 2+QI0PT+YO2qLeex91IGU3ViJm7j1u2W5u//U1rH1FJ1hzOXG+H/Amr0MzYMggvJm5Pp rty9gXkpXMQ8Jyp8axLVFqx1+MOIiHs9WC7xi2k1fz+LTwZDoGtMPSiTthyCUaj6uYu2 Emmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741112133; x=1741716933; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RPR5/gkRFnVQMJMbVsn46mzB6kS1cj5/8xTNdJ4J+00=; b=QU6IAQcZE2+c4pOoIPRtigjN+RAF4hwnwcY5U6HX4HOHVNofulg4XJFMh8ST/uoWlj CpZ9j5cqO05CBef3Ine8pSXqvXPHFUqcrZpmHLX/cFTP9nTIG3dSl/QZQb9fkAmaOSnB nNnN0qMHtcybqpAVGWwRdm9gPjKH8Zq1qNeTx9KkyyCgBSJPqaSCdmfHUmLgMhlDZVuQ R/gb2b/0zFCf6KM8h4ZEMM4o8UrxYTAgTyiNGVqNnsuJncGhF7FpJRVp6xxqMHckkerL AUox2VTsvCt1cvBJXDnWmdSVotDLNxcjL2PcuGq2FB4vFmYY5o8zr1kGb91QeyQFR5zw EuZA== X-Forwarded-Encrypted: i=1; AJvYcCVoOan7M8n3GI5eTwCF24RJOiSBAvEGecYBeGRhadVmcfV+DxQXhEMCdBYcViAHsGDVhmQnksnXMkzbH0/1@lists.postgresql.org X-Gm-Message-State: AOJu0YyG2CQel6BakM49vgpVVFri0bKa+0pP1WxEyJmIBGYysGkTiMMt Zo3iWIb0++vy1PKQJBynZbMB3ko0RuM/OSGyxAtfUs/XYo63pDWgB7/IqlsTMQ== X-Gm-Gg: ASbGncv7Bmzp6GZXdh1wPHJWfqSCsVwNyD5E2ygieZUnsJgJ86lc9Jjylf5T9lXUGdy 0geAXjiFGymq6/pU7FpVl2vhjJ+98us5k9wTgEY8Qe5QopM04KcZa+nAj9I4PTCsNJsapzexdwD ooeUm8Wf8V8cQJyNyHV7AF4WoDEwwUrgXnKTYSgPTp09Oqxi4jSYKEd+DOw2vXWk4w6D0jezTi8 XqDyBD9hNu3otZeMFWeDUXcrd6+Aqx3W2cYfuCmLHBwqDseZ3oomtEZUlJ+LHvXlquAh7u8Ewbj 94WafIeMwpmXXksMKTv6EbkwyZDHkdycsp+LCI3ZwfvH++tEo06aUlRdfLHdoKkv00JoJMFfDvM dlmWOxbO/weI= X-Google-Smtp-Source: AGHT+IEluWZ0DlsC2XaFfLNo2sDcA9OZ/S3mwe/rGJjgYsbacsi6S4e5cVk4x0fFm1UNsPYP6109eg== X-Received: by 2002:a17:902:dac4:b0:220:fe51:1aab with SMTP id d9443c01a7336-223f1cf7565mr1990515ad.38.1741112132987; Tue, 04 Mar 2025 10:15:32 -0800 (PST) Received: from jeff-laptop.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223504c5b38sm98276175ad.138.2025.03.04.10.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 10:15:32 -0800 (PST) Message-ID: Subject: Re: Statistics Import and Export: difference in statistics dumped From: Jeff Davis To: Ashutosh Bapat Cc: Corey Huinker , Andres Freund , Tom Lane , Michael Paquier , Nathan Bossart , Bruce Momjian , Matthias van de Meent , Magnus Hagander , Stephen Frost , Peter Smith , PostgreSQL Hackers , Alvaro Herrera , jian he Date: Tue, 04 Mar 2025 10:15:30 -0800 In-Reply-To: References: <97b451228227c555be1a4f79c4a62ddec9a74f06.camel@j-davis.com> <1457469.1740419458@sss.pgh.pa.us> <8d13e4296408c53a93390525d0bcb906cbd13df4.camel@j-davis.com> <768b2a237e892bf1334bdcbb066cdc1bd1368cb2.camel@j-davis.com> <5053263e41692dc2358a642403e9aa6fcda53578.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-03-04 at 10:28 +0530, Ashutosh Bapat wrote: > >=20 > > What solution are you suggesting? The only one that comes to mind > > is > > moving everything to SECTION_POST_DATA, which is possible, but it > > seems > > like a big design change to satisfy a small detail. >=20 > We don't have to do that. We can manage it by making statistics of > index dependent upon the indexes on the table. The index relstats are already dependent on the index definition. If you have a simple database like: CREATE TABLE t(i INT); INSERT INTO t SELECT generate_series(1,10); CREATE INDEX t_idx ON t (i); ANALYZE; and then you dump it, you get: ------- SECTION_PRE_DATA ------- CREATE TABLE public.t ... ------- SECTION_DATA ----------- COPY public.t (i) FROM stdin; ... SELECT * FROM pg_catalog.pg_restore_relation_stats( 'version', '180000'::integer, 'relation', 'public.t'::regclass, 'relpages', '1'::integer, 'reltuples', '10'::real, 'relallvisible', '0'::integer ); ... ------- SECTION_POST_DATA ------ CREATE INDEX t_idx ON public.t USING btree (i); SELECT * FROM pg_catalog.pg_restore_relation_stats( 'version', '180000'::integer, 'relation', 'public.t_idx'::regclass, 'relpages', '2'::integer, 'reltuples', '10'::real, 'relallvisible', '0'::integer ); (section annotations added for clarity) There is no problem with the index relstats, because they are already dependent on the index definition, and will be restored after the CREATE INDEX. The issue is when the table's restored relstats are different from what CREATE INDEX calculates, and then the CREATE INDEX overwrites the table's just-restored relation stats. The easiest way to see this is when restoring with --no-data, because CREATE INDEX will see an empty table and overwrite the table's restored relstats with zeros. If we view this issue as a dependency problem, then we'd have to make the *table relstats* depend on the *index definition*. If a table has any indexes, the relstats would need to go after the last index definition, effectively moving most relstats to SECTION_POST_DATA. The table's attribute stats would not be dependent on the index definition (because CREATE INDEX doesn't touch those), so they could stay in SECTION_DATA. And if the table doesn't have any indexes, then its relstats could also stay in SECTION_DATA. But then we have a mess, so we might as well just put all stats in SECTION_POST_DATA. But I don't see it as a dependency problem. When I look at the above SQL, it reads nicely to me and there's no obvious problem with it.=20 If we want stats to be stable, we need some kind of mode to tell the server not to apply these kind of helpful optimizations, otherwise the issue will resurface in some form no matter what we do with pg_dump. We could invent a new mode, but autovacuum=3Doff seems close enough to me. Regards, Jeff Davis