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 1u0AHy-00D7is-Ef for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Apr 2025 02:26:42 +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 1u0AHw-001vV5-PN for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Apr 2025 02:26:40 +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 1u0AHw-001vSv-6j for pgsql-hackers@lists.postgresql.org; Thu, 03 Apr 2025 02:26:40 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u0AHs-002eey-2r for pgsql-hackers@lists.postgresql.org; Thu, 03 Apr 2025 02:26:39 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-6fece18b3c8so4082627b3.3 for ; Wed, 02 Apr 2025 19:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743647196; x=1744251996; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=13BMWnOYnRESJ7JSfD0XiPjYBPBIoLfXuozklwDZ9l0=; b=eynMYam2pZgp5brdXvlYol/iVb4+crD5179+6BpNH0V5VkSy8hejALkt0S4em1HzYv pfGKFMwWUdDacKjTiirQq5rAJv+yO2TB7KdHZ5S4GU+ojDBdz+aUwOwfi0X39MdDSM3I MGUJbiOj0VVjVbDw61ow/QnXlHpGPv4Myxp9tHeo0Biwf46bN47uhArAbcU7pqKhfGhb aUcB1GWNlaL2r0ZSZ/ZJYPb0NWCd6aimFAJJQH1upvHIBQ94HB17uPp7chDtZibJPfoa xPpviaRhGNmBdz+VswK3AqSyAlpJYqnl4zTJhGrIjIh7HArKsSCyrwv5eLglvh5qSigF zGKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743647196; x=1744251996; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=13BMWnOYnRESJ7JSfD0XiPjYBPBIoLfXuozklwDZ9l0=; b=fd3TRUb8wf7Xo9vYegIvSs86RQv8HrMSeMTS6Q5ZB9jvtkTlFtW4omxF5R5mSsLdW9 oGXZzz0ZRJEPf6Pb0/ETG3OEHOLN6IwNDHFQtOenE50HxuCuK/KPLshNs46f+a/QG2IP yOCWMEBKpvhjNNyVHpDiwDZp6BmFUQOBy/Au0r1Gf0Ns6Dv/taX5/TDcwkaJlDvAj6KF HNKZvBZ3FvezZ2JDUq1dPZY1gGjh8XuXCfT4oOtYVV3HDI+ns2S+P/gsgUwmPr7vDWn4 ErxRcka8+jSY65QJ/tuhKakNW7jKyyFmNVR+iLjSWZdnatxQqARalg5vwDzY7+3J4xQm KMlg== X-Forwarded-Encrypted: i=1; AJvYcCXRw4I1cjDb853uSImeptNfUVjs3i/CR6gWIETFYK/nDEh5YnRpyL1gW0Vgj8DjyKVvFx2LwQEgXNYrajsb@lists.postgresql.org X-Gm-Message-State: AOJu0YzkpsMFAxkZ71vKchd46Nlao04rSAB6YKoWBPw+YQOIkJVezCal 0NKQupKp6PKw1F0teGtdgZtZFnkaeQo7rEUqRS9lYmZF68/dMJAC X-Gm-Gg: ASbGncvoXL1vdWN2q9JIva4bVkf+d0lCFyqRLGQMCTWbQb23WCSQrhQkzoj3ExyfKDH dFOm6u2u5RcNFB9hxEgyI5hDEI8UA+4grRBN6Qs/dLOjBNvNTbXftBAUcFqjHLzz/SY3fkh8FFQ XnLleOA0xUcpVcQ1nu4PKhJ/PQwMTs2LUs4uDfAoihKU4oTA1JE2XWlr68X7j8ln78yQUIB9hki 2SRguzG+QGnTSIPF2JMAjx7UMzkPrL45ZhRNQUdi+7w3E7/gRB7ZuMrsjShgI8DCShpFM3r1NYd /GkuWcA4ydEL8Ntjkv84ukN0gluEiQXbbPMcnTWuhSNygFH9Uu0lSR9p+gk1ihoWvl47FgLZxNp rWR/2ZH9ZTXacMZwixxtw+7b0Y79rkr9mYJlgVl+g6u9sSA== X-Google-Smtp-Source: AGHT+IEKUaZnhInpDt8L6c2/JkUuiTgomxX0PIumDRfei0UY2UCT3YxEGJo62mxoYF3F6Hj3mE4qEQ== X-Received: by 2002:a05:690c:6501:b0:6fb:9280:5bf4 with SMTP id 00721157ae682-70257337694mr256473047b3.30.1743647195577; Wed, 02 Apr 2025 19:26:35 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 00721157ae682-703d1f70600sm1224867b3.79.2025.04.02.19.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Apr 2025 19:26:34 -0700 (PDT) Date: Wed, 2 Apr 2025 21:26:32 -0500 From: Nathan Bossart To: Jeff Davis Cc: Corey Huinker , Robert Treat , Robert Haas , Andres Freund , Tom Lane , Michael Paquier , jian he , Bruce Momjian , Matthias van de Meent , Magnus Hagander , Stephen Frost , Ashutosh Bapat , Peter Smith , PostgreSQL Hackers , alvherre@alvh.no-ip.org Subject: Re: Statistics Import and Export Message-ID: References: <88af35fe0ff24cc4e0700b841aa60a0865f11648.camel@j-davis.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="r7s4R03d6TAiW1f4" 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 --r7s4R03d6TAiW1f4 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, Apr 01, 2025 at 10:44:19PM -0700, Jeff Davis wrote: > On Tue, 2025-04-01 at 22:21 -0500, Nathan Bossart wrote: >> We might be able to improve this by inventing a new callback that fails for >> all formats except for custom with feesko() available.  That would at least >> ensure hard failures if these assumptions change.  That problably wouldn't >> be terribly invasive.  I'm curious what you think. > > That sounds fine, I'd say do that if it feels reasonable, and if the > extra callbacks get too messy, we can just document the assumptions > instead. I did write a version with callbacks, but it felt a bit silly because it is very obviously intended for this one case. So, I removed them in the attached patch set. >> Hm.  One thing we could do is to send the TocEntry to the callback and >> verify that matches the one we were expecting to see next (as set by a >> previous call).  Does that sound like a strong enough check? > > Again, I'd just be practical here and do the check if it feels natural, > and if not, improve the comments so that someone modifying the code > would know where to look. Okay, here is an updated patch set. I did add some verification code, which ended up being a really good idea because it revealed a couple of cases we weren't handling: * Besides custom format calling WriteToc() twice to update the data offsets, tar format calls WriteToc() followed by RestoreArchive() to write restore.sql. I couldn't think of a great way to avoid executing the queries twice in this case, so I settled on allowing it for only that mode. While we don't expect the second set of queries to result in different stats definitions, even if it did, the worst case is that the content of restore.sql (which isn't used by pg_restore) would be different. I noticed some past discussion that seems to suggest that this format might be a candidate for deprecation [0], so I'm not sure it's worth doing anything fancier. * Our batching code assumes that stats entries are dumped in TOC order, which unfortunately wasn't true for formats that use RestoreArchive() for dumping. This is because RestoreArchive() does multiple passes through the TOC and selectively dumps certain entries each time. This is particularly troublesome for index stats and a subset of matview stats; both are in SECTION_POST_DATA, but matview stats that depend on matview data are dumped in RESTORE_PASS_POST_ACL, while all other stats data is dumped in RESTORE_PASS_MAIN. To deal with this, I propose moving all stats entries in SECTION_POST_DATA to RESTORE_PASS_POST_ACL, which ensures that we always dump stats in TOC order. One convenient side effect of this change is that we can revert a decent chunk of commit a0a4601765. It might be possible to do better via smarter lookahead code or a more sophisticated cache, but it's a bit late in the game for that. [0] https://postgr.es/m/20180727015306.fzlo4inv5i3zqr2c%40alap3.anarazel.de -- nathan --r7s4R03d6TAiW1f4 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v12n5-0001-Skip-second-WriteToc-for-custom-format-dumps-w.patch"