Implementation of UPDATE

Started by Diogo Biazusover 23 years ago2 messagesgeneral
Jump to latest
#1Diogo Biazus
diogo@ikono.com.br

Hi folks,

I was wondering if postgres executes a subquery in an UPDATE clause once
and use the result (of the subquery) for all the updates.

Example:
UPDATE table SET field1 = (SELECT field2 FROM table2 WHERE field3 = '123')

Sorry if it seems to be a stupid question, but sometimes this kind of
update is so slow in my server, that makes me suspicious.

TIA

--
Diogo de Oliveira Biazus
diogo@ikono.com.br
Ikono Sistemas e Automa��o
http://www.ikono.com.br

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Diogo Biazus (#1)
Re: Implementation of UPDATE

Diogo Biazus <diogo@ikono.com.br> writes:

I was wondering if postgres executes a subquery in an UPDATE clause once
and use the result (of the subquery) for all the updates.

It should if the subquery is not dependent on any variables of the outer
table. To tell, run EXPLAIN on the query and look to see if you see
"InitPlan" (done once) or "SubPlan" (done each time result is needed).

regards, tom lane