Re: slow down on UPDATE using IN statements

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: MaRcElO PeReIrA <gandalf_mp(at)yahoo(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: slow down on UPDATE using IN statements
Date: 2003-11-03 15:28:24
Message-ID: 20031103072543.P13887@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 3 Nov 2003, [iso-8859-1] MaRcElO PeReIrA wrote:

> Hi there,
>
> I was in troubles with a UPDATE+IN statement:
>
> The following command use to take about 5 minutes to
> be done:
>
> UPDATE requisicao SET conclusao='3' WHERE reg IN
> (SELECT reg FROM requisicao WHERE now()-data>'15
> days');
>
> The table 'requisicao' has only about 400 lines (!!).
>
> If I change it to:
>
> UPDATE requisicao SET conclusao='3' WHERE reg IN (12,
> 45, 87, 98, 129, 350, 389);
>
> I have detected that the major problem isn't in the
> amount of lines changed, but in the subselect.
>
> How can I solve/optimize it? I would like to use the
> IN, but in the last case I would make a software
> change.

The easiest is wait for 7.4 where IN optimizes better than it has in the
past and see if that resolves the problem, otherwise, try
changing the query into an exists form.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2003-11-03 15:28:57 Re: insert data of composite type
Previous Message Alexandr S 2003-11-03 15:27:29 question