Re: select/update performance?

From: Rob Fielding <rob(at)dsvr(dot)net>
To: Bjørn T Johansen <btj(at)havleik(dot)no>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: select/update performance?
Date: 2003-11-05 09:42:26
Message-ID: 3FA8C602.5030005@dsvr.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bjørn T Johansen wrote:
> I need to maintain a manually counter for an id-field, but I can do this
> two ways. Either make a counter table (which means one select and one
> update) or just selecting the largest id from existing table and
> increment by one (just one select + one table lock). Which one is
> fastest?

Is would be better to create a SEQUENCE and simply call nextval on it.
Then you are assured that you'll get a unique sequence when working in a
concurrent environment.

It would also be guaranteed faster than interrogating tables.

Hope this helps,

--

Rob Fielding
Development
Designer Servers Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bjørn T Johansen 2003-11-05 09:49:17 Re: select/update performance?
Previous Message Manfred Koizar 2003-11-05 09:25:29 Re: Help on update that subselects other records in table, uses joins