Re: ATTACH PARTITION cost grows linearly with pg_constraint size (seqscan in CloneFkReferenced), much worse since not-null constraints are in pg_constraint (PG 18)

From: Manu <manuelreyesbravo(at)gmail(dot)com>
To: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Cc: Bernhard Wonisch <bernhard(dot)wonisch(at)gmx(dot)at>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: ATTACH PARTITION cost grows linearly with pg_constraint size (seqscan in CloneFkReferenced), much worse since not-null constraints are in pg_constraint (PG 18)
Date: 2026-09-30 15:42:44
Message-ID: 179078296404.144634.18436236579600890520@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-Sep-29, Álvaro Herrera wrote:

> Makes sense. Please create a commitfest entry for this, if there
> isn't one already.

Done -- it's CF 7365 in PG20-3.

> I think we should explore the idea of adding support for partial
> indexes on catalogs, though. Having an index 90% populated by
> useless entries doesn't sound like the best use of resources.
> Perhaps we could also use such functionality on
> ConstraintRelidTypidNameIndexId, splitting that into two indexes,
> one for constraints on types and another for indexes on relations,
> and avoid having to store InvalidOid on the other column.
> This doesn't have to delay this patch, however.

I'd like to take that up. I spent some time mapping what stands in
the way today, and it comes down to two places:

- The bootstrap index grammar (Boot_DeclareIndexStmt in
bootparse.y) has no WHERE production, so a predicate declared in
the catalog headers reaches genbki but initdb cannot parse it.

- CatalogIndexInsert() asserts ii_Predicate == NIL and never
evaluates a predicate, so even a built index would be maintained
for every row.

The engine side (index_create) already carries ii_Predicate, so the
work looks contained to those two spots rather than the access method
layer.

If that reading matches yours, I can start a separate thread with a
first sketch, using confrelid and the ConstraintRelidTypidNameIndexId
split you mention as the two motivating cases. Happy to hear if
you'd shape it differently.

Manu

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Johannes Edmeier 2026-09-30 15:47:45 Detoast a column once per row instead of once per reference
Previous Message Radim Marek 2026-09-30 15:38:40 Re: REPACK (CONCURRENTLY) might keep dropped-column data