comments around heap_lock_tuple confus{ing,ed} around deleted tuples

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: comments around heap_lock_tuple confus{ing,ed} around deleted tuples
Date: 2018-04-04 21:21:40
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


While looking at resolving [1] I re-read heap_lock_tuple() and
subsidiary routines and got thoroughly confused for a while.

One reason was that function names and comments talk about updated, when
they also actually deal with deletes. heap_lock_updated_tuple()
specifically is called on tuples that have not been updated, but have
been deleted.

* heap_lock_updated_tuple
* Follow update chain when locking an updated tuple, acquiring locks (row
* marks) on the updated versions.
* The initial tuple is assumed to be already locked.


a) The function name is wrong, we're not necessarily dealing with an
updated tuple.
b) The initial tuple is actually not generally locked when the function
is called. See the call below the
/* if there are updates, follow the update chain */

Or is that supposed to mean that the initial tuple has already been
locked with the heavyweight lock? But that can't be true either,
because afaics the heap_lock_updated_tuple() call for
LockTupleKeyShare doesn't even do that?

It's also fairly weird that heap_lock_updated_tuple() returns
/* nothing to lock */
return HeapTupleMayBeUpdated;
when the tuple has been deleted (and thus
ItemPointerEquals(&tuple->t_self, ctid)). That'll not get returned by
heap_lock_tuple() itself, but seems thoroughly confusing.

There's some argument to be made for not changing this because "it seems
to work", but the wrong comments and function names are not unlikely to
cause future bugs...


Andres Freund



Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2018-04-04 21:28:09 Re: PostgreSQL's handling of fsync() errors is unsafe and risks data loss at least on XFS
Previous Message Alvaro Herrera 2018-04-04 21:09:09 Re: Foreign keys and partitioned tables