Fix bad formula in previous commit.
authorRobert Haas <[email protected]>
Tue, 17 Dec 2019 20:53:17 +0000 (15:53 -0500)
committerRobert Haas <[email protected]>
Tue, 17 Dec 2019 20:53:17 +0000 (15:53 -0500)
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.

src/backend/access/common/detoast.c

index 61d7e64c4490752273118a61112c14c1e1e4ff8a..6341107e8823475b02792ffe77c6f84a79e7cb44 100644 (file)
@@ -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),