pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: andrew@pillette.com
Cc: okparanoid@free.fr
Cc: pgsql-performance@postgresql.org
Subject: Re: update 600000 rows
Date: Sun, 16 Dec 2007 13:52:00 -0500
Message-ID: <b42b73150712161052h5bfade28h1a5043c457a2a6a0@mail.gmail.com> (raw)
In-Reply-To: <200712160521.lBG5Llf25219@pillette.com>
References: <200712160521.lBG5Llf25219@pillette.com>

On Dec 16, 2007 12:21 AM,  <andrew@pillette.com> wrote:
> Loïc Marteau <okparanoid@free.fr> wrote ..
> > Steve Crawford wrote:
> > > If this
> > > is correct, I'd first investigate simply loading the csv data into a
> > > temporary table, creating appropriate indexes, and running a single
> > > query to update your other table.
>
> My experience is that this is MUCH faster. My predecessor in my current position was doing an update from a csv file line by line with perl. That is one reason he is my predecessor. Performance did not justify continuing his contract.
>
> > i can try this. The problem is that i have to make an insert if the
> > update don't have affect a rows (the rows don't exist yet). The number
> > of rows affected by insert is minor regards to the numbers of updated
> > rows and was 0 when i test my script). I can do with a temporary table
> > : update all the possible rows and then insert the rows that are in
> > temporary table and not in the production table with a 'not in'
> > statement. is this a correct way ?
>
> That's what I did at first, but later I found better performance with a TRIGGER on the permanent table that deletes the target of an UPDATE, if any, before the UPDATE. That's what PG does anyway, and now I can do the entire UPDATE in one command.

that's very clever, and probably is the fastest/best way to do it.
you can even temporarily add the trigger a transaction...I am going to
try this out in a couple of things (I currently do these type of
things in two statements) and see how it turns out.

merlin



view thread (9+ messages)  latest in thread

Message-ID: <b42b73150712161052h5bfade28h1a5043c457a2a6a0@mail.gmail.com>
Permalink:  ../b42b73150712161052h5bfade28h1a5043c457a2a6a0@mail.gmail.com/
Also on:    postgresql.org/message-id/b42b73150712161052h5bfade28h1a5043c457a2a6a0@mail.gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mmoncure@gmail.com, andrew@pillette.com, okparanoid@free.fr
  Subject: Re: update 600000 rows
  In-Reply-To: <b42b73150712161052h5bfade28h1a5043c457a2a6a0@mail.gmail.com>
  References: <200712160521.lBG5Llf25219@pillette.com> <b42b73150712161052h5bfade28h1a5043c457a2a6a0@mail.gmail.com>

* 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