On 2020-May-26, Tom Lane wrote:

> Are you sure you correctly identified the source of the bogus error
> report?

This version's better.  It doesn't touch the write side at all.
On the read side, only report a short read as such if errno's not set.

This error isn't frequently seen.  This page
https://blog.csdn.net/pg_hgdb/article/details/106279303
(A Postgres fork; blames the error on the temp hash files being encrypted,
suggests to increase temp_buffers) is the only one I found.

There are more uses of BufFileRead that don't bother to distinguish
these two cases apart, though -- logtape.c, tuplestore.c,
gistbuildbuffers.c all do the same.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c
index d13efc4d98..f91e69a09d 100644
--- a/src/backend/executor/nodeHashjoin.c
+++ b/src/backend/executor/nodeHashjoin.c
@@ -930,9 +930,17 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
 		return NULL;
 	}
 	if (nread != sizeof(header))
-		ereport(ERROR,
-				(errcode_for_file_access(),
-				 errmsg("could not read from hash-join temporary file: %m")));
+	{
+		if (errno == 0)
+			ereport(ERROR,
+					(errcode_for_file_access(),
+					 errmsg("could not read from hash-join temporary file: read only %d of %d bytes",
+							(int) nread, (int) sizeof(header))));
+		else
+			ereport(ERROR,
+					(errcode_for_file_access(),
+					 errmsg("could not read from hash-join temporary file: %m")));
+	}
 	*hashvalue = header[0];
 	tuple = (MinimalTuple) palloc(header[1]);
 	tuple->t_len = header[1];
@@ -940,9 +948,17 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
 						(void *) ((char *) tuple + sizeof(uint32)),
 						header[1] - sizeof(uint32));
 	if (nread != header[1] - sizeof(uint32))
-		ereport(ERROR,
-				(errcode_for_file_access(),
-				 errmsg("could not read from hash-join temporary file: %m")));
+	{
+		if (errno == 0)
+			ereport(ERROR,
+					(errcode_for_file_access(),
+					 errmsg("could not read from hash-join temporary file: read only %d of %d bytes",
+							(int) nread, (int) (header[1] - sizeof(uint32)))));
+		else
+			ereport(ERROR,
+					(errcode_for_file_access(),
+					 errmsg("could not read from hash-join temporary file: %m")));
+	}
 	return ExecStoreMinimalTuple(tuple, tupleSlot, true);
 }
 

Reply via email to