On Mon, Jan 22, 2018 at 7:17 PM, Robert Haas <robertmh...@gmail.com> wrote: > On Sun, Jan 21, 2018 at 9:02 AM, Amit Kapila <amit.kapil...@gmail.com> wrote: >> How about adding a project to support Unique capability for the Hash >> Index? > > Hmm, that seems pretty hard. >
Yeah, but I think here hard part is to decide the solution to achieve it. The problem is that for the hash index to ensure that there is no duplicate entry we need to traverse the whole bucket chain and also we need to ensure that only one backend should be allowed to perform it. The simplest way to ensure that is to take and retain an exclusive lock on the primary bucket for the whole operation. Now, considering that for unique indexes there shouldn't be many overflows buckets, retaining lock doesn't sound to be much problematic. We can even think of slightly different locking technique as well which is that instead of always retaining the lock on the primary bucket, we can keep the lock on the first bucket where we find the space to insert the key and then proceed to find the entry again by taking an exclusive lock on each overflow bucket one-by-one. Only one inserter should win in this scheme, the others should find the entry inserted by it and probably the concurrency won't also be bad. -- With Regards, Amit Kapila. EnterpriseDB: http://www.enterprisedb.com