Incomplete Explain for delete

From: Ghislain ROUVIGNAC <ghr(at)sylob(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Incomplete Explain for delete
Date: 2015-06-22 15:47:10
Message-ID: CAH12p1DdCst11O9Adivjd9LJ2v5nr0448vLofja04ioO1BQvKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

I ran into a slow delete issue.

The reason is explained by Tom Lane in
http://www.postgresql.org/message-id/16186.1150464632@sss.pgh.pa.us:

> I was about to ask if you had any. Usually the reason for DELETE being
> slow is that you have foreign key references to (not from) the table and
> the referencing columns aren't indexed. This forces a seqscan search
> of the referencing table for each row deleted :-(
> regards, tom lane

Before adding an index on the referencing column, delete ran for more than
12 hours with no result. Someone finally cancelled it.
After adding the index on the referencing column, delete ran in 6 seconds.

Explain gives me the same plan and same expected cost for both cases:

Explain for slow delete > 12 hours
http://explain.depesz.com/s/v5GH

Explain for Quick delete = 6 seconds
http://explain.depesz.com/s/lN2U

So I think explain needs an improvement as it does not show the real plan
used when running the query.

Instead of displaying:
Delete on uniform (cost=0.000..4,489.270 rows=57,847 width=6)
-> Index Scan using two on uniform (cost=0.000..4,489.270 rows=57,847
width=6)
Index Cond: ((bravo)::text = 'romeo'::text)

It should display something like this
Delete on uniform (cost=0.000..4,489.270 rows=57,847 width=6)
-> Index Scan using two on uniform (cost=0.000..4,489.270 rows=57,847
width=6)
Index Cond: ((bravo)::text = 'romeo'::text)
-> Foreign Keys check
-> Index Scan using ix_ref1 on referencing1 (cost= rows= width=)
Index Cond: ...
-> ...
-> Index Scan using ix_refN on referencingN (cost= rows= width=)
Index Cond: ...

Test environnement:
- Windows 7
- PostgreSQL 9.2

Cordialement,
*Ghislain ROUVIGNAC*
ghr(at)sylob(dot)com
<http://www.sylob.com/>
7 rue Marcel Dassault - Z.A. La Mouline - 81990 Cambon d'Albi - FRANCE
Tel : 05 63 53 08 18 - Fax : 05 63 53 07 42 - www.sylob.com
Entreprise certifiée ISO 9001 version 2008 par Bureau Veritas.
*Retrouvez prochainement SYLOB à l'occasion **du salon du Bourget du 15 au
21 juin - Stand B136 Hall 4 - Pavillon Aerospace Valley.*
*Venez échanger et partager votre expérience lors de la journée clients
Sylob 1, 5 et 9 du 26 juin dans nos locaux de Cambon​​.*
<http://twitter.com/SylobErp> <http://www.google.com/+sylob>
<http://www.viadeo.com/fr/company/sylob-sas>
<http://www.linkedin.com/company/sylob>

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kurt De Cauwsemaecker 2015-06-22 15:56:01 psql -A parameter unalines continued data wrongly
Previous Message Tom Lane 2015-06-22 15:00:26 Re: BUG #13460: ERROR: could not find block containing chunk 0x2930072