> On Mon, Jan 20, 2020 at 05:05:33PM -0800, Peter Geoghegan wrote: > > I suggest that you find a way to add assertions to code like > _bt_readpage() that verify that we do in fact have the buffer content > lock. Actually, there is an existing assertion here that covers the > pin, but not the buffer content lock: > > static bool > _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum) > { > <declare variables> > ... > > /* > * We must have the buffer pinned and locked, but the usual macro can't be > * used here; this function is what makes it good for currPos. > */ > Assert(BufferIsValid(so->currPos.buf)); > > You can add another assertion that calls a new utility function in > bufmgr.c. That can use the same logic as this existing assertion in > FlushOneBuffer(): > > Assert(LWLockHeldByMe(BufferDescriptorGetContentLock(bufHdr))); > > We haven't needed assertions like this so far because it's usually it > is clear whether or not a buffer lock is held (plus the bufmgr.c > assertions help on their own). The fact that it isn't clear whether or > not a buffer lock will be held by caller here suggests a problem. Even > still, having some guard rails in the form of these assertions could > be helpful. Also, it seems like _bt_scankey_within_page() should have > a similar set of assertions.
Thanks for suggestion. Agree, we will add such guards. It seems that in general I need to go through the locking in the patch one more time, since there are some gaps I din't notice/didn't know about before. > BTW, there is a paper that describes optimizations like loose index > scan and skip scan together, in fairly general terms: "Efficient > Search of Multidimensional B-Trees". Loose index scans are given the > name "MDAM duplicate elimination" in the paper. See: > > http://vldb.org/conf/1995/P710.PDF > > Goetz Graefe told me about the paper. It seems like the closest thing > that exists to a taxonomy or conceptual framework for these > techniques. Yes, I've read this paper, as it's indeed the only reference I found about this topic in literature. But unfortunately it's not much and (at least from the first read) gives only an overview of the idea.