Multi-table-unique-constraint

From: Matt Newell <newellm(at)blur(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Multi-table-unique-constraint
Date: 2005-11-11 18:23:01
Message-ID: 200511111023.01265.newellm@blur.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Thursday 10 November 2005 15:58, you wrote:
> >> The multi-table-unique-constraint problem has to
> >> be solved before we can even think much about multi-table FKs :-(
> >
> > Do you have ideas about how this should be solved?
>
> There's some discussions in the pghackers archives --- look for
> "multi-table index" and similar phrases. But if anyone had had
> a really decent plan, it would have got done by now :-(
>

Are multi-table indexes really required? After reading the code some more, I
came across this comment in nbtinsert.c:_bt_doinsert

* NOTE: obviously, _bt_check_unique can only detect keys that are already in
* the index; so it cannot defend against concurrent insertions of the
* same key. We protect against that by means of holding a write lock on
* the target page. Any other would-be inserter of the same key must
* acquire a write lock on the same target page, so only one would-be
* inserter can be making the check at one time. Furthermore, once we are
* past the check we hold write locks continuously until we have performed
* our insertion, so no later inserter can fail to see our insertion.
* (This requires some care in _bt_insertonpg.)

Would it be possible to make another routine that locates and aquires a write
lock on the page where the key would be inserted in each index(for each table
in the inheritance), and holds all these locks until the key is inserted into
the correct index. It seems this would solve the unique problem without
changing much else.

Matt

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2005-11-11 18:24:39 Re: someone working to add merge?
Previous Message Marek Lewczuk 2005-11-11 18:22:17 Re: Getting table name/tuple from OID

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2005-11-11 19:07:43 Re: Multi-table-unique-constraint
Previous Message Hiroshi Saito 2005-11-11 01:55:53 problem in MS-VC6 environment.