Re: Slow UPADTE, compared to INSERT

From: Jeff <threshar(at)torgo(dot)978(dot)org>
To: Ivar Zarans <iff(at)alcaron(dot)ee>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow UPADTE, compared to INSERT
Date: 2003-12-04 19:23:20
Message-ID: 20031204142320.3c021100.threshar@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, 4 Dec 2003 20:57:51 +0200
Ivar Zarans <iff(at)alcaron(dot)ee> wrote:
.

> table1 is updated with new value (done). Update statement itself is
> extremely simple: "update table1 set status = 'done' where recid =
> ..."
>
> Most interesting is, that insert takes 0.004 seconds in average, but
> update takes 0.255 seconds in average. Processing of 24000 records
> took around 1 hour 20 minutes.

Do you have an index on recid?

and did you vacuum analyze after you loaded up the data?

>
> Then i changed processing logic not to update every record in table1
> after processing. Instead i did insert recid value into temporary
> table and updated records in table1 after all records were processed
> and inserted into table2:
> UPDATE table1 SET Status = 'done' WHERE recid IN (SELECT recid FROM
> temptable)
>

"IN" queries are terribly slow on versions before 7.4

> Why is UPDATE so slow compared to INSERT? I would expect more or less
> similar performance, or slower on insert since table2 has four indexes
> in addition to primary key, table1 has only primary key, which is used
> on update. Am i doing something wrong or is this normal?
>

Remember, UPDATE has to do all the work of select and more.

And if you have 4 indexes those will also add to the time (Since it has
to update/add them to the tree)

--
Jeff Trout <jeff(at)jefftrout(dot)com>
http://www.jefftrout.com/
http://www.stuarthamm.net/

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Vivek Khera 2003-12-04 19:29:58 Re: autovacuum daemon stops doing work after about an hour
Previous Message Josh Berkus 2003-12-04 19:20:21 Re: tuning questions