pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gunther <raj@gusw.net>
To: 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 16:01:38 -0400
Message-ID: <808a0d1a-9357-6bd7-bfe9-5f401fa48d5a@gusw.net> (raw)
In-Reply-To: <16581.1553203016@sss.pgh.pa.us>
References: <189c6fff-0180-8179-d059-e222ec83bb1e@gusw.net>
	<16581.1553203016@sss.pgh.pa.us>


On 3/21/2019 17:16, Tom Lane wrote:
> Gunther <raj@gusw.net> writes:
>> 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);
>> shows me that it uses the nested loop by Foo_pkey index to find the 250
>> items from Garbage to be deleted.
>> But once that starts, I see HUGE amount of read activity from the
>> tablespace Foo_main that contains the Foo table, and only the Foo table,
>> not the Foo_pkey, not any other index, not any other child table, not
>> even the toast table for Foo is contained in that tablespace (I have the
>> toast table diverted with symlinks to another volume).
> I'm betting you neglected to index the referencing column for one
> or more of the foreign keys involved.  You can get away with that
> as long as you're not concerned with the speed of DELETE ...
>
> 			regards, tom lane

I had the same suspicion. But firstly my schema is generated 
automatically and all foreign keys have the indexes.

But what is even more stunning is that the table where this massive read 
activity happens is the Foo heap table. I verified that by using strace 
where all the massive amounts of reads are on those files for the main 
Foo table. And this doesn't make sense, since any foreign key targets 
its primary key. The foreign keys of the child tables are also indexed 
and there is no io on the volumes that hold these child tables, nor is 
the io on the volume that holds the Foo_pkey.






view thread (4+ messages)  latest in thread

Message-ID: <808a0d1a-9357-6bd7-bfe9-5f401fa48d5a@gusw.net>
Permalink:  ../808a0d1a-9357-6bd7-bfe9-5f401fa48d5a@gusw.net/
Also on:    postgresql.org/message-id/808a0d1a-9357-6bd7-bfe9-5f401fa48d5a@gusw.net

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: 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: <808a0d1a-9357-6bd7-bfe9-5f401fa48d5a@gusw.net>

* 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