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 1nYrV8-0006h9-Ir for pgsql-general@arkaria.postgresql.org; Mon, 28 Mar 2022 15:41:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nYrV7-0006D5-9Q for pgsql-general@arkaria.postgresql.org; Mon, 28 Mar 2022 15:41:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYrV6-0006Cv-3q for pgsql-general@lists.postgresql.org; Mon, 28 Mar 2022 15:41:48 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYrV3-0002wJ-Ix for pgsql-general@postgresql.org; Mon, 28 Mar 2022 15:41:47 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 4B1143201F43; Mon, 28 Mar 2022 11:41:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 28 Mar 2022 11:41:44 -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=mpnB0qKftyv8Tr dbO6vkS4m9oI7LHI9B4xUFDqGtgwQ=; b=DAQX6ZrsjKmLWTqDnbqme1Jlbhij0C ajIagwl9e6Nj/piX/91tnb09uBT7V8zFz9QHmtiEPNjXTwsSkTPjI5fdMgIyLHTe f7jM8AIoxyNJ+E2awYr9NA7cdf1qffux7BVcIayzYyUl2dZxEWKeh3fZ+u6+NFBZ o1at6WDaWtBJMFA9QLVR6FxBO+hRGTO1BIgAIDr6cvgOYwnTylfltFKvkvyuZ5C9 bXFDFUWoQ542X8v5i0Dz5jvHOneizDi3nYF+Jh/zTlpUxdMrSzYegHA95Muw26QA 690OTraO4GOxNSDNrMwl0Xn+221bwXAV4Urokxek9E9QxGBV0KCBXz3w== 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=mpnB0qKftyv8TrdbO6vkS4m9oI7LHI9B4xUFDqGtgwQ=; b=dZfigM39 oFsOFLS8KyjzhxqtVHJePc+b2dJdII2KuzkpNFoLNqUm3HECpycRLyIdwCx+AW7l jYC3olci1Xr1HFlQUivMf1lBDlbCvtrfc2Kr/8aFJCmdjClQGeqP3PIOBXokJh70 s65dHcseBvBPGvUgwFsuvKssw1+fSqt5W8Xxls/hbfjpIq6XhmGqnqD+xaDB8X+V 1v45mQ7ZgvK6mWwov6YiHS3oGXVWQBnn0PE0vOIebyHd7HPrRivZ2ViVzlPlLzKA /OBtR1hzhcKZBOLyTVpDVE8CR6lMNk4JLnFPC1PK4w/jEnAfoXLDCJXTkA2+7wbC P78BYEjv+BBW6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudehjedgleduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpedugfeuleegveffhfegleejhefhtedtgeeileeggfeh fefffeevgeejtdeutefftdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 28 Mar 2022 11:41:43 -0400 (EDT) Message-ID: <733c2f32-e808-9024-2332-b0a972ac0bb0@aklaver.com> Date: Mon, 28 Mar 2022 08:41:42 -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: <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com> 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/28/22 00:22, Per Kaminsky wrote: > Sorry, i forgot to add the following: > > Explain / Analyze for the last "update type on B" call, normally there > the table has million of rows but i removed most of them since otherwise > it would not finish sometime soon: > > ('Update on B (cost=0.00..71.50 rows=1000 width=244) (actual > time=18.015..18.015 rows=0 loops=1)',) > ('  Buffers: shared hit=26141 read=21 dirtied=77 written=54',) > ('  ->  Seq Scan on B (cost=0.00..71.50 rows=1000 width=244) (actual > time=0.102..0.536 rows=1000 loops=1)',) > ('        Filter: ((type IS NULL) AND (firmid = 1))',) > ('        Buffers: shared hit=59',) > ('Planning Time: 0.430 ms',) > # ('Trigger for constraint B_firmid_fkey: time=25.592 calls=1000',) > # ('Trigger for constraint B_type_fkey: time=14.899 calls=1000',) > # ('Trigger for constraint B_userid_fkey: time=16.146 calls=1000',) > # ('Trigger for constraint B_version_fkey: time=11.285 calls=1000',) > # ('Trigger for constraint B_common_fkey: time=7.913 calls=1000',) > # ('Trigger for constraint B_shiftinstanceid_fkey: time=8543.369 > calls=1000',) > ('Trigger for constraint B_to_A_fkey: time=27246.413 calls=1000',) > ('Execution Time: 35884.978 ms',) > > The tables have Index on each other. The vacuum can not be called, since > all those table modifications are part of one big transaction to be able Analyze can be run by itself in the transaction. As Tom said I am not seeing any information about indexes on the tables(s). Also, which one of the tables you showed is the temporary one or was that not shown? > to make a rollback on any problem without causing an abnormal data state > regarding the program. > -- Adrian Klaver adrian.klaver@aklaver.com