Skip site navigation (1) Skip section navigation (2)

Re: Delete performance

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Phillip Sitbon <phillip(at)sitbon(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Delete performance
Date: 2009-06-15 18:46:52
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Phillip Sitbon <phillip(at)sitbon(dot)net> writes:
> I've had to do this quite a bit, and here's how I usually go about it:

> DELETE FROM data_structures_items WHERE NOT EXISTS
>   (SELECT 1 FROM data_structures WHERE id_structure=id_data_structure LIMIT 1);

> Even when the item in the subquery is a primary key, I find it
> semantically informative to always use "LIMIT 1".

EXISTS implies LIMIT 1 for its subquery; there's no value for either
comprehension or performance in adding that.  I'd recommend leaving
it off, because it makes your query syntax nonstandard for no benefit.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: TimDate: 2009-06-16 01:08:46
Subject: Fwd: Yum Update Errors
Previous:From: Phillip SitbonDate: 2009-06-15 18:34:40
Subject: Re: Delete performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group