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 1nYq1h-00080F-Bh for pgsql-general@arkaria.postgresql.org; Mon, 28 Mar 2022 14:07:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nYq1f-0007ic-VM for pgsql-general@arkaria.postgresql.org; Mon, 28 Mar 2022 14:07:19 +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 1nYq1f-0007iT-L3 for pgsql-general@lists.postgresql.org; Mon, 28 Mar 2022 14:07:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYq1d-000397-Hq for pgsql-general@postgresql.org; Mon, 28 Mar 2022 14:07:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 22SE76DH704028; Mon, 28 Mar 2022 10:07:07 -0400 From: Tom Lane To: Per Kaminsky cc: Adrian Klaver , "pgsql-general@postgresql.org" Subject: Re: Performance issues on FK Triggers after replacing a primary column In-reply-to: References: <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com> Comments: In-reply-to Per Kaminsky message dated "Mon, 28 Mar 2022 07:22:09 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <704026.1648476426.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 28 Mar 2022 10:07:06 -0400 Message-ID: <704027.1648476426@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Per Kaminsky writes: > # ('Trigger for constraint B_firmid_fkey: time=3D25.592 calls=3D1000',) > # ('Trigger for constraint B_type_fkey: time=3D14.899 calls=3D1000',) > # ('Trigger for constraint B_userid_fkey: time=3D16.146 calls=3D1000',) > # ('Trigger for constraint B_version_fkey: time=3D11.285 calls=3D1000',) > # ('Trigger for constraint B_common_fkey: time=3D7.913 calls=3D1000',) > # ('Trigger for constraint B_shiftinstanceid_fkey: time=3D8543.369 calls= =3D1000',) > ('Trigger for constraint B_to_A_fkey: time=3D27246.413 calls=3D1000',) Sure looks like B_shiftinstanceid_fkey and B_to_A_fkey are running seq scans for lack of any matching index. > 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 = to make a rollback on any problem without causing an abnormal data state r= egarding the program. Hmm, are you dropping and re-adding the reference-side indexes as part of the same transaction that is doing this? I'm too short of caffeine to recall details, but I think there are cases where a newly-made index cannot be used right away. regards, tom lane