]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix an O(N^2) problem in foreign key references.
authorKevin Grittner <kgrittn@postgresql.org>
Fri, 11 Sep 2015 18:20:30 +0000 (13:20 -0500)
committerKevin Grittner <kgrittn@postgresql.org>
Fri, 11 Sep 2015 18:20:30 +0000 (13:20 -0500)
commit7d0712890d1e18379394cec33b01edb7102928de
treec9dc476375b109ba128899d96c235e3936e75e4a
parent907f3a94f1aa7122f87568455277934e03bb9d92
Fix an O(N^2) problem in foreign key references.

Commit 45ba424f improved foreign key lookups during bulk updates
when the FK value does not change.  When restoring a schema dump
from a database with many (say 100,000) foreign keys, this cache
would grow very big and every ALTER TABLE command was causing an
InvalidateConstraintCacheCallBack(), which uses a sequential hash
table scan.  This could cause a severe performance regression in
restoring a schema dump (including during pg_upgrade).

The patch uses a heuristic method of detecting when the hash table
should be destroyed and recreated.
InvalidateConstraintCacheCallBack() adds the current size of the
hash table to a counter.  When that sum reaches 1,000,000, the hash
table is flushed.  This fixes the regression without noticeable
harm to the bulk update use case.

Jan Wieck
Backpatch to 9.3 where the performance regression was introduced.
src/backend/utils/adt/ri_triggers.c