pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Per Kaminsky <per.kaminsky@hawk-intech.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Performance issues on FK Triggers after replacing a primary column
Date: Sun, 27 Mar 2022 14:22:44 -0700
Message-ID: <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com> (raw)
In-Reply-To: <DB8PR09MB3913300D0A5150D499048FA8D81C9@DB8PR09MB3913.eurprd09.prod.outlook.com>
References: <DB8PR09MB3913300D0A5150D499048FA8D81C9@DB8PR09MB3913.eurprd09.prod.outlook.com>

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





view thread (13+ messages)  latest in thread

Message-ID: <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com>
Permalink:  ../8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com/
Also on:    postgresql.org/message-id/8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, per.kaminsky@hawk-intech.com
  Subject: Re: Performance issues on FK Triggers after replacing a primary column
  In-Reply-To: <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com>
  References: <DB8PR09MB3913300D0A5150D499048FA8D81C9@DB8PR09MB3913.eurprd09.prod.outlook.com> <8ed0c2ae-8a35-2628-4b41-68f9cb734297@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox