pgsql: Code cleanup for toast_fetch_datum and toast_fetch_datum_slice. - Mailing list pgsql-committers

From Robert Haas
Subject pgsql: Code cleanup for toast_fetch_datum and toast_fetch_datum_slice.
Date
Msg-id E1ihItS-0006Rn-Ps@gemulon.postgresql.org
Whole thread Raw
Responses Re: pgsql: Code cleanup for toast_fetch_datum and toast_fetch_datum_slice.  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-committers
Code cleanup for toast_fetch_datum and toast_fetch_datum_slice.

Rework some of the checks for bad TOAST chunks to be a bit simpler
and easier to understand. These checks verify that (1) we get all
and only the chunk numbers we expect to see and (2) each chunk has
the expected size. However, the existing code was a bit hard to
understand, at least for me; try to make it clearer.

As part of that, have toast_fetch_datum_slice check the relationship
between endchunk and totalchunks only with an Assert() rather than
checking every chunk number against both values. There's no need to
check that relationship in production builds because it's not a
function of whether on-disk corruption is present; it's just a
question of whether the code does the right math.

Also, have toast_fetch_datum_slice() use ereport(ERROR) rather than
elog(ERROR). Commit fd6ec93bf890314ac694dc8a7f3c45702ecc1bbd made
the two functions inconsistent with each other.

Rename assorted variables for better clarity and consistency, and
move assorted variables from function scope to the function's main
loop. Remove a few variables that are used only once entirely.

Patch by me, reviewed by Peter Eisentraut.

Discussion: http://postgr.es/m/CA+TgmobBzxwFojJ0zV0Own3dr09y43hp+OzU2VW+nos4PMXWEg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d5406dea25b600408e7acf17d5a06e82d3ce6d0d

Modified Files
--------------
src/backend/access/common/detoast.c | 220 +++++++++++++++++-------------------
1 file changed, 102 insertions(+), 118 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: simplehash: Allow for use in frontend code.
Next
From: Robert Haas
Date:
Subject: Re: pgsql: Code cleanup for toast_fetch_datum and toast_fetch_datum_slice.