Re: SELECT FOR UPDATE performance is bad

From: Christopher Kings-Lynne <chris(dot)kings-lynne(at)calorieking(dot)com>
To: PFC <lists(at)peufeu(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, mario(dot)splivalo(at)mobart(dot)hr, pgsql-performance(at)postgresql(dot)org
Subject: Re: SELECT FOR UPDATE performance is bad
Date: 2006-04-19 02:21:35
Message-ID: 44459EAF.2030601@calorieking.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> Suppose you have a table codes :
> (
> game_id INT,
> code TEXT,
> used BOOL NOT NULL DEFAULT 'f',
> prize ...
> ...
> PRIMARY KEY (game_id, code)
> )
>
> Just UPDATE codes SET used='t' WHERE used='f' AND game_id=... AND
> code=...
>
> Then check the rowcount : if one row was updated, the code was not
> used yet. If no row was updated, the code either did not exist, or was
> already used.

You can use a stored procedure with exceptions no?

Try this:

http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE

Chris

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Terje Elde 2006-04-19 02:35:11 Re: Blocks read for index scans
Previous Message Tom Lane 2006-04-19 02:19:44 Re: Planner doesn't chose Index - (slow select)