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 17:43:10
Message-ID: 14681.1443202990@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

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.

Sure, there's room for optimization of that sort, although I think we
could do with some evidence that it's actually helpful. I believe that
under "production" workloads InvalidateConstraintCacheCallBack won't
get called much at all, so the problem's moot.

(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.)

regards, tom lane

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2015-09-25 18:07:50 Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.
Previous Message Alvaro Herrera 2015-09-25 17:32:54 Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-09-25 18:07:50 Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references.
Previous Message Jeff Janes 2015-09-25 17:35:30 Re: No Issue Tracker - Say it Ain't So!