Hi, I find some independent improvement in this area. In the detoast_attr, VARATT_IS_EXTERNAL_ONDISK and VARATT_IS_EXTERNAL_INDIRECT are checked first, and then VARATT_IS_EXTERNAL_EXPANDED is checked. However when VARATT_IS_EXTERNAL_EXPANDED is true, detoast_external_attr is called which would check the previous two cases again. The attached patch uses a more specific code to handle this.
This would not only remove such the double check overhead, but also make my following patch easier since I don't need to build a detoast_external_attr_[buffer] function. 'make check-world' passed. -- Best Regards Andy Fan
>From 7208142241ac18e44be2ee87e9c83c451032ca95 Mon Sep 17 00:00:00 2001 From: Andy Fan <zhihuifan1...@163.com> Date: Tue, 29 Oct 2024 14:05:05 +0800 Subject: [PATCH v20241029 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 it is true, detoast_external_attr is called which would check the two cases again. The attached patch uses a more specific code to handle this. --- src/backend/access/common/detoast.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/access/common/detoast.c b/src/backend/access/common/detoast.c index 3547cdba56..5f191a83b5 100644 --- a/src/backend/access/common/detoast.c +++ b/src/backend/access/common/detoast.c @@ -161,9 +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 */ - Assert(!VARATT_IS_EXTENDED(attr)); + 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; } else if (VARATT_IS_COMPRESSED(attr)) { -- 2.45.1