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

Commit83cd2d8

Browse files
committed
Make heap_fetch API more consistent by having the buffer remain pinned
in all cases when keep_buf = true. This allows ANALYZE's inner loop touse heap_release_fetch, which saves multiple buffer lookups for the samepage and avoids overestimation of cost by the vacuum cost mechanism.
1 parent2c66dcf commit83cd2d8

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.179 2004/10/15 22:39:42 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.180 2004/10/26 16:05:02 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -878,14 +878,16 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
878878
* is set to the buffer holding the tuple and TRUE is returned. The caller
879879
* must unpin the buffer when done with the tuple.
880880
*
881-
* If the tuple is not found, then tuple->t_data is set to NULL, *userbuf
882-
* is set toInvalidBuffer, and FALSE is returned.
881+
* If the tuple is not found (ie, item number references a deleted slot),
882+
*then tuple->t_datais set toNULL and FALSE is returned.
883883
*
884-
* If the tuple is found but fails the time qual check, then FALSE will be
885-
* returned. When the caller specifies keep_buf = true, we retain the pin
886-
* on the buffer and return it in *userbuf (so the caller can still access
887-
* the tuple); when keep_buf = false, the pin is released and *userbuf is set
888-
* to InvalidBuffer.
884+
* If the tuple is found but fails the time qual check, then FALSE is returned
885+
* but tuple->t_data is left pointing to the tuple.
886+
*
887+
* keep_buf determines what is done with the buffer in the FALSE-result cases.
888+
* When the caller specifies keep_buf = true, we retain the pin on the buffer
889+
* and return it in *userbuf (so the caller must eventually unpin it); when
890+
* keep_buf = false, the pin is released and *userbuf is set to InvalidBuffer.
889891
*
890892
* It is somewhat inconsistent that we ereport() on invalid block number but
891893
* return false on invalid item number. This is historical. The only
@@ -914,6 +916,8 @@ heap_fetch(Relation relation,
914916
* InvalidBuffer on entry, that buffer will be released before reading
915917
* the new page. This saves a separate ReleaseBuffer step and hence
916918
* one entry into the bufmgr when looping through multiple fetches.
919+
* Also, if *userbuf is the same buffer that holds the target tuple,
920+
* we avoid bufmgr manipulation altogether.
917921
*/
918922
bool
919923
heap_release_fetch(Relationrelation,
@@ -962,8 +966,13 @@ heap_release_fetch(Relation relation,
962966
if (!ItemIdIsUsed(lp))
963967
{
964968
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
965-
ReleaseBuffer(buffer);
966-
*userbuf=InvalidBuffer;
969+
if (keep_buf)
970+
*userbuf=buffer;
971+
else
972+
{
973+
ReleaseBuffer(buffer);
974+
*userbuf=InvalidBuffer;
975+
}
967976
tuple->t_datamcxt=NULL;
968977
tuple->t_data=NULL;
969978
return false;
@@ -1007,17 +1016,13 @@ heap_release_fetch(Relation relation,
10071016

10081017
/* Tuple failed time qual, but maybe caller wants to see it anyway. */
10091018
if (keep_buf)
1010-
{
10111019
*userbuf=buffer;
1012-
1013-
return false;
1020+
else
1021+
{
1022+
ReleaseBuffer(buffer);
1023+
*userbuf=InvalidBuffer;
10141024
}
10151025

1016-
/* Okay to release pin on buffer. */
1017-
ReleaseBuffer(buffer);
1018-
1019-
*userbuf=InvalidBuffer;
1020-
10211026
return false;
10221027
}
10231028

‎src/backend/access/nbtree/nbtinsert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.117 2004/10/15 22:39:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.118 2004/10/26 16:05:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -269,8 +269,8 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
269269
SetBufferCommitInfoNeedsSave(buf);
270270
}
271271
LockBuffer(hbuffer,BUFFER_LOCK_UNLOCK);
272-
ReleaseBuffer(hbuffer);
273272
}
273+
ReleaseBuffer(hbuffer);
274274
}
275275
}
276276

‎src/backend/commands/analyze.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.77 2004/09/30 23:21:19 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.78 2004/10/26 16:05:03 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -822,11 +822,12 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
822822
for (targoffset=FirstOffsetNumber;targoffset <=maxoffset;targoffset++)
823823
{
824824
HeapTupleDatatargtuple;
825-
Buffertupbuffer;
826825

827826
ItemPointerSet(&targtuple.t_self,targblock,targoffset);
828-
if (heap_fetch(onerel,SnapshotNow,&targtuple,&tupbuffer,
829-
false,NULL))
827+
/* We use heap_release_fetch to avoid useless bufmgr traffic */
828+
if (heap_release_fetch(onerel,SnapshotNow,
829+
&targtuple,&targbuffer,
830+
true,NULL))
830831
{
831832
/*
832833
* The first targrows live rows are simply copied into the
@@ -869,9 +870,6 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
869870
rowstoskip-=1;
870871
}
871872

872-
/* must release the extra pin acquired by heap_fetch */
873-
ReleaseBuffer(tupbuffer);
874-
875873
liverows+=1;
876874
}
877875
else
@@ -886,7 +884,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
886884
}
887885
}
888886

889-
/* Now release theinitialpin on the page */
887+
/* Now release the pin on the page */
890888
ReleaseBuffer(targbuffer);
891889
}
892890

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp