From: Justin Pryzby <pryzby@telsasoft.com>
To: Gunther <raj@gusw.net>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?
Date: Fri, 22 Mar 2019 15:07:19 -0500
Message-ID: <20190322200719.GR2952@telsasoft.com> (raw)
In-Reply-To: <189c6fff-0180-8179-d059-e222ec83bb1e@gusw.net>
References: <189c6fff-0180-8179-d059-e222ec83bb1e@gusw.net>
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
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: pryzby@telsasoft.com, raj@gusw.net, pgsql-performance@lists.postgresql.org
Subject: Re: EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?
In-Reply-To: <20190322200719.GR2952@telsasoft.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