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 1uDMsq-009mze-8h for pgsql-hackers@arkaria.postgresql.org; Fri, 09 May 2025 12:31:21 +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 1uDMso-00AVZQ-Qy for pgsql-hackers@arkaria.postgresql.org; Fri, 09 May 2025 12:31:18 +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 1uDMso-00AVZC-8J for pgsql-hackers@lists.postgresql.org; Fri, 09 May 2025 12:31:18 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uDMsj-000x4T-32 for pgsql-hackers@postgresql.org; Fri, 09 May 2025 12:31:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1746793872; bh=EvrugWpUAJA6Y9oMghZYV4W5LSuBi9x6R6yXU07Kcxw=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=6TiJIODz6wndbG5h3TwHwF7B2yszqMf4IEE4I+VWqLBEdHX5DuyyIo0qoKRhrJQ63 Wl3+pjwA3SPoNioRuBv0qsMYvCUXFI7kG81SpSuC9y6NaSK6beImYTvNCUCZZN3YwN iemw/YjcT+A38P08FZY6CKBXyY9YIFgd7TAoK3w/MyoD4ppF0BsL/G3VihPf4abDeG 1mn/QIpolOJe2ZkSOQCmUfOVf3BEU+KhM4JUQdimTgxQI4ImJhdmQgIw4Hlc0zhNtD tsGagwsyOG8M5Lx9i5zLI++YluEldlutQvadQqmXNS8tU7WEK9N4eobX+nm4LxKA5Q odrIKx8NzEzKw== Received: from [10.4.12.74] (unknown [93.174.131.141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: a.rybakina@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id C846C60386; Fri, 9 May 2025 15:31:11 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------AOVD9Iagr4x5MTrKfKcg5iOK" Message-ID: Date: Fri, 9 May 2025 15:31:11 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Vacuum statistics To: Andrei Lepikhov , Alexander Korotkov Cc: Ilia Evdokimov , Andrei Zubkov , Alena Rybakina , pgsql-hackers , jian he References: <53c47c2d-72a5-44f2-900c-9973b2af1808@tantorlabs.com> <4a902cea-54fb-41b5-b208-b84731a5f577@postgrespro.ru> <092adec6-4eae-4bd4-bd0d-473a9df1282b@tantorlabs.com> <3deae1bd-ad84-4459-a26e-04c9136b84e9@postgrespro.ru> <631e09ab-099c-4089-883d-4524d852dfa2@gmail.com> Content-Language: en-US From: Alena Rybakina In-Reply-To: <631e09ab-099c-4089-883d-4524d852dfa2@gmail.com> X-KSMG-AntiPhishing: NotDetected, bases: 2025/05/09 11:58:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/05/09 11:08:00 #27966249 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 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. --------------AOVD9Iagr4x5MTrKfKcg5iOK Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi! On 22.04.2025 21:23, Andrei Lepikhov wrote: > On 10/28/24 14:40, Alexander Korotkov wrote: >> On Sun, Aug 25, 2024 at 6:59 PM Alena Rybakina >>> If I missed something or misunderstood, can you explain in more detail? >> >> Actually, I mean why do we need a possibility to return statistics for >> all tables/indexes in one function call?  User anyway is supposed to >> use pg_stat_vacuum_indexes/pg_stat_vacuum_tables view, which do >> function calls one per relation.  I suppose we can get rid of >> possibility to get all the objects in one function call and just >> return a tuple from the functions like other pgstatfuncs.c functions >> do. > I suppose it was designed this way because databases may contain > thousands of tables and indexes - remember, at least, partitions. But > it may be okay to use the SRF_FIRSTCALL_INIT / SRF_RETURN_NEXT API. I > think by registering a prosupport routine predicting cost and rows of > these calls, we may let the planner build adequate plans for queries > involving those stats - people will definitely join it with something > else in the database. > I think we can add this, but first we need to answer the main question - are there cases when we have statistics for a relation that are not in pg_class? After all, we have views that show vacuum statistics for all relations for objects stored in pg_class. +CREATE VIEW pg_stat_vacuum_tables AS ... FROM pg_class rel + JOIN pg_namespace ns ON ns.oid = rel.relnamespace, + LATERAL*pg_stat_get_vacuum_tables(rel.oid)* stats +WHERE rel.relkind = 'r'; I tend to think that such a case will happen because to solve the problem with the memory consumed for storing vacuum statistics, we need to store them separately from the relations' statistics (I already wrote the code here [0]), so the approach with the output of all statistics from a snapshot, as we did here [1] and removed this approach here [2] and this approach now makes sense and it is worth organizing it as you suggest. I can add the code if no one is against it. [0] https://www.postgresql.org/message-id/2a04ad18-5572-4633-848b-eb57209e7ac0%40postgrespro.ru [1] https://www.postgresql.org/message-id/995657bc-9966-47c0-b085-4c5e8886d249%40postgrespro.ru [2] https://www.postgresql.org/message-id/CAPpHfdvSo3mfH%3D2m4ADCHAuN%3D22SnBY3TrPaPbGKTw3r_Jaw7Q%40mail.gmail.com -- Regards, Alena Rybakina Postgres Professional --------------AOVD9Iagr4x5MTrKfKcg5iOK Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi!

On 22.04.2025 21:23, Andrei Lepikhov wrote:
On 10/28/24 14:40, Alexander Korotkov wrote:
On Sun, Aug 25, 2024 at 6:59 PM Alena Rybakina
If I missed something or misunderstood, can you explain in more detail?

Actually, I mean why do we need a possibility to return statistics for
all tables/indexes in one function call?  User anyway is supposed to
use pg_stat_vacuum_indexes/pg_stat_vacuum_tables view, which do
function calls one per relation.  I suppose we can get rid of
possibility to get all the objects in one function call and just
return a tuple from the functions like other pgstatfuncs.c functions
do.
I suppose it was designed this way because databases may contain thousands of tables and indexes - remember, at least, partitions. But it may be okay to use the SRF_FIRSTCALL_INIT / SRF_RETURN_NEXT API. I think by registering a prosupport routine predicting cost and rows of these calls, we may let the planner build adequate plans for queries involving those stats - people will definitely join it with something else in the database.

I think we can add this, but first we need to answer the main question - are there cases when we have statistics for a relation that are not in pg_class? After all, we have views that show vacuum statistics for all relations for objects stored in pg_class.

+CREATE VIEW pg_stat_vacuum_tables AS
...
FROM pg_class rel
+  JOIN pg_namespace ns ON ns.oid = rel.relnamespace,
+  LATERAL pg_stat_get_vacuum_tables(rel.oid) stats
+WHERE rel.relkind = 'r';

I tend to think that such a case will happen because to solve the problem with the memory consumed for storing vacuum statistics, we need to store them separately from the relations' statistics (I already wrote the code here [0]), so
the approach with the output of all statistics from a snapshot, as we did here [1] and removed this approach here [2] and this approach now makes sense and it is worth organizing it as you suggest.

I can add the code if no one is against it.


[0] https://www.postgresql.org/message-id/2a04ad18-5572-4633-848b-eb57209e7ac0%40postgrespro.ru

[1] https://www.postgresql.org/message-id/995657bc-9966-47c0-b085-4c5e8886d249%40postgrespro.ru

[2] https://www.postgresql.org/message-id/CAPpHfdvSo3mfH%3D2m4ADCHAuN%3D22SnBY3TrPaPbGKTw3r_Jaw7Q%40mail.gmail.com

-- 
Regards,
Alena Rybakina
Postgres Professional
--------------AOVD9Iagr4x5MTrKfKcg5iOK--