Re: SELECT FOR UPDATE performance is bad

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: SELECT FOR UPDATE performance is bad
Дата
Msg-id 44459EAF.2030601@calorieking.com
обсуждение исходный текст
Ответ на Re: SELECT FOR UPDATE performance is bad  (PFC <lists@peufeu.com>)
Список 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



В списке pgsql-performance по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Planner doesn't chose Index - (slow select)
Следующее
От: Terje Elde
Дата:
Сообщение: Re: Blocks read for index scans