slow update - Mailing list pgsql-general

From Janning Vygen
Subject slow update
Date
Msg-id 200207261314.g6QDEcM32601@janning.planwerk6.local
Whole thread Raw
Responses Re: slow update  (Andrew Sullivan <andrew@libertyrms.info>)
List pgsql-general
Hi,

i need to update a table in a database and i already managed it to
copy new data in a temproary table with 'copy' command very quick.

what i have is
CREATE TABLE tmp  (id int4, val1 int4, val2 int4);
CREATE TABLE real (id int4 PRIMARY KEY, val1 int4, val2 int4);

not all id s in real have appropiate values in temp.
now i just want to merge these tables and  i tried:

UPDATE real
   SET val1=(SELECT val1 FROM temp WHERE temp.id = real.id ),
       val2=(SELECT val2 FROM temp WHERE temp.id = real.id )
WHERE  id IN (SELECT temp.id FROM temp);

update is taking very long time. there is an index on real but not on
the columns which i update and theer are no triggers at all.
but there are many, many rows in real.

Can anybody give me a hint to a faster way updating the data??

it looks like a very easy task for the database just to merge to
tables, but maybe its not?

kind regards,
janning

pgsql-general by date:

Previous
From: "Christian H. Stork"
Date:
Subject: Evolving databases (eg deleting columns)
Next
From: Elielson Fontanezi
Date:
Subject: set DateStyle to 'SQL'