From bd43f06a3fadc75a54248a5a54941b9dff3fc576 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Mon, 8 Jul 2019 12:34:37 -0400
Subject: [PATCH 4/4] Rename attribute-detoasting functions.

The old names included the word "heap," which seems outdated now that
the heap is only one of potentially many table access methods.

Discussion: http://postgr.es/m/CA+TgmoZv-=2iWM4jcw5ZhJeL18HF96+W1yJeYrnGMYdkFFnEpQ@mail.gmail.com
---
 src/backend/access/common/detoast.c        | 26 +++++++++++-----------
 src/backend/access/common/indextuple.c     |  2 +-
 src/backend/access/heap/heaptoast.c        |  6 ++---
 src/backend/access/table/toast_helper.c    |  4 ++--
 src/backend/executor/tstoreReceiver.c      |  2 +-
 src/backend/storage/large_object/inv_api.c |  2 +-
 src/backend/utils/adt/expandedrecord.c     |  4 ++--
 src/backend/utils/fmgr/fmgr.c              |  8 +++----
 src/include/access/detoast.h               | 16 ++++++-------
 src/pl/plpgsql/src/pl_exec.c               |  2 +-
 src/test/regress/regress.c                 |  2 +-
 11 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/src/backend/access/common/detoast.c b/src/backend/access/common/detoast.c
index 36b68e35fb..78256f91ca 100644
--- a/src/backend/access/common/detoast.c
+++ b/src/backend/access/common/detoast.c
@@ -31,7 +31,7 @@ static struct varlena *toast_decompress_datum(struct varlena *attr);
 static struct varlena *toast_decompress_datum_slice(struct varlena *attr, int32 slicelength);
 
 /* ----------
- * heap_tuple_fetch_attr -
+ * detoast_external_attr -
  *
  *	Public entry point to get back a toasted value from
  *	external source (possibly still in compressed format).
@@ -43,7 +43,7 @@ static struct varlena *toast_decompress_datum_slice(struct varlena *attr, int32
  * ----------
  */
 struct varlena *
-heap_tuple_fetch_attr(struct varlena *attr)
+detoast_external_attr(struct varlena *attr)
 {
 	struct varlena *result;
 
@@ -69,7 +69,7 @@ heap_tuple_fetch_attr(struct varlena *attr)
 
 		/* recurse if value is still external in some other way */
 		if (VARATT_IS_EXTERNAL(attr))
-			return heap_tuple_fetch_attr(attr);
+			return detoast_external_attr(attr);
 
 		/*
 		 * Copy into the caller's memory context, in case caller tries to
@@ -104,7 +104,7 @@ heap_tuple_fetch_attr(struct varlena *attr)
 
 
 /* ----------
- * heap_tuple_untoast_attr -
+ * detoast_attr -
  *
  *	Public entry point to get back a toasted value from compression
  *	or external storage.  The result is always non-extended varlena form.
@@ -114,7 +114,7 @@ heap_tuple_fetch_attr(struct varlena *attr)
  * ----------
  */
 struct varlena *
-heap_tuple_untoast_attr(struct varlena *attr)
+detoast_attr(struct varlena *attr)
 {
 	if (VARATT_IS_EXTERNAL_ONDISK(attr))
 	{
@@ -145,7 +145,7 @@ heap_tuple_untoast_attr(struct varlena *attr)
 		Assert(!VARATT_IS_EXTERNAL_INDIRECT(attr));
 
 		/* recurse in case value is still extended in some other way */
-		attr = heap_tuple_untoast_attr(attr);
+		attr = detoast_attr(attr);
 
 		/* if it isn't, we'd better copy it */
 		if (attr == (struct varlena *) redirect.pointer)
@@ -162,7 +162,7 @@ heap_tuple_untoast_attr(struct varlena *attr)
 		/*
 		 * This is an expanded-object pointer --- get flat format
 		 */
-		attr = heap_tuple_fetch_attr(attr);
+		attr = detoast_external_attr(attr);
 		/* flatteners are not allowed to produce compressed/short output */
 		Assert(!VARATT_IS_EXTENDED(attr));
 	}
@@ -193,14 +193,14 @@ heap_tuple_untoast_attr(struct varlena *attr)
 
 
 /* ----------
- * heap_tuple_untoast_attr_slice -
+ * detoast_attr_slice -
  *
  *		Public entry point to get back part of a toasted value
  *		from compression or external storage.
  * ----------
  */
 struct varlena *
-heap_tuple_untoast_attr_slice(struct varlena *attr,
+detoast_attr_slice(struct varlena *attr,
 							  int32 sliceoffset, int32 slicelength)
 {
 	struct varlena *preslice;
@@ -230,13 +230,13 @@ heap_tuple_untoast_attr_slice(struct varlena *attr,
 		/* nested indirect Datums aren't allowed */
 		Assert(!VARATT_IS_EXTERNAL_INDIRECT(redirect.pointer));
 
-		return heap_tuple_untoast_attr_slice(redirect.pointer,
+		return detoast_attr_slice(redirect.pointer,
 											 sliceoffset, slicelength);
 	}
 	else if (VARATT_IS_EXTERNAL_EXPANDED(attr))
 	{
-		/* pass it off to heap_tuple_fetch_attr to flatten */
-		preslice = heap_tuple_fetch_attr(attr);
+		/* pass it off to detoast_external_attr to flatten */
+		preslice = detoast_external_attr(attr);
 	}
 	else
 		preslice = attr;
@@ -737,7 +737,7 @@ toast_decompress_datum(struct varlena *attr)
  * toast_decompress_datum_slice -
  *
  * Decompress the front of a compressed version of a varlena datum.
- * offset handling happens in heap_tuple_untoast_attr_slice.
+ * offset handling happens in detoast_attr_slice.
  * Here we just decompress a slice from the front.
  */
 static struct varlena *
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index 07586201b9..8a5f5227a3 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -89,7 +89,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
 		if (VARATT_IS_EXTERNAL(DatumGetPointer(values[i])))
 		{
 			untoasted_values[i] =
-				PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)
+				PointerGetDatum(detoast_external_attr((struct varlena *)
 													  DatumGetPointer(values[i])));
 			untoasted_free[i] = true;
 		}
diff --git a/src/backend/access/heap/heaptoast.c b/src/backend/access/heap/heaptoast.c
index c0acefc97e..9221dc71d7 100644
--- a/src/backend/access/heap/heaptoast.c
+++ b/src/backend/access/heap/heaptoast.c
@@ -376,7 +376,7 @@ toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
 			new_value = (struct varlena *) DatumGetPointer(toast_values[i]);
 			if (VARATT_IS_EXTERNAL(new_value))
 			{
-				new_value = heap_tuple_fetch_attr(new_value);
+				new_value = detoast_external_attr(new_value);
 				toast_values[i] = PointerGetDatum(new_value);
 				toast_free[i] = true;
 			}
@@ -491,7 +491,7 @@ toast_flatten_tuple_to_datum(HeapTupleHeader tup,
 			if (VARATT_IS_EXTERNAL(new_value) ||
 				VARATT_IS_COMPRESSED(new_value))
 			{
-				new_value = heap_tuple_untoast_attr(new_value);
+				new_value = detoast_attr(new_value);
 				toast_values[i] = PointerGetDatum(new_value);
 				toast_free[i] = true;
 			}
@@ -590,7 +590,7 @@ toast_build_flattened_tuple(TupleDesc tupleDesc,
 			new_value = (struct varlena *) DatumGetPointer(new_values[i]);
 			if (VARATT_IS_EXTERNAL(new_value))
 			{
-				new_value = heap_tuple_fetch_attr(new_value);
+				new_value = detoast_external_attr(new_value);
 				new_values[i] = PointerGetDatum(new_value);
 				freeable_values[num_to_free++] = (Pointer) new_value;
 			}
diff --git a/src/backend/access/table/toast_helper.c b/src/backend/access/table/toast_helper.c
index e33918a7f4..dedc123e31 100644
--- a/src/backend/access/table/toast_helper.c
+++ b/src/backend/access/table/toast_helper.c
@@ -136,9 +136,9 @@ toast_tuple_init(ToastTupleContext *ttc)
 			{
 				ttc->ttc_attr[i].tai_oldexternal = new_value;
 				if (att->attstorage == 'p')
-					new_value = heap_tuple_untoast_attr(new_value);
+					new_value = detoast_attr(new_value);
 				else
-					new_value = heap_tuple_fetch_attr(new_value);
+					new_value = detoast_external_attr(new_value);
 				ttc->ttc_values[i] = PointerGetDatum(new_value);
 				ttc->ttc_attr[i].tai_colflags |= TOASTCOL_NEEDS_FREE;
 				ttc->ttc_flags |= (TOAST_NEEDS_CHANGE | TOAST_NEEDS_FREE);
diff --git a/src/backend/executor/tstoreReceiver.c b/src/backend/executor/tstoreReceiver.c
index c0c81c82da..6306b7d0bd 100644
--- a/src/backend/executor/tstoreReceiver.c
+++ b/src/backend/executor/tstoreReceiver.c
@@ -133,7 +133,7 @@ tstoreReceiveSlot_detoast(TupleTableSlot *slot, DestReceiver *self)
 		{
 			if (VARATT_IS_EXTERNAL(DatumGetPointer(val)))
 			{
-				val = PointerGetDatum(heap_tuple_fetch_attr((struct varlena *)
+				val = PointerGetDatum(detoast_external_attr((struct varlena *)
 															DatumGetPointer(val)));
 				myState->tofree[nfree++] = val;
 			}
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index e591236343..263d5be12e 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -180,7 +180,7 @@ getdatafield(Form_pg_largeobject tuple,
 	if (VARATT_IS_EXTENDED(datafield))
 	{
 		datafield = (bytea *)
-			heap_tuple_untoast_attr((struct varlena *) datafield);
+			detoast_attr((struct varlena *) datafield);
 		freeit = true;
 	}
 	len = VARSIZE(datafield) - VARHDRSZ;
diff --git a/src/backend/utils/adt/expandedrecord.c b/src/backend/utils/adt/expandedrecord.c
index 369432d53c..d99d370b17 100644
--- a/src/backend/utils/adt/expandedrecord.c
+++ b/src/backend/utils/adt/expandedrecord.c
@@ -1159,7 +1159,7 @@ expanded_record_set_field_internal(ExpandedRecordHeader *erh, int fnumber,
 			{
 				/* Detoasting should be done in short-lived context. */
 				oldcxt = MemoryContextSwitchTo(get_short_term_cxt(erh));
-				newValue = PointerGetDatum(heap_tuple_fetch_attr((struct varlena *) DatumGetPointer(newValue)));
+				newValue = PointerGetDatum(detoast_external_attr((struct varlena *) DatumGetPointer(newValue)));
 				MemoryContextSwitchTo(oldcxt);
 			}
 			else
@@ -1305,7 +1305,7 @@ expanded_record_set_fields(ExpandedRecordHeader *erh,
 					if (expand_external)
 					{
 						/* Detoast as requested while copying the value */
-						newValue = PointerGetDatum(heap_tuple_fetch_attr((struct varlena *) DatumGetPointer(newValue)));
+						newValue = PointerGetDatum(detoast_external_attr((struct varlena *) DatumGetPointer(newValue)));
 					}
 					else
 					{
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index 0484adb984..099ebd779b 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -1739,7 +1739,7 @@ struct varlena *
 pg_detoast_datum(struct varlena *datum)
 {
 	if (VARATT_IS_EXTENDED(datum))
-		return heap_tuple_untoast_attr(datum);
+		return detoast_attr(datum);
 	else
 		return datum;
 }
@@ -1748,7 +1748,7 @@ struct varlena *
 pg_detoast_datum_copy(struct varlena *datum)
 {
 	if (VARATT_IS_EXTENDED(datum))
-		return heap_tuple_untoast_attr(datum);
+		return detoast_attr(datum);
 	else
 	{
 		/* Make a modifiable copy of the varlena object */
@@ -1764,14 +1764,14 @@ struct varlena *
 pg_detoast_datum_slice(struct varlena *datum, int32 first, int32 count)
 {
 	/* Only get the specified portion from the toast rel */
-	return heap_tuple_untoast_attr_slice(datum, first, count);
+	return detoast_attr_slice(datum, first, count);
 }
 
 struct varlena *
 pg_detoast_datum_packed(struct varlena *datum)
 {
 	if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
-		return heap_tuple_untoast_attr(datum);
+		return detoast_attr(datum);
 	else
 		return datum;
 }
diff --git a/src/include/access/detoast.h b/src/include/access/detoast.h
index 582af147ea..8c07124b76 100644
--- a/src/include/access/detoast.h
+++ b/src/include/access/detoast.h
@@ -44,34 +44,34 @@ do { \
 #define INDIRECT_POINTER_SIZE (VARHDRSZ_EXTERNAL + sizeof(varatt_indirect))
 
 /* ----------
- * heap_tuple_fetch_attr() -
+ * detoast_external_attr() -
  *
  *		Fetches an external stored attribute from the toast
  *		relation. Does NOT decompress it, if stored external
  *		in compressed format.
  * ----------
  */
-extern struct varlena *heap_tuple_fetch_attr(struct varlena *attr);
+extern struct varlena *detoast_external_attr(struct varlena *attr);
 
 /* ----------
- * heap_tuple_untoast_attr() -
+ * detoast_attr() -
  *
  *		Fully detoasts one attribute, fetching and/or decompressing
  *		it as needed.
  * ----------
  */
-extern struct varlena *heap_tuple_untoast_attr(struct varlena *attr);
+extern struct varlena *detoast_attr(struct varlena *attr);
 
 /* ----------
- * heap_tuple_untoast_attr_slice() -
+ * detoast_attr_slice() -
  *
  *		Fetches only the specified portion of an attribute.
  *		(Handles all cases for attribute storage)
  * ----------
  */
-extern struct varlena *heap_tuple_untoast_attr_slice(struct varlena *attr,
-							  int32 sliceoffset,
-							  int32 slicelength);
+extern struct varlena *detoast_attr_slice(struct varlena *attr,
+										  int32 sliceoffset,
+										  int32 slicelength);
 
 /* ----------
  * toast_raw_datum_size -
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index db2eff1bbb..870818287a 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -8267,7 +8267,7 @@ assign_simple_var(PLpgSQL_execstate *estate, PLpgSQL_var *var,
 		 * pain, but there's little choice.
 		 */
 		oldcxt = MemoryContextSwitchTo(get_eval_mcontext(estate));
-		detoasted = PointerGetDatum(heap_tuple_fetch_attr((struct varlena *) DatumGetPointer(newvalue)));
+		detoasted = PointerGetDatum(detoast_external_attr((struct varlena *) DatumGetPointer(newvalue)));
 		MemoryContextSwitchTo(oldcxt);
 		/* Now's a good time to not leak the input value if it's freeable */
 		if (freeable)
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index 826556eb29..2bbeaa0460 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -558,7 +558,7 @@ make_tuple_indirect(PG_FUNCTION_ARGS)
 
 		/* copy datum, so it still lives later */
 		if (VARATT_IS_EXTERNAL_ONDISK(attr))
-			attr = heap_tuple_fetch_attr(attr);
+			attr = detoast_external_attr(attr);
 		else
 		{
 			struct varlena *oldattr = attr;
-- 
2.17.2 (Apple Git-113)

