On Sat, Aug 20, 2016 at 4:27 AM, Amit Kapila <amit.kapil...@gmail.com> wrote: >> All uniqueness checks will find the same "nbuf" (read-locked), which >> is the first one that matches the key. >> >> They could have different "buf" buffers (the write-locked) one. But >> since read locks cannot be held while a write-lock is held, I believe >> it doesn't matter. All uniqueness checks will try to read-lock nbuf >> unless the uniqueness check for that insertion is done. When they do, >> they will block until the other insertion is finished, and when that >> happens, either the insert happened, or it returned an xid to wait for >> and retry. If it succeeded, the check attempting the read-lock will >> see the inserted tuple and return the xid of the earlier transaction >> and wait on it. If it failed, no insert happened because there's a >> visible tuple there, and the read-lock will succeed, find the visible >> tuple, and the insert will fail too. >> >> In essence, it is still the case, I believe, that only one insert can >> succeed at a time, all the others will retry. It only happens that >> with the patch, the contention will be between a read lock and a write >> lock, and not two write locks, and there's a little less contention >> (some more work can be done in parallel). >> >>> With this new mechanism, do we have two type of search interfaces >>> where one would work for keys (as now) and other for key-ctid or it >>> will be just a single interface which works both ways? I think either >>> way there are pros and cons. >> >> The patch doesn't add another interface, but the idea is to add it. >> The implementation will probably fall on a common function that can do >> both >> > > That makes sense, but this means there is a chance that the searches > could lead to different buffers in case of uniqueness checks (the > search with key-ctid could lead to a different buffer than the search > with just key). I am not clear do we have requirement for doing this > uniqueness check for key-ctid search API, because as I understand you > want to do it mainly for vacuum and WARM tuples. Vacuum won't add new > tuples, so is this required for WARM tuples?
Well, I'm not realy sure what exactly would need to be done when doing the WARM conditional insert in the case of unique indexes, and that's a strong motivation to not add the interface for inserts just yet. Vacuum will only need to delete, and in the case of deletes the operation would be quite straight forward. -- Sent via pgsql-hackers mailing list (firstname.lastname@example.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers