On 2020-Jul-23, Anastasia Lubennikova wrote:
> This error is caused by the problem with root_offsets array bounds. It
> occurs if a new HOT tuple was inserted after we've collected root_offsets,
> and thus we don't have root_offset for tuple's offnum. Concurrent insertions
> are possible, because brin_summarize_new_values() only holds ShareUpdateLock
> on table and no lock (only pin) on the page.
Excellent detective work, thanks.
> The draft fix is in the attachments. It saves root_offsets_size and checks
> that we only access valid fields.
I think this is more complicated than necessary. It seems easier to
solve this problem by just checking whether the given root pointer is
set to InvalidOffsetNumber, which is already done in the existing coding
of heap_get_root_tuples (only they spell it "0" rather than
InvalidOffsetNumber, which I propose to change). AFAIR this should only
happen in the 'anyvisible' mode, so I added that in an assert.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services