From 2737a2d6d17edcf38c67016571d231d3f0e98c4d Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Tue, 17 Oct 2017 09:35:31 +1300
Subject: [PATCH] Don't count EOF as a temporary buffer read in EXPLAIN.

Previously, hash joins appeared to read slightly more temporary data than
they wrote in EXPLAIN (ANALYZE, BUFFERS) output, which looked a bit strange.

Author: Thomas Munro
Reported-By: Vik Fearing
---
 src/backend/storage/file/buffile.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index 4ca0ea4f2a..de85b6805c 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -264,7 +264,8 @@ BufFileLoadBuffer(BufFile *file)
 	file->offsets[file->curFile] += file->nbytes;
 	/* we choose not to advance curOffset here */
 
-	pgBufferUsage.temp_blks_read++;
+	if (file->nbytes > 0)
+		pgBufferUsage.temp_blks_read++;
 }
 
 /*
-- 
2.14.1

