By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,178 Members | 987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,178 IT Pros & Developers. It's quick & easy.

slow down on UPDATE using IN statements

P: n/a
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.

Thanks in advance and
Best regards,

Marcelo Pereira
Brazil

Yahoo! Mail - o melhor webmail do Brasil
http://mail.yahoo.com.br

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In versions 7.3 and before, IN was a dog compared to the equivalent EXISTS
statement. But given your timings, how long has it been since you did a
VACUUM ANALYZE FULL on your database?

Or REINDEX on any of the indexes?

Hope this helps,

On Mon, Nov 03, 2003 at 10:52:44AM -0300, 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.

Thanks in advance and
Best regards,

Marcelo Pereira
Brazil

Yahoo! Mail - o melhor webmail do Brasil
http://mail.yahoo.com.br

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ "All that is needed for the forces of evil to triumph is for enough good
men to do nothing." - Edmond Burke
"The penalty good people pay for not being interested in politics is to be
governed by people worse than themselves." - Plato


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE/pmGyY5Twig3Ge+YRAtg1AJ4miT2uOXTpSxkS+2JIHoZEY7xaZw CeJ/3a
q0Jc8pwJizY2t+mhZr8ycSc=
=Cd9/
-----END PGP SIGNATURE-----

Nov 12 '05 #2

P: n/a
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.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #3

P: n/a


Is the query below any different from what you are trying to accomplish.

UPDATE requisicao SET conclusao='3' WHERE now()-data>'15 days' ;

if you want to use the exact query more efficiently you may rewrite
using EXISTS as

UPDATE requisicao AS a SET conclusao='3' WHERE
EXISTS (select * from requisicao where reg=a.reg and
now()-data>'15 days' ) ;
Best Regards
Mallah.

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.

Thanks in advance and
Best regards,

Marcelo Pereira
Brazil

Yahoo! Mail - o melhor webmail do Brasil
http://mail.yahoo.com.br

---------------------------(end of broadcast)--------------------------- TIP 5: Have you
checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


-----------------------------------------
Over 1,00,000 exporters are waiting for your order! Click below to get
in touch with leading Indian exporters listed in the premier
trade directory Exporters Yellow Pages.
http://www.trade-india.com/dyn/gdh/eyp/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #4

P: n/a


Oops sorry AS is not allowed.
UPDATE requisicao AS a SET conclusao='3' WHERE
EXISTS (select * from requisicao where reg=a.reg and
now()-data>'15 days' ) ;

probably below will work.
UPDATE requisicao SET conclusao='3' WHERE
EXISTS (select * from requisicao as a where reg=requisicao.reg and
now()-data>'15 days' ) ;

Regds
Mallah.

Hi,

Is this right?? Can I use AS on UPDATE???

Regards,

Marcelo

--- ma****@trade-india.com escreveu: >

Is the query below any different from what you are
trying to accomplish.

UPDATE requisicao SET conclusao='3' WHERE
now()-data>'15 days' ;

if you want to use the exact query more efficiently
you may rewrite
using EXISTS as

UPDATE requisicao AS a SET conclusao='3' WHERE
EXISTS (select * from requisicao where reg=a.reg and
now()-data>'15 days' ) ;
Best Regards
Mallah.

> 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.
>
> Thanks in advance and
> Best regards,
>
> Marcelo Pereira
> Brazil
>
> Yahoo! Mail - o melhor webmail do Brasil
> http://mail.yahoo.com.br
>
> ---------------------------(end of

broadcast)--------------------------- TIP 5: Have
you
> checked our extensive FAQ?
>
>

http://www.postgresql.org/docs/faqs/FAQ.html

-----------------------------------------
Over 1,00,000 exporters are waiting for your order!
Click below to get
in touch with leading Indian exporters listed in the
premier
trade directory Exporters Yellow Pages.
http://www.trade-india.com/dyn/gdh/eyp/


Yahoo! Mail - o melhor webmail do Brasil
http://mail.yahoo.com.br


-----------------------------------------
Over 1,00,000 exporters are waiting for your order! Click below to get
in touch with leading Indian exporters listed in the premier
trade directory Exporters Yellow Pages.
http://www.trade-india.com/dyn/gdh/eyp/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.