From: Robert Haas Date: Tue, 17 Dec 2019 20:53:17 +0000 (-0500) Subject: Fix bad formula in previous commit. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=5184f110aa4130ec87b0b3e0834292cd8cb1fd8a;p=users%2Frhaas%2Fpostgres.git Fix bad formula in previous commit. Commit d5406dea25b600408e7acf17d5a06e82d3ce6d0d used a slightly novel, and wrong, approach to compute the length of the last toast chunk. It worked fine unless the last chunk happened to have the largest possible size. --- diff --git a/src/backend/access/common/detoast.c b/src/backend/access/common/detoast.c index 61d7e64c44..6341107e88 100644 --- a/src/backend/access/common/detoast.c +++ b/src/backend/access/common/detoast.c @@ -443,7 +443,7 @@ toast_fetch_datum(struct varlena *attr) toast_pointer.va_valueid, RelationGetRelationName(toastrel)))); expected_size = curchunk < totalchunks - 1 ? TOAST_MAX_CHUNK_SIZE - : attrsize % TOAST_MAX_CHUNK_SIZE; + : attrsize - ((totalchunks - 1) * TOAST_MAX_CHUNK_SIZE); if (chunksize != expected_size) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -676,7 +676,7 @@ toast_fetch_datum_slice(struct varlena *attr, int32 sliceoffset, toast_pointer.va_valueid, RelationGetRelationName(toastrel)))); expected_size = curchunk < totalchunks - 1 ? TOAST_MAX_CHUNK_SIZE - : attrsize % TOAST_MAX_CHUNK_SIZE; + : attrsize - ((totalchunks - 1) * TOAST_MAX_CHUNK_SIZE); if (chunksize != expected_size) ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED),