From ef3342955ab6296f463ddb8997a266376f35a658 Mon Sep 17 00:00:00 2001 From: buter Date: Tue, 7 Jun 2022 15:01:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djson=5Fto=5Frecordset?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=9C=AA=E5=AF=B9=E8=BE=93=E5=85=A5=E5=81=9A?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/jsonfuncs.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/common/backend/utils/adt/jsonfuncs.cpp b/src/common/backend/utils/adt/jsonfuncs.cpp index 77f88ace6..43b7f5bf7 100644 --- a/src/common/backend/utils/adt/jsonfuncs.cpp +++ b/src/common/backend/utils/adt/jsonfuncs.cpp @@ -2304,6 +2304,7 @@ static inline Datum populate_recordset_worker(FunctionCallInfo fcinfo, bool have int32 tupTypmod; HeapTupleHeader rec; TupleDesc tupdesc; + bool needforget = false; RecordIOData *my_extra = NULL; int ncolumns; PopulateRecordsetState *state = NULL; @@ -2351,7 +2352,10 @@ static inline Datum populate_recordset_worker(FunctionCallInfo fcinfo, bool have if (PG_ARGISNULL(0)) { rec = NULL; } else { + /* using the arg tupdesc, becouse it may not be the same as the result tupdesc. */ rec = PG_GETARG_HEAPTUPLEHEADER(0); + tupdesc = lookup_rowtype_tupdesc(HeapTupleHeaderGetTypeId(rec), HeapTupleHeaderGetTypMod(rec)); + needforget = true; } } else { if (PG_ARGISNULL(1)) { @@ -2359,6 +2363,7 @@ static inline Datum populate_recordset_worker(FunctionCallInfo fcinfo, bool have } rec = NULL; } + tupType = tupdesc->tdtypeid; tupTypmod = tupdesc->tdtypmod; ncolumns = tupdesc->natts; @@ -2388,6 +2393,9 @@ static inline Datum populate_recordset_worker(FunctionCallInfo fcinfo, bool have /* make these in a sufficiently long-lived memory context */ old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory); state->ret_tdesc = CreateTupleDescCopy(tupdesc); + if (needforget) { + DecrTupleDescRefCount(tupdesc); + } BlessTupleDesc(state->ret_tdesc); state->tuple_store = tuplestore_begin_heap((uint32)rsi->allowedModes & SFRM_Materialize_Random, false, u_sess->attr.attr_memory.work_mem); From c7c7457fff0f28d07a252f7e64b27d5abe53babd Mon Sep 17 00:00:00 2001 From: buter Date: Fri, 10 Jun 2022 17:33:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E5=88=AB?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/jsonfuncs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/backend/utils/adt/jsonfuncs.cpp b/src/common/backend/utils/adt/jsonfuncs.cpp index 43b7f5bf7..8e763b631 100644 --- a/src/common/backend/utils/adt/jsonfuncs.cpp +++ b/src/common/backend/utils/adt/jsonfuncs.cpp @@ -2352,7 +2352,7 @@ static inline Datum populate_recordset_worker(FunctionCallInfo fcinfo, bool have if (PG_ARGISNULL(0)) { rec = NULL; } else { - /* using the arg tupdesc, becouse it may not be the same as the result tupdesc. */ + /* using the arg tupdesc, because it may not be the same as the result tupdesc. */ rec = PG_GETARG_HEAPTUPLEHEADER(0); tupdesc = lookup_rowtype_tupdesc(HeapTupleHeaderGetTypeId(rec), HeapTupleHeaderGetTypMod(rec)); needforget = true;