Re: Deleting orphaned records (not exists is very slow) - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: Deleting orphaned records (not exists is very slow)
Date
Msg-id 297FDC28-6CC4-4A8D-B98A-D42370C16BD8@seespotcode.net
Whole thread Raw
In response to Re: Deleting orphaned records (not exists is very slow)  (Tim Uckun <timuckun@gmail.com>)
List pgsql-general
On Sep 27, 2010, at 23:20 , Tim Uckun wrote:

>> Why are you messing with ctid? Does the table have no key? If not, you should fix that first.
>>
>
> I got the idea from here
>
> http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks

If your table already has a key (some column or combination of columns that is unique per row),
there's really no need to use ctid. The only reason they're using ctid on that page because
they have duplicate rows: the table *doesn't* have a key and they have no other way to specify
rows uniquely. Given you reference an id column, I suspect your your table already has a key,
so you should just use that.

ctid is an implementation detail of PostgreSQL rather than part of the logical design of the
database: it really shouldn't be used unless you absolutely have to.

Anyway, sounds like you got it sussed out. Good luck with straightening out the rest of your data!

Michael Glaesemann
grzm seespotcode net




pgsql-general by date:

Previous
From: Tim Uckun
Date:
Subject: Re: Killing "stuck" queries and preventing queries from getting "stuck"
Next
From: Craig Ringer
Date:
Subject: Re: Preserving order through an inner join