From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
Cc: | Jim Vanns <jvanns(at)ilm(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Tips on troubleshooting slow DELETE (suspect cascades) |
Date: | 2024-01-16 22:16:14 |
Message-ID: | 1905752.1705443374@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2024-01-16 22:31:04 | Re: Mimic ALIAS in Postgresql? |
Previous Message | hector vass | 2024-01-16 22:07:16 | Re: Mimic ALIAS in Postgresql? |