D
Deleted member 43669
Guest
Hi all,
Just found out today that if you do:
in Postgres (i.e. complex update based on a select), it tends to be slllllllow. Fortunately, if you replace it with:
It flies.
Should I use Postgres' non-standard FROM in the UPDATE? Is this a flaw of the optimizer? Other thoughts?
(I use the temp table because it's quick and I have several updates to perform which can reuse some temp tables...)
Just found out today that if you do:
Code:
update foo
set bar = (
select {complex_expr} new_bar
from {some_tables}
where {complex_join}
and foo.id = {some_table}.id)
where {condition_goes_here}
in Postgres (i.e. complex update based on a select), it tends to be slllllllow. Fortunately, if you replace it with:
Code:
begin;
create temporary table tmp_table on commit drop as (
select {some_table}.id, {complex_expr} new_bar
from {some_tables}
where {complex_join}
);
update foo
set bar = (
select new_bar
from tmp_table
where foo.id = tmp_table.id)
where {condition_goes_here};
commit;
It flies.
Should I use Postgres' non-standard FROM in the UPDATE? Is this a flaw of the optimizer? Other thoughts?
(I use the temp table because it's quick and I have several updates to perform which can reuse some temp tables...)