Re: UNIQUE INDEX unaware of transactions (a spin ofquestion) - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: UNIQUE INDEX unaware of transactions (a spin ofquestion)
Date
Msg-id Pine.LNX.4.30.0106181819260.898-100000@peter.localdomain
Whole thread Raw
In response to Re: UNIQUE INDEX unaware of transactions (a spin ofquestion)  (Hannu Krosing <hannu@tm.ee>)
List pgsql-hackers
Hannu Krosing writes:

> Is there any way to make unique indexes transaction-aware ?
> Are competeing updates on unique indexes transaction-aware ?

AFAIK, indexes are not transaction-aware at all, they only provide
information that there might be a visible row at the pointed-to location
in the table.  (This is also the reason that you cannot simply fetch the
data from the index, you always need to look at the table, too.)

Personally, I think that to support proper transaction-aware and
deferrable unique contraints, this needs to be done with triggers,
somewhat like the foreign keys.

> I.e. can I be sure that if I do
>
> begin;
> if select where key=1 result exists
> then update where key=1
> else insert(key,...)values(1,...)
> end;
>
> then this will have the expected behaviour in presence of multiple
> concurrent updaters?

I guess not.

The classical example is

update t set x = x + 1;

which won't work if x is constrained to be unique.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Doc translation
Next
From: Tom Lane
Date:
Subject: Re: AW: AW: Call for alpha testing: planner statistics revi sion s