Re: [GENERAL] Delete Duplicates with Using - Mailing list pgsql-general

From Igal @ Lucee.org
Subject Re: [GENERAL] Delete Duplicates with Using
Date
Msg-id b9f92384-9582-f06e-6cdc-4a1191317d4b@lucee.org
Whole thread Raw
In response to Re: [GENERAL] Delete Duplicates with Using  ("Igal @ Lucee.org" <igal@lucee.org>)
List pgsql-general
FYI,

On 10/16/2017 8:58 AM, Igal @ Lucee.org wrote:


test=*# with keep as (select max(ctid) as ctid from dubletten group by c1,c2,c3) delete from dubletten where ctid not in (select ctid from keep);


I like this solution, but would using a subquery be much slower than the implicit join of `using`?  My tables are not big in Postgres-standards, so it's probably not an issue, but I'm trying to learn as much as I can about Postgres now that I'm getting ready to move it to production.

I was able to compare the performance on a table with about 350k rows, with duplicates over 7 columns and no indices.

The GROUP BY solution with the subquery (though I was using a simpler version of it without a CTE), was taking over 30 seconds so I killed the request.

I then ran the USING version which completed in 16 seconds and deleted 39 rows.

Best,

Igal Sapir
Lucee Core Developer
Lucee.org

pgsql-general by date:

Previous
From: Seamus Abshere
Date:
Subject: Re: [GENERAL] Non-overlapping updates blocking each other
Next
From: Khalil Khamlichi
Date:
Subject: Re: [GENERAL] time series data