Skip to content

Commit

Permalink
Replace assert which doesn't take in account presence of invalid down…
Browse files Browse the repository at this point in the history
…links
  • Loading branch information
Konstantin Knizhnik committed Dec 1, 2024
1 parent 07fb9fb commit 72c8912
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/backend/access/nbtree/nbtsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,12 +1478,15 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
int skip = ScanDirectionIsForward(dir)
? stack->bts_offset - first_offset
: first_offset + so->n_prefetch_blocks - 1 - stack->bts_offset;
Assert(so->n_prefetch_blocks >= skip);
so->current_prefetch_distance = INCREASE_PREFETCH_DISTANCE_STEP;
so->n_prefetch_requests = Min(so->current_prefetch_distance, so->n_prefetch_blocks - skip);
so->last_prefetch_index = skip + so->n_prefetch_requests;
for (int i = skip; i < so->last_prefetch_index; i++)
PrefetchBuffer(rel, MAIN_FORKNUM, so->prefetch_blocks[i]);
/* n_prefetch_blocks can be smaller than skip because of skipped invalid downlinks */
if (so->n_prefetch_blocks >= skip)
{
so->current_prefetch_distance = INCREASE_PREFETCH_DISTANCE_STEP;
so->n_prefetch_requests = Min(so->current_prefetch_distance, so->n_prefetch_blocks - skip);
so->last_prefetch_index = skip + so->n_prefetch_requests;
for (int i = skip; i < so->last_prefetch_index; i++)
PrefetchBuffer(rel, MAIN_FORKNUM, so->prefetch_blocks[i]);
}
}

/* don't need to keep the stack around... */
Expand Down

0 comments on commit 72c8912

Please sign in to comment.