Re: UNIQUE INDEX unaware of transactions (a spin ofquestion)

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Hannu Krosing <hannu(at)tm(dot)ee>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: UNIQUE INDEX unaware of transactions (a spin ofquestion)
Date: 2001-06-18 16:24:36
Message-ID: Pine.LNX.4.30.0106181819260.898-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-06-18 16:26:09 Re: AW: AW: Call for alpha testing: planner statistics revi sion s
Previous Message Zeugswetter Andreas SB 2001-06-18 15:49:43 AW: AW: AW: Call for alpha testing: planner statistics revi sion s