pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Karim Nassar <karim.nassar@acm.org>
To: pgsql-performance@postgresql.org
Subject: Re: Delete query takes exorbitant amount of time
Date: Thu, 24 Mar 2005 18:48:24 -0700
Message-ID: <1111715304.9089.179.camel@k2.cet.nau.edu> (raw)
In-Reply-To: <2630.1111711927@sss.pgh.pa.us>
References: <1111709457.9085.127.camel@k2.cet.nau.edu>
	<2630.1111711927@sss.pgh.pa.us>


On Thu, 2005-03-24 at 19:52 -0500, Tom Lane wrote:
> Karim Nassar <Karim.Nassar@acm.org> writes:
> > Here is the statement:
> 
> > orfs=# explain analyze DELETE FROM int_sensor_meas_type WHERE
> > id_meas_type IN (SELECT * FROM meas_type_ids);
> >                                                          QUERY PLAN 
> >
-----------------------------------------------------------------------------------------------------------------------------
> >  Hash Join  (cost=11.53..42.06 rows=200 width=6) (actual
> > time=1.564..2.840 rows=552 loops=1)
> > ...
> >  Total runtime: 2499616.216 ms
> > (7 rows)
> 
> Notice that the actual join is taking 2.8 ms.  The other ~40 minutes
is
> in operations that we cannot see in this plan, but we can surmise are
ON
> DELETE triggers.

There are no DELETE triggers (that I have created).

> > Where do I go from here?
> 
> Look at what your triggers are doing.  My private bet is that you have
> unindexed foreign keys referencing this table, and so each deletion
> forces a seqscan of some other, evidently very large, table(s).

Almost. I have a large table (6.3 million rows) with a foreign key
reference to this one (which has 749 rows), however it is indexed. 

I deleted the fk, ran the delete, then recreated the foreign key in
about 15 seconds. Thanks!

Problem now is: this referencing table I expect to grow to about 110
million rows in the next 2 months, then by 4 million rows per month
thereafter. I expect that the time for recreating the foreign key will
grow linearly with size.

Is this just the kind of thing I need to watch out for? Any other
suggestions for dealing with tables of this size? What can I do to my
indexes to make them mo' betta?

-- 
Karim Nassar
Department of Computer Science
Box 15600, College of Engineering and Natural Sciences
Northern Arizona University,  Flagstaff, Arizona 86011
Office: (928) 523-5868 -=- Mobile: (928) 699-9221







view thread (60+ messages)  latest in thread

Message-ID: <1111715304.9089.179.camel@k2.cet.nau.edu>
Permalink:  ../1111715304.9089.179.camel@k2.cet.nau.edu/
Also on:    postgresql.org/message-id/1111715304.9089.179.camel@k2.cet.nau.edu

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: karim.nassar@acm.org
  Subject: Re: Delete query takes exorbitant amount of time
  In-Reply-To: <1111715304.9089.179.camel@k2.cet.nau.edu>
  References: <1111709457.9085.127.camel@k2.cet.nau.edu> <2630.1111711927@sss.pgh.pa.us> <1111715304.9089.179.camel@k2.cet.nau.edu>

* 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