pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Extremely slow DELETE with cascade foreign keys
Date: Tue, 5 Dec 2017 13:43:28 -0300
Message-ID: <20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql> (raw)
In-Reply-To: <8f569ed9-fde9-1fe7-4beb-01945009e040@gmail.com>

Rodrigo Rosenfeld Rosas wrote:

> explain analyze delete from field_values where transaction_id=226;
> QUERY PLAN
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
>  Delete on field_values  (cost=0.43..257.93 rows=481 width=6) (actual
> time=367375.805..367375.805 rows=0 loops=1)
>    ->  Index Scan using index_field_values_on_transaction_id on
> field_values  (cost=0.43..257.93 rows=481 width=6) (actual time=0.223..4.216
> rows=651 loops=1)
>          Index Cond: (transaction_id = 226)
>  Planning time: 0.234 ms
>  Execution time: 367375.882 ms
> (5 registros)
> 
> Time: 367377,085 ms (06:07,377)

Normally this is because you lack indexes on the referencing columns, so
the query that scans the table to find the referencing rows is a
seqscan.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




view thread (10+ messages)  latest in thread

Message-ID: <20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql>
Permalink:  ../20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql/
Also on:    postgresql.org/message-id/20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql

 · 

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: alvherre@alvh.no-ip.org, rr.rosas@gmail.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Extremely slow DELETE with cascade foreign keys
  In-Reply-To: <20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql>

* 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