Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZfX37-00051f-37 for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2015 17:44:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZfX36-0000Yb-Ks for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2015 17:44:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZfX1o-0007WK-CE for pgsql-hackers@postgresql.org; Fri, 25 Sep 2015 17:43:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZfX1l-0004Fs-QP; Fri, 25 Sep 2015 17:43:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t8PHhAxA014682; Fri, 25 Sep 2015 13:43:11 -0400 From: Tom Lane To: Alvaro Herrera cc: Jan Wieck , Kevin Grittner , pgsql-hackers@postgresql.org Subject: Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references. In-reply-to: <20150925173254.GK295765@alvherre.pgsql> References: <10758.1442239007@sss.pgh.pa.us> <55F81C48.4020009@wi3ck.info> <22834.1442325108@sss.pgh.pa.us> <1935.1442329129@sss.pgh.pa.us> <55F83ABF.2080609@wi3ck.info> <4716.1442332474@sss.pgh.pa.us> <55F84112.8020307@wi3ck.info> <55FB7089.1030702@wi3ck.info> <16320.1442587639@sss.pgh.pa.us> <20150925173254.GK295765@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Fri, 25 Sep 2015 14:32:54 -0300" Date: Fri, 25 Sep 2015 13:43:10 -0400 Message-ID: <14681.1443202990@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Alvaro Herrera 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 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers