Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZbsZ6-0004CO-Um for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Sep 2015 15:54:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZbsZ6-00084g-Fs for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Sep 2015 15:54:40 +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 1ZbsZ5-00083b-BP for pgsql-hackers@postgresql.org; Tue, 15 Sep 2015 15:54:39 +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 1ZbsZ2-00056Q-3t; Tue, 15 Sep 2015 15:54:38 +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 t8FFsYc7004717; Tue, 15 Sep 2015 11:54:34 -0400 From: Tom Lane To: Jan Wieck cc: Kevin Grittner , pgsql-hackers@postgresql.org Subject: Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references. In-reply-to: <55F83ABF.2080609@wi3ck.info> 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> Comments: In-reply-to Jan Wieck message dated "Tue, 15 Sep 2015 11:35:27 -0400" Date: Tue, 15 Sep 2015 11:54:34 -0400 Message-ID: <4716.1442332474@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 Jan Wieck writes: > Would it be appropriate to use (Un)RegisterXactCallback() in case of > detecting excessive sequential scanning of that cache and remove all > invalid entries from it at that time? Don't see how unregistering the callback would help? In any case, I'm -1 on this entire concept of "let's zero out the cache at randomly chosen moments". That's far too hard to test the effects of, as we've just seen. It needs to be more predictable, and I think it ought to be more selective too. One idea is to limit the cache to say 1000 entries, and get rid of the least-used one when the threshold is exceeded. We could do that fairly cheaply if we chain the cache entries together in a doubly-linked list (see ilist.h) and move an entry to the front when referenced. For reasonably large cache sizes, that would pretty much guarantee that you weren't destroying an actively-used entry. However, it would still be a bit hard to test, because you could not safely reduce the cache size to just 1 as a test mechanism. Another idea is that it's not the size of the cache that's the problem, it's the cost of finding the entries that need to be invalidated. So we could also consider adding list links that chain only the entries that are currently marked valid. If the list gets too long, we could mark them all invalid and thereby reset the list to nil. This doesn't do anything for the cache's space consumption, but that wasn't what you were worried about anyway was it? 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