From: Andrew Dunstan <andrew@dunslane.net>
To: Marcin Mańk <marcin.mank@gmail.com>
Cc: Reuven M. Lerner <reuven@lerner.co.il>
Cc: pgsql-performance@postgresql.org
Subject: Re: Very long deletion time on a 200 GB database
Date: Thu, 23 Feb 2012 09:25:13 -0500
Message-ID: <4F464C49.4050503@dunslane.net> (raw)
In-Reply-To: <CAK61fk6bSQtmDUzm2rNv33kN4Oar_dYZ-yFEa9zR_zLL8L9esQ@mail.gmail.com>
References: <4F45FB55.1020600@lerner.co.il>
<CAK61fk6bSQtmDUzm2rNv33kN4Oar_dYZ-yFEa9zR_zLL8L9esQ@mail.gmail.com>
On 02/23/2012 05:07 AM, Marcin Mańk wrote:
>> DELETE FROM B
>> WHERE r_id IN (SELECT R.id
>> FROM R, B
>> WHERE r.end_date< (NOW() - (interval '1 day' * 30))
>> AND r.id = b.r_id
>>
> How about:
>
> DELETE FROM B
> WHERE r_id IN (SELECT distinct R.id
> FROM R WHERE r.end_date< (NOW() - (interval '1 day' * 30))
>
> ?
>
Or possibly without the DISTINCT. But I agree that the original query
shouldn't have B in the subquery - that alone could well make it crawl.
What is the distribution of end_dates? It might be worth running this in
several steps, deleting records older than, say, 90 days, 60 days, 30 days.
cheers
andrew
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: andrew@dunslane.net, marcin.mank@gmail.com, reuven@lerner.co.il
Subject: Re: Very long deletion time on a 200 GB database
In-Reply-To: <4F464C49.4050503@dunslane.net>
* 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