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 1tzofv-00758M-Qs for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Apr 2025 03:22:00 +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 1tzofs-009JxX-Fk for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Apr 2025 03:21:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzofs-009JxP-1c for pgsql-hackers@lists.postgresql.org; Wed, 02 Apr 2025 03:21:56 +0000 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tzofm-002t2B-1H for pgsql-hackers@lists.postgresql.org; Wed, 02 Apr 2025 03:21:55 +0000 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-6ff1e375a47so56836627b3.1 for ; Tue, 01 Apr 2025 20:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743564108; x=1744168908; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=s0lcWmqlpmC6oQqrqH6O2pYTH0EkXTuSDjdKn0KIcPE=; b=Qa+SpfjwG2p85mEaZZFffS/CuiHf6lBUFRDoV+LVq1DXIuBbhRXdVO4s8zsDtM5e/z IjsSXiGFebfLcBWZYdNv+t9WfjLoUptjdmSVzb6SpTc73ndtpKQRAqOIJ2QRhoOQrl99 iTqtBxe2yh0AI8a4hRtoFUzU0KtV3yDoDcQ610wsz+UnYP2aCiz63x9f4nO0gYAQgTHg hwRzkfg2ytxX2hZaoM1C2s6M9t1AQQpR9vwg5fCaJ4Vn66ZeFs+qtDupMszJSCb+blts usmBbiy/c3AeJQp0YOhEyYITIXWFUZ2kJxW5l5V7k8S4JdpgPCSBOLGZlR8R25DQhC4J j/lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743564108; x=1744168908; h=in-reply-to: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=s0lcWmqlpmC6oQqrqH6O2pYTH0EkXTuSDjdKn0KIcPE=; b=NrFY4GJvtXRMUfwCEvsDmIZq40JzfEkEXSmppHDXSBNJXaRm+157/vqwfXzWecwWuM T8vQBxbodo2W9Z4m4fsUX62JSdDO6DRI+VQVXEsX5DjmU0l5AYHtAO72BzDpsXgz+8mm zHDsR+UzW0jEkIbUVSlz6MsrqDC5KJzTAp2PLVy5MGDS6W+K/vDhmpbht8XeCpa4fFCV xFNtCyw6+7lMegOFwqNsknSteEcy2kvZxkqdB6qbh3prAP6rCfrg8txH3gdOb05DuDrT +gx4aD6qSNpwA0KLEcNfbuHdVFcZEKE1PcVZVkzS8xAjJ9TNLD8mJ1MaK5oib9bBLB/I j7RQ== X-Forwarded-Encrypted: i=1; AJvYcCWIv1REFi44cGqCMVJ6lJpWVMDBXkytAbkUUFYOtYbisiNqWrtEKNPhCLAu+hm0VWb4H1YJOQyz+j8bHSi7@lists.postgresql.org X-Gm-Message-State: AOJu0YwdKwtYE5QAYKpD54+/8UfNS+Xchp3EhDQXPrYVylO0KUjaNMsJ aQTIHpV2UMnrLqzFwCd3nBBwFiVwaYzgeBEnUzJjjjHzIXV/eHLb X-Gm-Gg: ASbGncswLF+ThGtbNs2IAwiidv8JH8MdWxdKTgLjDU/GSi9eBY8ZdV7M9wNPOhJb1xi G+c0r3HhJtUK9qpv/7cTcBDsj+Q1R3UCy/squ2XixGlJn3chYKJX8rP4V/7IQ2Jc7h+io/ASyTe dVrCQxkJA5BwghDClsnCCtfhDq5XDBumdukPTsVfzdUbll9py9tOhUHCVLA9wOPRSxCX9yUOC5D rTio39tSVNCJEy9kaMS6Sh553uAEWgl5FQ2kqfmcKU9vH0sgw0DsMaVI0NZbEAYhiGPR/3wTJQm 6kf1b5qhQDycoa0SEBSbSpNq2GEgnmkS6OR2NLSPDtEHmH1JBQTUuZyzNWAhwm16dIX7JY4fEA7 eedA+esXU2rCJK/bsdboxH1YlRmYrpONFgnk= X-Google-Smtp-Source: AGHT+IGgAHje+ikHm2NCs4RKrHqq8Nrma+ERYGXWBMZjyWeW7LWiM19ftE9tIP8M4936i6HwrSCkkQ== X-Received: by 2002:a81:fa09:0:b0:703:ac44:d379 with SMTP id 00721157ae682-703ac44fb01mr51359417b3.22.1743564108140; Tue, 01 Apr 2025 20:21:48 -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-7023a9fea69sm30552637b3.112.2025.04.01.20.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Apr 2025 20:21:47 -0700 (PDT) Date: Tue, 1 Apr 2025 22:21:44 -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="nfxxzXxr01r2a0nb" Content-Disposition: inline In-Reply-To: <88af35fe0ff24cc4e0700b841aa60a0865f11648.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --nfxxzXxr01r2a0nb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Apr 01, 2025 at 03:05:59PM -0700, Jeff Davis wrote: > To restate the problem: one of the problems being solved here is that > the existing code for custom-format dumps calls WriteToc twice. That > was not a big problem before this patch, when the contents of the > entries was easily accessible in memory. But the point of 0002 is to > avoid keeping all of the stats in memory at once, because that causes > bloat; and instead to query it on demand. > > In theory, we could fix the pre-existing code by making the second pass > able to jump over the other contents of the entry and just update the > data offsets. But that seems invasive, at least to do it properly. > > 0001 sidesteps the problem by skipping the second pass if data's not > being dumped (because there are no offsets that need updating). The > worst case is when there are a lot of objects with a small amount of > data. But that's a worst case for stats in general, so I don't think > that needs to be solved here. > > Issuing the stats queries twice is not great, though. If there's any > non-deterministic output in the query, that could lead to strangeness. > How bad can that be? If the results change in some way that looks > benign, but changes the length of the definition string, can it lead to > corruption of a ToC entry? I'm not saying there's a problem, but trying > to understand the risk of future problems. It certainly feels risky. I was able to avoid executing the queries twice in all cases by saving the definition length in the TOC entry and skipping that many bytes the second time round. That's simple enough, but it relies on various assumptions such as fseeko() being available (IIUC the file will only be open for writing so we cannot fall back on fread()) and WriteStr() returning an accurate value (which I'm skeptical of because some formats compress this data). But AFAICT custom format is the only format that does a second WriteToc() pass at the moment, and it only does so when fseeko() is usable. Plus, custom format doesn't appear to compress anything written via WriteStr(). 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. > For 0003, it makes an assumption about the way the scan happens in > WriteToc(). Can you add some additional sanity checks to verify that > something doesn't happen in a different order than we expect? 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? FWIW the pg_dump tests failed miserably until Corey and I got this part right, so our usual tests should also offer some assurance. > Also, why do we need the clause "WHERE s.tablename = ANY($2)"? Isn't > that already implied by "JOIN unnest($1, $2) ... s.tablename = > u.tablename"? Good question. Corey, do you recall why this was needed? -- nathan --nfxxzXxr01r2a0nb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v12n4-0001-Skip-second-WriteToc-for-custom-format-dumps-w.patch"