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

Commitde239d0

Browse files
committed
Consistently use PageGetExactFreeSpace() in pgstattuple.
Previously this code used PageGetHeapFreeSpace on heap pages,and usually used PageGetFreeSpace on index pages (though for somereason GetHashPageStats used PageGetExactFreeSpace instead).The difference is that those functions subtract off the size ofa line pointer, and PageGetHeapFreeSpace has some additionalrules about returning zero if adding another line pointer wouldrequire exceeding MaxHeapTuplesPerPage. Those things make sensewhen testing to see if a new tuple can be put on the page, butthey seem pretty strange for pure statistics collection.Additionally, statapprox_heap had a special rule about countinga "new" page as being fully available space. This also seemsstrange, because it's not actually usable until VACUUM or somesuch process initializes the page. Moreover, it's inconsistentwith what pgstat_heap does, which is to count such a page ashaving zero free space. So make it work like pgstat_heap, whichas of this patch unconditionally calls PageGetExactFreeSpace.This is more of a definitional change than a bug fix, so noback-patch. The module's documentation doesn't define exactlywhat "free space" means either, so we left that as-is.Frédéric Yhuel, reviewed by Rafia Sabih and Andreas Karlsson.Discussion:https://postgr.es/m/3a18f843-76f6-4a84-8cca-49537fefa15d@dalibo.com
1 parent218527d commitde239d0

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

‎contrib/pgstattuple/pgstatapprox.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,7 @@ statapprox_heap(Relation rel, output_type *stat)
106106

107107
page=BufferGetPage(buf);
108108

109-
/*
110-
* It's not safe to call PageGetHeapFreeSpace() on new pages, so we
111-
* treat them as being free space for our purposes.
112-
*/
113-
if (!PageIsNew(page))
114-
stat->free_space+=PageGetHeapFreeSpace(page);
115-
else
116-
stat->free_space+=BLCKSZ-SizeOfPageHeaderData;
109+
stat->free_space+=PageGetExactFreeSpace(page);
117110

118111
/* We may count the page as scanned even if it's new/empty */
119112
scanned++;

‎contrib/pgstattuple/pgstatindex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
311311

312312
max_avail=BLCKSZ- (BLCKSZ- ((PageHeader)page)->pd_special+SizeOfPageHeaderData);
313313
indexStat.max_avail+=max_avail;
314-
indexStat.free_space+=PageGetFreeSpace(page);
314+
indexStat.free_space+=PageGetExactFreeSpace(page);
315315

316316
indexStat.leaf_pages++;
317317

‎contrib/pgstattuple/pgstattuple.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
372372
buffer=ReadBufferExtended(rel,MAIN_FORKNUM,block,
373373
RBM_NORMAL,hscan->rs_strategy);
374374
LockBuffer(buffer,BUFFER_LOCK_SHARE);
375-
stat.free_space+=PageGetHeapFreeSpace((Page)BufferGetPage(buffer));
375+
stat.free_space+=PageGetExactFreeSpace((Page)BufferGetPage(buffer));
376376
UnlockReleaseBuffer(buffer);
377377
block++;
378378
}
@@ -385,7 +385,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
385385
buffer=ReadBufferExtended(rel,MAIN_FORKNUM,block,
386386
RBM_NORMAL,hscan->rs_strategy);
387387
LockBuffer(buffer,BUFFER_LOCK_SHARE);
388-
stat.free_space+=PageGetHeapFreeSpace((Page)BufferGetPage(buffer));
388+
stat.free_space+=PageGetExactFreeSpace((Page)BufferGetPage(buffer));
389389
UnlockReleaseBuffer(buffer);
390390
block++;
391391
}
@@ -565,7 +565,7 @@ pgstat_index_page(pgstattuple_type *stat, Page page,
565565
{
566566
OffsetNumberi;
567567

568-
stat->free_space+=PageGetFreeSpace(page);
568+
stat->free_space+=PageGetExactFreeSpace(page);
569569

570570
for (i=minoff;i <=maxoff;i=OffsetNumberNext(i))
571571
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp