Quadratic constraint naming for FKs to partitioned tables

Started by Manu8 days ago1 messageshackers
Jump to latest
#1Manu
manuelreyesbravo@gmail.com

Hi Álvaro,

A foreign key that references a table with N partitions makes N(N+1)/2
index probes in ChooseConstraintName(), because the name of each
partition's row is searched from suffix 1 again. With 10,000
partitions, ALTER TABLE ... ADD FOREIGN KEY takes 43 s on master and
2 s with the attached patch. pg_restore pays the same in post-data:
765 billion instructions there on master, 65 billion patched.

The patch keeps the last suffix chosen in addFkRecurseReferenced() and
starts the next search after it, so the names do not change: an oracle
over 3,880 cases gives the same names as master, and a new test pins a
taken name in the middle. DETACH of a referencing partition had the
same cost and is covered; creating or attaching one referenced
partition is still linear per command. The new extern sits next to
the one in Marko's CF 6842, so one of the two will need a small rebase.

Manu

Attachments:

t259283_1
v1-0001-Avoid-quadratic-name-search-for-FKs-to-partitione.patchtext/x-patchDownload+132-23
measurements.txttext/plainDownload
fk-names-measure.py.txttext/plainDownload
fk-names-oracle.py.txttext/plainDownload