Andy Fan <zhihuifan1...@163.com> writes:

>
> make check-world passed after applying this patch.

v2 changes the places of Assert, which is missed in v1 by mistakes.

-- 
Best Regards
Andy Fan

>From 0bbd242e034b8461e40bb17aec4fa354f5c97815 Mon Sep 17 00:00:00 2001
From: Andy Fan <zhihuifan1...@163.com>
Date: Tue, 29 Oct 2024 14:05:05 +0800
Subject: [PATCH v2 1/1] Using more specific code when detoasting an expanded
 datum.

In the detoast_attr function, VARATT_IS_EXTERNAL_ONDISK and
VARATT_IS_EXTERNAL_INDIRECT are checked first, and then
VARATT_IS_EXTERNAL_EXPANDED is checked, However when it's true,
detoast_external_attr is called which checks the two cases again.
The attached patch uses a more specific code to handle this.
---
 src/backend/access/common/detoast.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/common/detoast.c b/src/backend/access/common/detoast.c
index 3547cdba56..ec439e667b 100644
--- a/src/backend/access/common/detoast.c
+++ b/src/backend/access/common/detoast.c
@@ -161,8 +161,15 @@ detoast_attr(struct varlena *attr)
 		/*
 		 * This is an expanded-object pointer --- get flat format
 		 */
-		attr = detoast_external_attr(attr);
-		/* flatteners are not allowed to produce compressed/short output */
+		ExpandedObjectHeader *eoh;
+		Size		resultsize;
+		struct varlena *result;
+
+		eoh = DatumGetEOHP(PointerGetDatum(attr));
+		resultsize = EOH_get_flat_size(eoh);
+		result = (struct varlena *) palloc(resultsize);
+		EOH_flatten_into(eoh, (void *) result, resultsize);
+		attr = result;
 		Assert(!VARATT_IS_EXTENDED(attr));
 	}
 	else if (VARATT_IS_COMPRESSED(attr))
-- 
2.45.1

Reply via email to