| From: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Index pg_constraint.confrelid to avoid seqscans |
| Date: | 2026-11-12 14:15:31 |
| Message-ID: | E1xRVaN-00000000Ri2-224M@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Index pg_constraint.confrelid to avoid seqscans
Since commit 14e87ffa5c54 added pg_constraint rows for not-null
constraints, the pg_constraint seqscans in various operations became
slower, sometimes painfully so; pg_upgrade and ATTACH/DETACH PARTITION
have been reported as particularly problematic. This new index should
speed up those operations.
Truncating tables involved in FK relationships also have a seqscan of
pg_constraint, but that's not modified by this patch because fixing that
case (heap_truncate_find_FKs()) is not as straightforward.
This new index, like the ones on conrelid and contypid, has a lot of
useless entries where the indexed column is just zeroes, both bloating
the index and slowing down operations that needn't be slowed down.
Someday it might be nice to avoid indexing those, but that's a larger
patch that requires more discussion.
Author: Manuel Reyes Bravo <manuelreyesbravo(at)gmail(dot)com>
Reported-by: Bernhard Wonisch <bernhard(dot)wonisch(at)gmx(dot)at>
Reported-by: David Rowley <dgrowleyml(at)gmail(dot)com>
Suggested-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Discussion: https://postgr.es/m/trinity-08d3329b-f6b2-4c11-91d7-2198e50bf4fc-1790681922354@trinity-msg-rest-gmx-gmx-live-58cc8f554d-c56lm
Discussion: https://postgr.es/m/1298334.1790896057@sss.pgh.pa.us
Discussion: https://postgr.es/m/CAApHDvpxGcb-_ddd+qL+F=Vmv4d3WZNbUCi3WQyj0HcFnC9v1g@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/b0496e30830b7cee6d17485404dd4c51d7aea286
Modified Files
--------------
src/backend/catalog/heap.c | 5 ++--
src/backend/commands/tablecmds.c | 46 ++++++++++++++++++++++---------------
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_constraint.h | 1 +
4 files changed, 33 insertions(+), 21 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-12 16:06:55 | pgsql: Silence compiler warnings about SOFT_ERROR_OCCURRED usage. |
| Previous Message | Daniel Gustafsson | 2026-11-12 13:32:49 | pgsql: oauth: Apply bgconn timeout per query in 001_server |