Re: Deleting orphaned records (not exists is very slow)

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Tim Uckun <timuckun(at)gmail(dot)com>
Cc: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Deleting orphaned records (not exists is very slow)
Date: 2010-09-28 03:56:32
Message-ID: 297FDC28-6CC4-4A8D-B98A-D42370C16BD8@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Satoshi Nagayasu 2010-09-28 04:06:19 Re: ECPG - Some errno definitions don't match to the manual
Previous Message Alvaro Herrera 2010-09-28 03:40:16 Re: ECPG - Some errno definitions don't match to the manual