From 5e51cfb41ab41cae9be319d36f26c4b5a1fc556e Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Mon, 19 Dec 2022 13:02:59 +0000 Subject: [PATCH v2] Remove unnecessary BlessTupleDesc() after get_call_result_type() get_call_result_type() already does what BlessTupleDesc() intends to do for the returned tuple descriptor. Hence, it is unnecessary to call BlessTupleDesc() it right after get_call_result_type(). --- contrib/hstore/hstore_op.c | 6 +----- contrib/pageinspect/brinfuncs.c | 1 - contrib/pageinspect/btreefuncs.c | 2 -- contrib/pageinspect/hashfuncs.c | 2 -- contrib/sslinfo/sslinfo.c | 6 +----- src/backend/statistics/mcv.c | 1 - src/backend/utils/adt/misc.c | 2 +- src/test/regress/regress.c | 1 - 8 files changed, 3 insertions(+), 18 deletions(-) diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c index 0d4ec16d1e..2b3a1e6a2f 100644 --- a/contrib/hstore/hstore_op.c +++ b/contrib/hstore/hstore_op.c @@ -862,13 +862,9 @@ setup_firstcall(FuncCallContext *funcctx, HStore *hs, if (fcinfo) { - TupleDesc tupdesc; - /* Build a tuple descriptor for our result type */ - if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) + if (get_call_result_type(fcinfo, NULL, &funcctx->tuple_desc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - - funcctx->tuple_desc = BlessTupleDesc(tupdesc); } MemoryContextSwitchTo(oldcontext); diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c index 12a7217038..b812cdeee3 100644 --- a/contrib/pageinspect/brinfuncs.c +++ b/contrib/pageinspect/brinfuncs.c @@ -348,7 +348,6 @@ brin_metapage_info(PG_FUNCTION_ARGS) /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - tupdesc = BlessTupleDesc(tupdesc); /* Extract values from the metapage */ meta = (BrinMetaPageData *) PageGetContents(page); diff --git a/contrib/pageinspect/btreefuncs.c b/contrib/pageinspect/btreefuncs.c index 9375d55e14..5e083a6f9c 100644 --- a/contrib/pageinspect/btreefuncs.c +++ b/contrib/pageinspect/btreefuncs.c @@ -537,7 +537,6 @@ bt_page_items_internal(PG_FUNCTION_ARGS, enum pageinspect_version ext_version) /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - tupleDesc = BlessTupleDesc(tupleDesc); uargs->tupd = tupleDesc; @@ -653,7 +652,6 @@ bt_page_items_bytea(PG_FUNCTION_ARGS) /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - tupleDesc = BlessTupleDesc(tupleDesc); uargs->tupd = tupleDesc; diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index 81815392d7..e1364c5518 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -259,7 +259,6 @@ hash_page_stats(PG_FUNCTION_ARGS) /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - tupleDesc = BlessTupleDesc(tupleDesc); j = 0; values[j++] = Int32GetDatum(stat.live_items); @@ -334,7 +333,6 @@ hash_page_items(PG_FUNCTION_ARGS) /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - tupleDesc = BlessTupleDesc(tupleDesc); fctx->attinmeta = TupleDescGetAttInMetadata(tupleDesc); diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c index 5fd46b9874..6e313ced5e 100644 --- a/contrib/sslinfo/sslinfo.c +++ b/contrib/sslinfo/sslinfo.c @@ -370,9 +370,6 @@ ssl_extension_info(PG_FUNCTION_ARGS) if (SRF_IS_FIRSTCALL()) { - - TupleDesc tupdesc; - /* create a function context for cross-call persistence */ funcctx = SRF_FIRSTCALL_INIT(); @@ -385,11 +382,10 @@ ssl_extension_info(PG_FUNCTION_ARGS) fctx = (SSLExtensionInfoContext *) palloc(sizeof(SSLExtensionInfoContext)); /* Construct tuple descriptor */ - if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) + if (get_call_result_type(fcinfo, NULL, &fctx->tupdesc) != TYPEFUNC_COMPOSITE) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context that cannot accept type record"))); - fctx->tupdesc = BlessTupleDesc(tupdesc); /* Set max_calls as a count of extensions in certificate */ max_calls = cert != NULL ? X509_get_ext_count(cert) : 0; diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c index f5a7c31272..592c76fea7 100644 --- a/src/backend/statistics/mcv.c +++ b/src/backend/statistics/mcv.c @@ -1371,7 +1371,6 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("function returning record called in context " "that cannot accept type record"))); - tupdesc = BlessTupleDesc(tupdesc); /* * generate attribute metadata needed later to produce tuples from raw diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 7808fbd448..a2a2df2adb 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -508,7 +508,7 @@ pg_get_catalog_foreign_keys(PG_FUNCTION_ARGS) if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - funcctx->tuple_desc = BlessTupleDesc(tupdesc); + funcctx->tuple_desc = tupdesc; /* * We use array_in to convert the C strings in sys_fk_relationships[] diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 2977045cc7..4d5e3e0918 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -1133,7 +1133,6 @@ test_enc_conversion(PG_FUNCTION_ARGS) /* Build a tuple descriptor for our result type */ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); - tupdesc = BlessTupleDesc(tupdesc); srclen = VARSIZE_ANY_EXHDR(string); src = VARDATA_ANY(string); -- 2.34.1