Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYaLe-0001hH-Tp for pgsql-general@arkaria.postgresql.org; Sun, 27 Mar 2022 21:22:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nYaLd-00064A-Qd for pgsql-general@arkaria.postgresql.org; Sun, 27 Mar 2022 21:22:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYaLb-000641-Vl for pgsql-general@lists.postgresql.org; Sun, 27 Mar 2022 21:22:53 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYaLY-00078A-GJ for pgsql-general@postgresql.org; Sun, 27 Mar 2022 21:22:51 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 074235C00DC; Sun, 27 Mar 2022 17:22:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 27 Mar 2022 17:22:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=DPgZoKRKXi7rGF +MHVMhSAigbENlQtG8Z21nqrc9f5g=; b=FkMEbF4rM+lvjDo8ve97onw+GXkFV9 dFC/xZXlDk4JI6QztdS51D2osdcSbnBwGunJ/O4/FE8vjUZKB3KTDi3DXK6eNcFj XcQDwlBFFrMXPQldzOW+YgkUxBVbIxJczh09IYjCKQ6pLH/J/kdRVTy7DCGkD1HD igO7DvwXU/0AA5IqGcitfhe6Lxq+Yd1h98ejTQJVZs9L5aB7B57yENUSNSU7RmWs x2RmfFs4fwXVl7GEDqzwMHF4wqsXUkZrkfBrMHuqnbmv3jCR6K3qlnZK6qcX+nSL Sv+9fqVrnFSMFB/g17GrwYg7vXMirFMgh3KXzghwB/o2ElLC4jMmepYQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=DPgZoKRKXi7rGF+MHVMhSAigbENlQtG8Z21nqrc9f5g=; b=GfI7Ct1T col5LrLsQDdndtiVfKtJwuDfTZilxzg37+NMFi4JjnE4o0Ia3Ktw6UvbxBLGiiNI Gg08QDNKMtZ6CCSgNGHNeFVGDSJK54jnrGMedwu3EkK47SFUHUbhw/Sr05ug0E5T ylQbIIHg/VTJW0Q2gTaeAC98h81C//5MoYhLvVQzE5TylT9X2IVLC7Bpb8/+VDwZ Q+hsh2gvJBwzJo9uNqb5l+vTj/7h8QAdl9cOXu3YecP6Dx6ES/WrrPahwgxezD/m 5yBf4U4BLFRN1zf6xTl5KECKslvR/MLFlTpEOylP+14AE8nWBNXAiFyUWtEwhqzE o1iwXTgVsS1Zrw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudehhedgudeivdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepudfgueelgeevfffhgeeljeehhfettdegieelgefg heefffefveegjedtueetffdtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 27 Mar 2022 17:22:45 -0400 (EDT) Message-ID: <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com> Date: Sun, 27 Mar 2022 14:22:44 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: Performance issues on FK Triggers after replacing a primary column Content-Language: en-US To: Per Kaminsky , "pgsql-general@postgresql.org" References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/27/22 09:30, Per Kaminsky wrote: > Hi there, > > i recently stumbled upon a performance issue which i can't > really understand. > The issue occured when i (roughly) did the following without a commit in > between: > > * Replace the PK column of a table A which has a referencing table B - > I have removed the FK from the referencing tables B and have > recreated them afterwards > * Now following i am working in one of the referencing tables B, > updating columns. This takes an extremely large amount of time. This > means, e.g. updating 1000 rows would now need 35-40 seconds. > * The "explain" tells, that the Foreign Key trigger in B referencing A > causes this mishap. Post the query and the explain. Also have you run vacuum and/or analyze on the tables involved? > * Re-creating the Index in B for the column referencing A does not > cause any performance gain. > * If i again remove the FK to A from B this again shrinks back to some > milliseconds. > > The question is, what does cause the FK trigger to be less performant > than recreating the FK constraint? If executed on 100k or even 1m rows > the operation takes hours or even days. > > Thank you very much. > Sincerely, Per Kaminsky > -- Adrian Klaver adrian.klaver@aklaver.com