pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: William Yu <wyu@talisys.com>
To: pgsql-performance@postgresql.org
Subject: Re: Slow UPADTE, compared to INSERT
Date: Thu, 04 Dec 2003 11:59:01 -0800
Message-ID: <bqo3lv$1jdg$1@news.hub.org> (raw)
In-Reply-To: <20031204185751.GA15893@alcaron.ee>
References: <20031204185751.GA15893@alcaron.ee>

Ivar Zarans wrote:
> 
> I am experiencing strange behaviour, where simple UPDATE of one field is
> very slow, compared to INSERT into table with multiple indexes. I have
> two tables - one with raw data records (about 24000), where one field

In Postgres and any other DB that uses MVCC (multi-version concurrency), 
UPDATES will always be slower than INSERTS. With MVCC, what the DB does 
is makes a copy of the record, updates that record and then invalidates 
the previous record. This allows maintains a consistent view for anybody 
who's reading the DB and also avoids the requirement of row locks.

If you have to use UPDATE, make sure (1) your UPDATE WHERE clause is 
properly indexed and (2) you are running ANALYZE/VACUUM periodically so 
the query planner can optimize for your UPDATE statements.




view thread (24+ messages)  latest in thread

Message-ID: <bqo3lv$1jdg$1@news.hub.org>
Permalink:  ../bqo3lv$1jdg$1@news.hub.org/
Also on:    postgresql.org/message-id/bqo3lv$1jdg$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: wyu@talisys.com
  Subject: Re: Slow UPADTE, compared to INSERT
  In-Reply-To: <bqo3lv$1jdg$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox