diff --git a/pkg/storage/pebble_mvcc_scanner.go b/pkg/storage/pebble_mvcc_scanner.go index b5d75eaf4de4..09a0e37c9781 100644 --- a/pkg/storage/pebble_mvcc_scanner.go +++ b/pkg/storage/pebble_mvcc_scanner.go @@ -551,8 +551,13 @@ func (p *pebbleMVCCScanner) incrementItersBeforeSeek() { // Decrements itersBeforeSeek while ensuring it stays positive. func (p *pebbleMVCCScanner) decrementItersBeforeSeek() { p.itersBeforeSeek-- - if p.itersBeforeSeek < 0 { - p.itersBeforeSeek = 0 + if p.itersBeforeSeek < 1 { + if maxItersBeforeSeek > 0 { + p.itersBeforeSeek = 1 + } else if p.itersBeforeSeek < 0 { + // INVARIANT: maxItersBeforeSeek == 0 && p.itersBeforeSeek < 0. + p.itersBeforeSeek = 0 + } } }