From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Jim Vanns <jvanns@ilm.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Tips on troubleshooting slow DELETE (suspect cascades)
Date: Tue, 16 Jan 2024 17:16:14 -0500
Message-ID: <1905752.1705443374@sss.pgh.pa.us> (raw)
In-Reply-To: <566a6359-940c-457e-b4c6-02cdf00f54f0@aklaver.com>
References: <CAH7vdhPg+8+dcp2uCibr2MFPU7LWPJtdvjTY1DOpj0Z3WOhiAw@mail.gmail.com>
<566a6359-940c-457e-b4c6-02cdf00f54f0@aklaver.com>
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 1/16/24 09:45, Jim Vanns wrote:
>> I have a slow (CPU bound) DELETE statement I'm attempting to debug and I
>> suspect that its actually the ON DELETE CASCADE on the foreign key thats
>> causing it.
99% of the time, the cause is lack of an index on the foreign key's
referencing columns. We make you have a unique index on the
referenced columns, because otherwise the FK constraint's semantics
are unclear. But you're not required to make one on the other side.
>> What I need is a way to see into this statement as it executes to
>> confirm my suspicion - does anyone have any tips on that?
> Explain:
> https://www.postgresql.org/docs/current/sql-explain.html
Specifically, if EXPLAIN ANALYZE shows a lot of time spent in the
enforcement trigger for the FK, this is likely what's happening.
regards, tom lane
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: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, jvanns@ilm.com
Subject: Re: Tips on troubleshooting slow DELETE (suspect cascades)
In-Reply-To: <1905752.1705443374@sss.pgh.pa.us>
References: <CAH7vdhPg+8+dcp2uCibr2MFPU7LWPJtdvjTY1DOpj0Z3WOhiAw@mail.gmail.com> <566a6359-940c-457e-b4c6-02cdf00f54f0@aklaver.com> <1905752.1705443374@sss.pgh.pa.us>
* 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