diff --git a/src/gausskernel/storage/tcap/tcap_manager.cpp b/src/gausskernel/storage/tcap/tcap_manager.cpp index bec2aa4e7b0b97a0b8b8a8e499ebce784d25b183..84f1e9b7bf0c79c30f3774826687e8e8ff3a50e1 100644 --- a/src/gausskernel/storage/tcap/tcap_manager.cpp +++ b/src/gausskernel/storage/tcap/tcap_manager.cpp @@ -282,11 +282,15 @@ static bool TrFetchOrinameImpl(Oid nspId, const char *oriname, TrObjType type, SysScanDesc sd; ScanKeyData skey[3]; HeapTuple tup; + TrObjDesc tempDesc; + errno_t rc = 0; bool found = false; if (!OidIsValid(nspId)) { return false; } + rc = memset_s(&tempDesc, sizeof(TrObjDesc), 0, sizeof(TrObjDesc)); + securec_check(rc, "\0", "\0"); rbRel = heap_open(RecyclebinRelationId, AccessShareLock); @@ -307,14 +311,22 @@ static bool TrFetchOrinameImpl(Oid nspId, const char *oriname, TrObjType type, continue; } - found = true; TrDescRead(desc, tup); - break; + + if(!found || desc->recyclecsn > tempDesc.recyclecsn) { + found = true; + rc = memcpy_s(&tempDesc, sizeof(TrObjDesc), desc, sizeof(TrObjDesc)); + securec_check(rc, "\0", "\0"); + } } systable_endscan(sd); heap_close(rbRel, AccessShareLock); + if(found) { + rc = memcpy_s(desc, sizeof(TrObjDesc), &tempDesc, sizeof(TrObjDesc)); + securec_check(rc, "\0", "\0"); + } return found; }