Re: Poor performance for delete query - Mailing list pgsql-performance

From Tom Lane
Subject Re: Poor performance for delete query
Date
Msg-id 28604.1398371340@sss.pgh.pa.us
Whole thread Raw
In response to Poor performance for delete query  (Jonatan Evald Buus <jonatan.buus@cellpointmobile.com>)
Responses Re: Poor performance for delete query
List pgsql-performance
Jonatan Evald Buus <jonatan.buus@cellpointmobile.com> writes:
> We're currently having very poor performance for the following delete query.
> DELETE FROM TopTable WHERE id IN (xx, yy, zz);

> We've observed that it takes around 7 seconds under normal load to for each
> row that's being from TopTable and several minutes pr deleted row under
> heavy load.

I'd really have to bet that you forgot to index one of the referencing
tables.  Are any of the foreign keys multi-column?  If so you probably
need a matching multi-column index, not just indexes on the individual
referencing columns.

> How do we track down the cause of the poorly performing delete query?

EXPLAIN ANALYZE on a DELETE, for starters.  That would isolate whether
it's the DELETE itself or one of the foreign-key updates, and if the
latter which one.  It's a little bit difficult to see the exact plan being
used for a foreign-key update query, but I think one way you could do it
is to enable auto_explain with auto_explain.log_nested_statements turned
on.

            regards, tom lane


pgsql-performance by date:

Previous
From: Sergey Konoplev
Date:
Subject: Re: tsearch2, large data and indexes
Next
From: Jonatan Evald Buus
Date:
Subject: Re: Poor performance for delete query