From: | Kevin Grittner <kgrittn(at)postgresql(dot)org> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Fix an O(N^2) problem in foreign key references. |
Date: | 2015-09-11 18:23:48 |
Message-ID: | E1ZaSzE-0007q3-2V@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers pgsql-hackers |
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.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/5ddc72887a012f6a8b85707ef27d85c274faf53d
Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 38 ++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2015-09-11 18:32:34 | pgsql: Add missing ReleaseBuffer call in BRIN revmap code |
Previous Message | Robert Haas | 2015-09-11 18:02:06 | pgsql: When trace_lwlocks is used, identify individual lwlocks by name. |
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2015-09-11 18:28:01 | Re: Did we forget to unpin buf in function "revmap_physical_extend" ? |
Previous Message | Robert Haas | 2015-09-11 18:03:26 | Re: Waits monitoring |