slow update

From: Janning Vygen <vygen(at)gmx(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: slow update
Date: 2002-07-26 13:14:37
Message-ID: 200207261314.g6QDEcM32601@janning.planwerk6.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Philipp Leibfried 2002-07-26 13:15:55 Transaction context switching?
Previous Message Scott Gammans 2002-07-26 13:06:53 Is there any such thing as PostgreSQL security on a hosted website?