Skip to content

Commit d67dae0

Browse files
committed
Don't count zero-filled buffers as 'read' in EXPLAIN.
If you extend a relation, it should count as a block written, not read (we write a zero-filled block). If you ask for a zero-filled buffer, it shouldn't be counted as read or written. Later we might consider counting zero-filled buffers with a separate counter, if they become more common due to future work. Author: Thomas Munro Reviewed-by: Haribabu Kommi, Kyotaro Horiguchi, David Rowley Discussion: https://postgr.es/m/CAEepm%3D3JytB3KPpvSwXzkY%2Bdwc5zC8P8Lk7Nedkoci81_0E9rA%40mail.gmail.com
1 parent 471a7af commit d67dae0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,10 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
733733
bufHdr = LocalBufferAlloc(smgr, forkNum, blockNum, &found);
734734
if (found)
735735
pgBufferUsage.local_blks_hit++;
736-
else
736+
else if (isExtend)
737+
pgBufferUsage.local_blks_written++;
738+
else if (mode == RBM_NORMAL || mode == RBM_NORMAL_NO_LOG ||
739+
mode == RBM_ZERO_ON_ERROR)
737740
pgBufferUsage.local_blks_read++;
738741
}
739742
else
@@ -746,7 +749,10 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
746749
strategy, &found);
747750
if (found)
748751
pgBufferUsage.shared_blks_hit++;
749-
else
752+
else if (isExtend)
753+
pgBufferUsage.shared_blks_written++;
754+
else if (mode == RBM_NORMAL || mode == RBM_NORMAL_NO_LOG ||
755+
mode == RBM_ZERO_ON_ERROR)
750756
pgBufferUsage.shared_blks_read++;
751757
}
752758

0 commit comments

Comments
 (0)