]> granicus.if.org Git - postgresql/commitdiff
Don't count zero-filled buffers as 'read' in EXPLAIN.
authorThomas Munro <tmunro@postgresql.org>
Tue, 27 Nov 2018 22:42:32 +0000 (11:42 +1300)
committerThomas Munro <tmunro@postgresql.org>
Tue, 27 Nov 2018 22:58:10 +0000 (11:58 +1300)
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

src/backend/storage/buffer/bufmgr.c

index 01eabe57063b485edb53a8aa6d3ada02f6a3dc62..9817770affcdfc4143bd28b90157cebecdb03fb3 100644 (file)
@@ -733,7 +733,10 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
                bufHdr = LocalBufferAlloc(smgr, forkNum, blockNum, &found);
                if (found)
                        pgBufferUsage.local_blks_hit++;
-               else
+               else if (isExtend)
+                       pgBufferUsage.local_blks_written++;
+               else if (mode == RBM_NORMAL || mode == RBM_NORMAL_NO_LOG ||
+                                mode == RBM_ZERO_ON_ERROR)
                        pgBufferUsage.local_blks_read++;
        }
        else
@@ -746,7 +749,10 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
                                                         strategy, &found);
                if (found)
                        pgBufferUsage.shared_blks_hit++;
-               else
+               else if (isExtend)
+                       pgBufferUsage.shared_blks_written++;
+               else if (mode == RBM_NORMAL || mode == RBM_NORMAL_NO_LOG ||
+                                mode == RBM_ZERO_ON_ERROR)
                        pgBufferUsage.shared_blks_read++;
        }