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.96) (envelope-from ) id 1vJEGL-00FO9R-2L for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Nov 2025 17:04:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJEGJ-00CzIS-1c for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Nov 2025 17:04:03 +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.96) (envelope-from ) id 1vJEGJ-00CzIJ-0X for pgsql-hackers@lists.postgresql.org; Wed, 12 Nov 2025 17:04:03 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vJEGG-007NYN-2D for pgsql-hackers@lists.postgresql.org; Wed, 12 Nov 2025 17:04:02 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4710022571cso9803765e9.3 for ; Wed, 12 Nov 2025 09:03:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762967038; x=1763571838; 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=KLCN05FaGVV0fo2OLfQP0wGajYhj8p0QvFXC84rJZ2c=; b=h2jeaP9T7gdkrjc88DucssbqgQ1wglSPPppdxeV3OG+HR/HVd4xC11UJJa35x2k2W3 Ns/IfYTYQgjz9My9I6ZBfHbK/lPKEWM2tOTRxAuiYt87ZGK3Pl8hGH1vUSeo7OQCnIuo hC8FsACl+AOBMYneSvF2RTbKvhcmEGAHEVVf3ou6jbnXorOdzpavSfWu9umiWhPjWCYm 3cp55AkLnllsKafGTcjeozmvvYys2xkoZX9EVTMEyGXDa03Y8n3Z5n+iFEfFpwLh/AZ8 ion5re0vLdSTMD1Ac+GMNaL4TtUOv2bkz1u6HpNBL+TTUzm+6oelKiuCfCE+jvvvrwxV vp0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762967038; x=1763571838; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KLCN05FaGVV0fo2OLfQP0wGajYhj8p0QvFXC84rJZ2c=; b=bVYzq0xC4S+hu8RJv0r0VretNCfwHt0XmxIF1ejpkI8lbX5Lyg3hYvAztiWjGInYJO L+A8gTnxU472ikfMsvtQmQ294b/NgCxgkkiv2L/RVw5G4mGqgIVhXAfOeCRruAYy0xIa wVE0XLy42HksMw1FTQ9vRCdYAdOYNs2MiKEghGBpZOkgdc61XETlAsByuztrwL6XKyl0 UCj1HUJcnXqTmK25qaO9uEpahebrHrFrXYBjzQeMJsMk7oJqpBRQRmDrrHuihZdxg1oH Qxky6XbZPNXai6Q0n3/Z+BphoTzWCG40e5nzGt18gkhfR934kI39oeAH8A0OPs0UGAVM SZEA== X-Forwarded-Encrypted: i=1; AJvYcCVcJozKy8dAfMg6aICDLQJtsvgm6YXbUKPuL7faiFbHx5TjzodDJ6lyLf9JC9kb3MZdxA1rOEAhREcOYGpN@lists.postgresql.org X-Gm-Message-State: AOJu0YybuZJvbIVsEhtqEIRuWBTr88CENrkam7pzD4y75ea/0kd7Iteb aBvbz3YnuCmcpesDO7wPhjD6tsI+BeysrFqGr3rt/4jLaMb4ZpQ79jLd X-Gm-Gg: ASbGncsAidqzDKaQ6KeJZhyLV+j5UIS5mRkaUKxB050yX1RrsMgaqhADG5TAUNEVD32 K71H1lbFkVeM3AO0X4cxEQls7LphUAktA82/gla8KbapXZs8U7avB1YIxDmglel2Hi2paPSUgBv K4nq8W3NNZG7zR5JWrKt03zh85xTyhdJeED/dHKQlQogqOf9RQIefI58vVZ81D5SGDpvrWGTvt2 fbLdqzrRNIXtJffdAveeObArm+AFAQsdy0sFLDeoOnzUZwZnRTSeZLPPUruwzsUCCLzaa/e9N2M TAWo21Rehi9Fw2vnG5KcG42o1QWZcL0chLRjpQ54TRe3AR7gumNsiHrwsccXJ36aMyiFOPJnIFd 7rDPMvbqbbhTrJclOWmgO+HxQhdP/4HC4PpI5MMsLwRX9NZ+831+QFjOjjZxO/RSW0AQ92wXYn8 cXhZD0on6zEShaju4DOKiGSvvLMnItpOm/3qOIVCCBP6bmfs9/ilCuZ5uX3/6x2lMcJWN/FVGnG rKaTA1EMKvJucpbUxGAxP0fWbfPdRvATPk= X-Google-Smtp-Source: AGHT+IGXtc9SZuuMqn4i4awRLqXDZbx6kvHsdu6pB+hRldZRlrebtEeWHjIdanQkkKjsarxqoa/ouw== X-Received: by 2002:a05:600c:1993:b0:475:dd04:1289 with SMTP id 5b1f17b1804b1-477870c535dmr32503515e9.20.1762967037525; Wed, 12 Nov 2025 09:03:57 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47787daab63sm49248185e9.0.2025.11.12.09.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 09:03:57 -0800 (PST) Date: Wed, 12 Nov 2025 17:03:55 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Kirill Reshke , Robert Haas , pgsql-hackers@lists.postgresql.org Subject: Re: relfilenode statistics Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Mon, Nov 10, 2025 at 05:53:45PM +0900, Michael Paquier wrote: > On Sun, Nov 09, 2025 at 08:33:54AM +0900, Michael Paquier wrote: > > Looking at this part of the patch set for now, not looked at the rest > > yet. This new stats_1.out is 2k lines long, introduced for the tests > > related to rewrites as an effect of 2PC. It seems to me that a split > > into a new stats_rewrite would be justified for this case, to reduce > > the output duplication. > > did a split into a new file, which should also be fine because we > don't rely on a system-wide stats reset, then applied the result. Thanks! > The patch is spending a great deal of effort on three fronts: > - making sure that the statistics are copied over after a relation > rewrite. Right, in 0003. > - making sure that we assign a "correct" object ID, assigning > the fields of RelFileLocator based on a relation ID. Mapped and > shared relations make the exercise a bit more difficult. It would be > nice to avoid this kind of duplication with other code paths that > assign a RelFileLocator. Are you referring to the new pgstat_reloid_to_relfilelocator() function? If so, I'll try to avoid code duplication with other code paths as suggested. > - Partitioned tables, where we don't have a relfilenode but we need to > track statistics. The patch relies on the relation oid to assign a > key, as far as I've read. Right. It's not doing that much in this area. It's needed so that things like "last_analyze" on a partitioned table is populated (see "Ensure only the partitioned table is analyzed" in vacuum.sql). > Among the three points, the first one is the most invasive in the > patch, it seems, and do we actually want to keep the stats across > rewrites at all? Not doing so would mean that all stats related to a relation will be lost after a rewrite. I think that would be a major regression as compared to the current behavior. > The main reason of doing the relfilenode move > would be to rebuild these stats on a WAL-record basis because the > relfile locator is the only thing we know in the startup process, and > once rewritten the state of the data is different. > relation_needs_vacanalyze() then cares about three fields: > - Number of dead tuples, which would be 0 after a rewrite. > - ins_since_vacuum, which would be 0 after a rewrite. > - mod_since_analyze, for analyze, again 0. > > I have not checked the recent autovacuum scheduling thread to see if > this set changes there. > > Are these numbers worth the effort of copying over at the end? I think so because that would impact all the other relation's stats (not only the ones linked to relation_needs_vacanalyze()). > Was > this particular point discussed? I've seen this mentioned once here, > but I am wondering what are the arguments in favor of copying the > stats data versus not copying it across rewrites: > https://www.postgresql.org/message-id/20240607031736.7izmr2yirznvidka%40awork3.anarazel.de In favor of copying, I would say: - no regression as compared to the current behavior. That means, for example, not breaking DBA's activities/decisions based on the pg_stat_all_tables fields after a rewrite. - a rewrite is not changing the number of dead tuples, ins_since_vacuum and mod_since_analyze. So, if don't copy those, then we'd change the relation_needs_vacanalyze() decision(s) as compared to the current one(s) for no reasons (as a rewrite has no impact on those). In favor of not copying, I would say make the code simpler. I'm in favor of copying but open to different point of views. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com