Re: EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Gunther <raj(at)gusw(dot)net>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?
Date: 2019-03-22 20:07:19
Message-ID: 20190322200719.GR2952@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, Mar 21, 2019 at 03:31:42PM -0400, Gunther wrote:
> Hi,
>
> I have 250 rows to delete, but they are a target to a bunch of child tables
> with foreign key on delete cascade.
>
> EXPLAIN DELETE FROM Foo WHERE id = (SELECT fooId FROM Garbage);

Probably because:
https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-FK
"Since a DELETE of a row from the referenced table [...] will require a scan of
the referencing table for rows matching the old value, it is often a good idea
to index the referencing columns too."

Can you show "\d+ foo", specifically its FKs ?

Justin

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Pavel Stehule 2019-03-24 05:57:10 Re: [HACKERS] proposal: schema variables
Previous Message Gunther 2019-03-22 20:01:38 Re: EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?