Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16dfe25

Browse files
committed
Fix hypothetical bug in heap backward scans
Both heapgettup() and heapgettup_pagemode() incorrectly set the first pageto scan in a backward scan in which the number of pages to scan wasspecified by heap_setscanlimits(). The code incorrectly started the scanat the end of the relation when startBlk was 0, or otherwise atstartBlk - 1, neither of which is correct when only scanning a subset ofpages.The fix here checks if heap_setscanlimits() has changed the number ofpages to scan and if so we set the first page to scan as the final page inthe specified range during backward scans.Proper adjustment of this code was forgotten when heap_setscanlimits() wasadded in7516f52 back in 9.5. However, practice, nowhere in core codeperforms backward scans after having used heap_setscanlimits(), yet, it ispossible an extension uses the heap functions in this way, hencebackpatch.An upcoming patch does use heap_setscanlimits() with backward scans, sothis must be fixed before that can go in.Author: David RowleyDiscussion:https://postgr.es/m/CAApHDvpGc9h0_oVD2CtgBcxCS1N-qDYZSeBRnUh+0CWJA9cMaA@mail.gmail.comBackpatch-through: 9.5, all supported versions
1 parent40ab64c commit16dfe25

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,14 @@ heapgettup(HeapScanDesc scan,
603603
* forward scanners.
604604
*/
605605
scan->rs_base.rs_flags &= ~SO_ALLOW_SYNC;
606-
/* start from last page of the scan */
607-
if (scan->rs_startblock>0)
606+
607+
/*
608+
* Start from last page of the scan. Ensure we take into account
609+
* rs_numblocks if it's been adjusted by heap_setscanlimits().
610+
*/
611+
if (scan->rs_numblocks!=InvalidBlockNumber)
612+
page= (scan->rs_startblock+scan->rs_numblocks-1) %scan->rs_nblocks;
613+
elseif (scan->rs_startblock>0)
608614
page=scan->rs_startblock-1;
609615
else
610616
page=scan->rs_nblocks-1;
@@ -918,8 +924,14 @@ heapgettup_pagemode(HeapScanDesc scan,
918924
* forward scanners.
919925
*/
920926
scan->rs_base.rs_flags &= ~SO_ALLOW_SYNC;
921-
/* start from last page of the scan */
922-
if (scan->rs_startblock>0)
927+
928+
/*
929+
* Start from last page of the scan. Ensure we take into account
930+
* rs_numblocks if it's been adjusted by heap_setscanlimits().
931+
*/
932+
if (scan->rs_numblocks!=InvalidBlockNumber)
933+
page= (scan->rs_startblock+scan->rs_numblocks-1) %scan->rs_nblocks;
934+
elseif (scan->rs_startblock>0)
923935
page=scan->rs_startblock-1;
924936
else
925937
page=scan->rs_nblocks-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp