Re: BUG #17942: vacuumdb doesn't populate extended statistics on partitioned tables

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: michael(at)paquier(dot)xyz
Cc: henri(dot)chapelle(at)dbandmore(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17942: vacuumdb doesn't populate extended statistics on partitioned tables
Date: 2023-05-26 09:02:07
Message-ID: 20230526.180207.2066564295031330076.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

At Fri, 26 May 2023 16:49:35 +0900 (JST), Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com> wrote in
> present in the list. Anyway, I don't find a simple way to do that for
> now.

For 12 or later, pg_partition_ancestors() is available. Thus something
like the following query would work.

+WITH inh_children AS
+ (SELECT tc.relid::name, t.nspname FROM
+ (SELECT c.relname, ns.nspname FROM pg_catalog.pg_class c
+ JOIN pg_catalog.pg_namespace ns ON c.relnamespace OPERATOR(pg_catalog.=) ns.oid
+ LEFT JOIN pg_catalog.pg_class t ON c.reltoastrelid OPERATOR(pg_catalog.=) t.oid
+ WHERE c.relkind OPERATOR(pg_catalog.=) 'p') t,
+ LATERAL
+ (SELECT tt.relid, t.nspname
+ FROM pg_catalog.pg_partition_tree(t.relname::text) tt WHERE isleaf) tc)

SELECT c.relname, ns.nspname FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace ns ON c.relnamespace OPERATOR(pg_catalog.=) ns.oid
LEFT JOIN pg_catalog.pg_class t ON c.reltoastrelid OPERATOR(pg_catalog.=) t.oid
WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array['r', 'm', 'p'])
+ AND NOT EXISTS (SELECT * FROM inh_children i WHERE i.relid = c.relname AND i.nspname = ns.nspname)

ORDER BY c.relpages DESC;

The lines prefixed by a '+' removes other than the topmost-parents of trees.

For 11, we need to do the same withouth using the function.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2023-05-26 11:00:01 BUG #17947: Combination of replslots pgstat issues causes error/assertion failure
Previous Message Kyotaro Horiguchi 2023-05-26 07:49:35 Re: BUG #17942: vacuumdb doesn't populate extended statistics on partitioned tables