Re: Extremely slow DELETE with cascade foreign keys

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Rodrigo Rosenfeld Rosas <rr(dot)rosas(at)gmail(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Extremely slow DELETE with cascade foreign keys
Date: 2017-12-05 16:43:28
Message-ID: 20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Rodrigo Rosenfeld Rosas 2017-12-05 17:00:41 Re: Extremely slow DELETE with cascade foreign keys
Previous Message Tom Lane 2017-12-05 16:27:14 Re: Extremely slow DELETE with cascade foreign keys