Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZfTsx-0004Zi-Pn for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2015 14:22:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZfTsx-0001VC-Bj for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2015 14:22:03 +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 1ZfTrc-0006zY-7n for pgsql-hackers@postgresql.org; Fri, 25 Sep 2015 14:20:40 +0000 Received: from mail-qg0-f47.google.com ([209.85.192.47]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZfTrV-0000Jv-Qr for pgsql-hackers@postgresql.org; Fri, 25 Sep 2015 14:20:39 +0000 Received: by qgt47 with SMTP id 47so70192547qgt.2 for ; Fri, 25 Sep 2015 07:20:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=wruXY0W13126ht4sNkBn/alErpwIaCKHTe4YsjXxQpQ=; b=fmCu7KutG3CFP3Mc/r4KD0+y8wUrM38uBu9blD7EcW2pFFQ7hIvP2QwmSCBnjUEoKy ZVn2AIEYblw6Ji/WJHSlI2yCh9gGPPUiDKnG1UFwOADdPQe+h7+6lm7HTtBAspRqTeCq btPQbK24EIQ8BWiI7JOs3c/0Mpq4ESfiijlzVhV1Gk79RyanionySHDb6MWIvsNgC/jS czG+x1Q1OUUlZkmvad4pwaa3S+eyiUhuLfKdxRIWFXis2lMKgcP7f1E49d7bZu9GVsCX RFuF5RlSb2bcwkT93jeGP9558/CsW1cXuJnl8Tzrct0FEu2np4z33Ls9LNJhtWoEORoo aN9Q== X-Gm-Message-State: ALoCoQnCR81AvFMq52HKBm7jjBOt6C9J7k1QVV0ixu/U+J03laekk0C8YLzcFyQbjfRkyFrQih+v X-Received: by 10.140.231.76 with SMTP id b73mr6912189qhc.87.1443190831874; Fri, 25 Sep 2015 07:20:31 -0700 (PDT) Received: from jupiter.onmars.janwieck.no-ip.info (pool-173-49-130-135.phlapa.fios.verizon.net. [173.49.130.135]) by smtp.googlemail.com with ESMTPSA id l8sm1488420qge.31.2015.09.25.07.20.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Sep 2015 07:20:31 -0700 (PDT) Subject: Re: [COMMITTERS] pgsql: Fix an O(N^2) problem in foreign key references. To: Tom Lane 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> Cc: Kevin Grittner , pgsql-hackers@postgresql.org From: Jan Wieck Message-ID: <5605582E.1010209@wi3ck.info> Date: Fri, 25 Sep 2015 10:20:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <16320.1442587639@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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 On 09/18/2015 10:47 AM, 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. > > Attached is something closer to what I was envisioning; can you do > performance testing on it? Sorry for the delay. Yes, that patch also has the desired performance for restoring a schema with hundreds of thousands of foreign key constraints. Regards, Jan -- Jan Wieck Senior Software Engineer http://slony.info -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers