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 1ujVLV-008UyV-5s for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Aug 2025 04:01:45 +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 1ujVLU-00DSeL-0t for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Aug 2025 04:01:44 +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 1ujVLT-00DSe6-J4 for pgsql-hackers@lists.postgresql.org; Wed, 06 Aug 2025 04:01:43 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ujVLQ-000yLH-2X for pgsql-hackers@lists.postgresql.org; Wed, 06 Aug 2025 04:01:42 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-30b6bd0a352so2528334fac.1 for ; Tue, 05 Aug 2025 21:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754452900; x=1755057700; darn=lists.postgresql.org; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=lbbliT06TZO99d+Cx1Nq9x7ceyq90WRg+N/eiH3Hw60=; b=CzQ+vr7iYlpVamQDKfhvSFryuy4rfl3m3A6WA1/rr1a9NezMsHPNXp7euLBCkeuXAg BIBTPg7C3/ZslWm07k7rgUSBg70hC+cjQx4jXSifS31DrGxroJ3pcUz3/UbC1OOp+nwR bRIjctWOpTR+ohKQB/9qcNK35DZz9ltRa99uwgMY6MHspBmoOMeknH0UdCQ8qB8fNNDf PKI23auJk9etPm8FxpKCIlIZmJX6LK5DwB5bqEVaIkorzIyBfPAzely4qHk2WJ7Tl2Bg naXv4O0zz3x2Wo8ch053qFEv4RTcLz0+XOpcZfy8+7Ut5YVh50sLI1EKmBtoG9ggASts VAFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754452900; x=1755057700; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=lbbliT06TZO99d+Cx1Nq9x7ceyq90WRg+N/eiH3Hw60=; b=G/AS6cv/O5HQRhmMF+ZVKpVPt12P9BK2xSjw0PvN+leyPmEgUCvNy+hNpsoYleuHeJ w1qETVfO2KlISku31iXMXXROLanhxokFO+1B00/PjW4mPTHAmI3wUR2cn/sUPtUvAIJq YQDwsapLV2m1Z2S4s1WmYd9eyjeLYWAZWVC17rhMC7QYS+ABv09NDUiNknSp8cxuXVbG DGuUNY+4BaMOxUWy0mjgIsL0CyszdhVHTaL8W3cOCLt6k7c3pU0Qwm7pBYNafEe8KmAa w3bfK/O3mk9qsvtmUnuWMfBYd1eNQhA/4YLiYODrzGMTryrYLhiKjm0kPPwWv+/0ZPVF 6s8w== X-Forwarded-Encrypted: i=1; AJvYcCV89d4nrragP9VyLc3wQQhxLSqezgF7AdB5WfcGpPoyZwY/4UQNritOUNHEny0JZU/zHfJwGjB4B+CDG1cx@lists.postgresql.org X-Gm-Message-State: AOJu0YzFLSSZlu2OmgJlg7IjJRelbNAJ2LdPVB8qmhsixdXlkbGeK+hR YQicIqa57ciJ1c1hJeLaXMrnhl7TQIxZvhcDdjRjxPXdN8a2uhrfIkLW X-Gm-Gg: ASbGnctjLQc+3NjukadcvuWdlOQ8oOWCPFDyWB5HFlmOVglDZUryw31kYa3GP/Z+FRH /cWOuTIuWlG+7sTIbYuciitk/ow6VdC3rT52mzxnbvYTFXIToHbpIjy145+usV6yLeQe2MHf5UA WJeipaEGTnTW5F4uSYsXqn0otVS4OFgpuEfT18tGPN3t7ZsA3dXS7xt7K67E+sowHQTRPp7AAUF 1vkwL4hTXhkeKpirpHFYcvtf6O3QJL6OZTgoBEu6Gfe6qVGxBK8PSD0m3SHovgPQKhCYjYHld+d FtwmqmeW9o9F2ct+xp4KTMQysEsc4W+1kqHzyPh5TraCmCSmUBn4f4mhK31tV4/L1RuCY/KMaNV wzUc/Rc9EyIfXo+kiKAEh57K6nweiL8ShLDmupX68edUI X-Google-Smtp-Source: AGHT+IFdlhFJEzIx8io58cok5bWbdf/JuYCm7AzYb8QWV2zPiq77w+9s0T+WwBBtWMetIwZ/vhpf2A== X-Received: by 2002:a05:6871:1cc:b0:30b:ba5e:3472 with SMTP id 586e51a60fabf-30be291137bmr915190fac.12.1754452898776; Tue, 05 Aug 2025 21:01:38 -0700 (PDT) Received: from [172.28.16.225] ([183.177.122.38]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-74303b9aff6sm455769a34.39.2025.08.05.21.01.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Aug 2025 21:01:38 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------jOfq9FkU83D0jQ9rf1S8zx0G" Message-ID: <9c9cb744-b8c7-4d75-acad-595b3faba187@gmail.com> Date: Wed, 6 Aug 2025 14:01:18 +1000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: analyze-in-stages post upgrade questions Content-Language: en-GB To: Fujii Masao Cc: Laurenz Albe , "Zechman, Derek S" , Adrian Klaver , pgsql-hackers@lists.postgresql.org References: <6add2a9a-7cf2-4d1b-8f3e-2e26a7ebe883@aklaver.com> <4d8122febd3007143504e4b6034b4253f7000761.camel@cybertec.at> <08d943a83590308cbb9be594d80b4e19ca80e08e.camel@cybertec.at> <2505eef1-b6aa-4518-baff-861a2e6a507b@gmail.com> <2c1f1834107045dfa8b32417771b56bab0cffc56.camel@cybertec.at> <2cce9851-327a-4b1a-ab8e-531c2f92532b@gmail.com> From: Mircea Cadariu In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------jOfq9FkU83D0jQ9rf1S8zx0G Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, On 30/07/2025 12:49, Fujii Masao wrote: > I've started reviewing the patch since it's marked as ready for committer. Thanks! > Overall, I like the change. But I have one question: should this be treated as > a bug fix that we back-patch to supported branches, or is it more of > an improvement that should only go into master? I reckon it might make sense to back-patch it to previous versions, as users might not upgrade always to the latest version. > Only calculate statistics for use by the optimizer (no vacuum). > + If that option is specified, vacuumdb will also > + process partitioned tables. Without that option, only the partitions > + will be considered, unless a partitioned table is explicitly specified > + with the option. > > This wording seems a bit out of place in the --analyze-only section, > since it also describes the default behavior of vacuumdb without that option. > Wouldn't it make more sense to move that explanation in the --table section? > > For example, we could add something like: > > ------------------ > If no tables are specified with the --table option, vacuumdb will > clean all regular tables and materialized views in the connected > database. If --analyze-only or --analyze-in-stages is also specified, > it will analyze all regular tables, partitioned tables, and > materialized views (but not foreign tables). > ------------------ Yes, agreed. > + /* > + * VACUUMing partitioned tables would be unreasonably expensive, since > + * that entails processing the partitions twice (once as part of the > + * partitioned table, once as tables in their own right) for no > + * benefit. But if we only ANALYZE, collecting statistics for > + * partitioned tables is worth the effort. > + */ > > This is probably true. But isn't the main reason more about aligning with > the behavior of the underlying VACUUM and ANALYZE commands? As the vacuumdb > docs says, "There is no effective difference between vacuuming and analyzing > databases via this utility and via other methods for accessing the server.", > so its default target objects should match: VACUUM skips partitioned tables > by default, while ANALYZE includes them. If that's the case, maybe the comment > should reflect that instead. I see what you mean. From that perspective, I wonder if we even need a comment there at all. > + qr/statement:\s+ANALYZE\s+public\.parent_table/s, > + '--analyze_only updates statistics for partitioned tables'); > > A plain space might be sufficient instead of \s+. > Also, I don't think the backslash before ".parent_table" is necessary. Good catch! Indeed let's simplify that to contain strictly only what's necessary. Kind regards, Mircea Cadariu --------------jOfq9FkU83D0jQ9rf1S8zx0G Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi,

On 30/07/2025 12:49, Fujii Masao wrote:
I've started reviewing the patch since it's marked as ready for committer.
Thanks! 
Overall, I like the change. But I have one question: should this be treated as
a bug fix that we back-patch to supported branches, or is it more of
an improvement that should only go into master?
I reckon it might make sense to back-patch it to previous versions, as users might not upgrade always to the latest version.
         Only calculate statistics for use by the optimizer (no vacuum).
+        If that option is specified, <command>vacuumdb</command> will also
+        process partitioned tables.  Without that option, only the partitions
+        will be considered, unless a partitioned table is explicitly specified
+        with the <option>--table</option> option.

This wording seems a bit out of place in the --analyze-only section,
since it also describes the default behavior of vacuumdb without that option.
Wouldn't it make more sense to move that explanation in the --table section?

For example, we could add something like:

------------------
If no tables are specified with the --table option, vacuumdb will
clean all regular tables and materialized views in the connected
database. If --analyze-only or --analyze-in-stages is also specified,
it will analyze all regular tables, partitioned tables, and
materialized views (but not foreign tables).
------------------
Yes, agreed. 
+ /*
+ * VACUUMing partitioned tables would be unreasonably expensive, since
+ * that entails processing the partitions twice (once as part of the
+ * partitioned table, once as tables in their own right) for no
+ * benefit. But if we only ANALYZE, collecting statistics for
+ * partitioned tables is worth the effort.
+ */

This is probably true. But isn't the main reason more about aligning with
the behavior of the underlying VACUUM and ANALYZE commands? As the vacuumdb
docs says, "There is no effective difference between vacuuming and analyzing
databases via this utility and via other methods for accessing the server.",
so its default target objects should match: VACUUM skips partitioned tables
by default, while ANALYZE includes them. If that's the case, maybe the comment
should reflect that instead.
I see what you mean. From that perspective, I wonder if we even need a comment there at all. 
+ qr/statement:\s+ANALYZE\s+public\.parent_table/s,
+ '--analyze_only updates statistics for partitioned tables');

A plain space might be sufficient instead of \s+.
Also, I don't think the backslash before ".parent_table" is necessary.

Good catch! Indeed let's simplify that to contain strictly only what's necessary.  

Kind regards,

Mircea Cadariu

--------------jOfq9FkU83D0jQ9rf1S8zx0G--