pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matteo Beccati <php@beccati.com>
To: Christian Paul B. Cosinas <cpc@cybees.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Deleting Records
Date: Thu, 20 Oct 2005 10:52:29 +0200
Message-ID: <43575ACD.8000206@beccati.com> (raw)
In-Reply-To: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>
References: <002701c5d552$5bc7ea30$1e21100a@ghwk02002147>

Hi,

> What could possibly I do so that I can make this fast?
> 
> Here is the code inside my function:
> 
> 	FOR temp_rec IN SELECT * FROM item_qc_doer LOOP
> 		DELETE FROM qc_session WHERE item_id = temp_rec.item_id;
> 		DELETE FROM item_qc_doer WHERE item_id = temp_rec.item_id;
> 	END LOOP;

Qhat about just using:

DELETE FROM gc_session WHERE item_id IN
	(SELECT item_id FROM item_qc_doer)
DELETE FROM item_qc_doer;

It doesn't make sense to run 2 x 22.000 separate delete statements 
instead that only two...

And... What about using a foreing key?


Best regards
--
Matteo Beccati
http://phpadsnew.com
http://phppgads.com



view thread (6+ messages)  latest in thread

Message-ID: <43575ACD.8000206@beccati.com>
Permalink:  ../43575ACD.8000206@beccati.com/
Also on:    postgresql.org/message-id/43575ACD.8000206@beccati.com

 · 

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: php@beccati.com, cpc@cybees.com
  Subject: Re: Deleting Records
  In-Reply-To: <43575ACD.8000206@beccati.com>

* 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