Re: select/update performance? - Mailing list pgsql-general

From Rob Fielding
Subject Re: select/update performance?
Date
Msg-id 3FA8C602.5030005@dsvr.net
Whole thread Raw
In response to select/update performance?  (Bjørn T Johansen <btj@havleik.no>)
Responses Re: select/update performance?  (Bjørn T Johansen <btj@havleik.no>)
List 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


pgsql-general by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: Help on update that subselects other records in table, uses joins
Next
From: Bjørn T Johansen
Date:
Subject: Re: select/update performance?