On Mon, Jun 18, 2018 at 4:05 PM, Peter Geoghegan <pg(at)bowt(dot)ie> wrote:> IOW, the approach you've taken in bttargetdelete() isn't quite correct> because you imagine that it's okay to occasionally "lose" the index> tuple that you originally found, and just move on. That needs to be> 100% reliable, or else we'll end up with index tuples that point to> the wrong heap tuples in rare cases with concurrent insertions.

Attached patch adds a new amcheck check withinbt_index_parent_check(). With the patch, heap TIDs are accumulated ina tuplesort and sorted at the tail end of verification (beforeoptional heapallindexed verification runs). This will reliably detectthe kind of corruption I noticed was possible with your patch.

Note that the amcheck enhancement that went along with myheap-tid-btree-sort patch may not have detected this issue, which iswhy I wrote this patch -- the heap-tid-btree-sort amcheck stuff coulddetect duplicates, but only when all other attributes happened to beidentical when comparing sibling index tuples (i.e. only when we mustactually compare TIDs across sibling index tuples). If you add thischeck, I'm pretty sure that you can detect any possible problem. Youshould think about using this to debug your patch.

I may get around to submitting this to a CF, but that isn't a priorityright now.