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: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Manu <manuelreyesbravo(at)gmail(dot)com>
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-29 18:45:31
Message-ID: arv-UHG6c-raryI-@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2026-Sep-29, Manu wrote:

> The third is the "maybe others": grepping Anum_pg_constraint_confrelid
> turns up its else branch, which scans confrelid on SET UNLOGGED and
> whose own comment already noted it had no usable index -- it does now.
> The other two share CloneFkReferenced's shape, so they scan on confrelid
> alone and filter contype in the loop.

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

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.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"La rebeldía es la virtud original del hombre" (Arthur Schopenhauer)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2026-09-29 18:54:31 Re: [PATCH] Add a check_hook for output_plugin_libraries
Previous Message Tom Lane 2026-09-29 18:31:30 Re: Bug in logical decoding with DDL and subtransactions