Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Jan Wieck <jan(at)wi3ck(dot)info>, Kevin Grittner <kgrittn(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.
Date: 2015-09-25 18:07:50
Message-ID: 16223.1443204470@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

I wrote:
> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
>> Would it make sense to remove the only the few oldest entries, instead
>> of all of them? As is, I think this causes a storm of reloads every
>> once in a while, if the number of FKs in the system is large enough.
>> Maybe on a cache hit we could push the entry to the head of the list,
>> and then remove N entries from the back of the list when the threshold
>> is reached.

> (FWIW, it might take less code to put the recently-used entries at the
> back of the list. Then the loop in InvalidateConstraintCacheCallBack
> could just invalidate/delete entries if either they're targets, or
> the current list length exceeds the threshold.)

Specifically, we could change it as per attached. But this adds some
cycles to the mainline usage of fetching a valid cache entry, so I'd
want to see some evidence that there are use-cases it helps before
applying it.

regards, tom lane

Attachment Content-Type Size
kill-only-oldest-FK-cache-entries.patch text/x-diff 3.7 KB

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2015-09-26 17:08:17 pgsql: Rework the way multixact truncations work.
Previous Message Tom Lane 2015-09-25 17:43:10 Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.

Browse pgsql-hackers by date

  From Date Subject
Next Message Stefan Kaltenbrunner 2015-09-25 18:11:32 upcoming infrastructure changes/OS upgrades on *.postgresql.org
Previous Message Tom Lane 2015-09-25 17:43:10 Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.