Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZfWtD-0004e2-AO for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2015 17:34:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZfWtC-0002NB-SV for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2015 17:34:30 +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 1ZfWrv-0000ur-7D for pgsql-hackers@postgresql.org; Fri, 25 Sep 2015 17:33:11 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZfWrp-00042e-Qo; Fri, 25 Sep 2015 17:33:09 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [200.104.15.201]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 004F640111D; Fri, 25 Sep 2015 10:32:57 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 483D3D11; Fri, 25 Sep 2015 14:32:54 -0300 (CLT) Date: Fri, 25 Sep 2015 14:32:54 -0300 From: Alvaro Herrera To: Tom Lane Cc: Jan Wieck , Kevin Grittner , pgsql-hackers@postgresql.org Subject: Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references. Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <16320.1442587639@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.6 (--) 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 Tom Lane wrote: > Jan Wieck writes: > > Attached is a complete rework of the fix from scratch, based on Tom's > > suggestion. > > > The code now maintains a double linked list as suggested, but only uses > > it to mark all currently valid entries as invalid when hashvalue == 0. > > If a specific entry is invalidated it performs a hash lookup for maximum > > efficiency in that case. > > That does not work; you're ignoring the possibility of hashvalue > collisions, and for that matter not considering that the hash value > is not equal to the hash key. I don't think your code is invalidating > the right entry at all during a foreign key constraint update, and > it certainly cannot do the right thing if there's a hash value collision. 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. I think the assumption here is that most sessions will not reach the threshold at all, except for those that access all tables such as pg_dump -- that is, most sessions are short-lived. But in cases involved connection poolers, eventually all sessions would access all tables, and thus be subject to the storm issue. (Of course, this is all hypothetical.) -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers