On Thu, Nov 4, 2021 at 8:52 AM Andrey Borodin <x4...@yandex-team.ru> wrote: > Let's enumerate steps how things can go wrong. > > Backend1: Index-Only scan returns tid and xs_hitup with index_tuple1 on > index_page1 pointing to heap_tuple1 on page1 > > Backend2: Remove index_tuple1 and heap_tuple1 > > Backend3: Mark page1 all-visible > Backend1: Thinks that page1 is all-visible and shows index_tuple1 as visible > > To avoid this Backend1 must hold pin on index_page1 until it's done with > checking visibility, and Backend2 must do LockBufferForCleanup(index_page1). > Do I get things right?
Almost. Backend3 is actually Backend2 here (there is no 3) -- it runs VACUUM throughout. Note that it's not particularly likely that Backend2/VACUUM will "win" this race, because it typically has to do much more work than Backend1. It has to actually remove the index tuples from the leaf page, then any other index work (for this and other indexes). Then it has to arrive back in vacuumlazy.c to set the VM bit in lazy_vacuum_heap_page(). That's a pretty unlikely scenario. And even if it happened it would only happen once (until the next time we get unlucky). What are the chances of somebody noticing a more or less once-off, slightly wrong answer? -- Peter Geoghegan