Re: Unique Constraints using Non-Unique Indexes - Mailing list pgsql-hackers

From Gregory Stark
Subject Re: Unique Constraints using Non-Unique Indexes
Date
Msg-id 87y78dz461.fsf@oxford.xeocode.com
Whole thread Raw
In response to Unique Constraints using Non-Unique Indexes  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
"Simon Riggs" <simon@2ndquadrant.com> writes:

> If the uniqueness check used a scan key that consisted of all of the
> Primary Key columns, rather than just the index columns then it would be
> able to scan through non-unique index entries to check uniqueness.
> Interestingly, the current uniqueness check code already scans through
> multiple tuples because of the possible existence of multiple row
> versions. So we just need to supply a different scan key.

The tricky part about unique constraints is guaranteeing that only one
transaction can see their insert as "first". If you just did a simple scan and
went ahead if you don't see any conflicts you would risk having two inserters
not see each others insert and go ahead and index their insert and proceed.

As I understand it we normally protect against that by holding a lock on the
first page of the key we're inserting while we perform the uniqueness check.
Could you still do that in this case? I don't immediately see any problems
aside from reduced concurrency but this code isn't really my forté.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com Ask me about EnterpriseDB's On-Demand Production
Tuning


pgsql-hackers by date:

Previous
From: Sam Mason
Date:
Subject: Re: Sort Refinement
Next
From: Tom Lane
Date:
Subject: Re: [PATCHES] [GENERAL] Empty arrays with ARRAY[]