fix get_tuple

Offering: openGaussDev

More detail: fix get_tuple

Match-id-aed00ca9fb0d67624e5de7d2448c57a3baf26eb0
This commit is contained in:
openGaussDev
2022-03-07 16:16:05 +08:00
committed by yanghao
parent 1d66aded47
commit 884ea16aa3
2 changed files with 32 additions and 0 deletions

View File

@ -44,6 +44,7 @@
#include "commands/vacuum.h"
#include "utils/snapmgr.h"
#include "mb/pg_wchar.h"
#include "access/tableam.h"
#undef TOAST_DEBUG
@ -2900,3 +2901,32 @@ struct varlena * toast_pointer_fetch_data(TupleTableSlot* varSlot, Form_pg_attri
return toast_pointer_lob;
}
HeapTuple ctid_get_tuple(Relation relation, ItemPointer tid)
{
Buffer user_buf = InvalidBuffer;
HeapTuple tuple = NULL;
HeapTuple new_tuple = NULL;
TM_Result result;
/* alloc memory for old tuple and set tuple id */
tuple = (HeapTupleData *)heaptup_alloc(BLCKSZ);
tuple->t_data = (HeapTupleHeader)((char *)tuple + HEAPTUPLESIZE);
Assert(tid != NULL);
tuple->t_self = *tid;
if (tableam_tuple_fetch(relation, SnapshotAny, tuple, &user_buf, false, NULL)) {
result = HeapTupleSatisfiesUpdate(tuple, GetCurrentCommandId(true), user_buf, false);
if (result != TM_Ok) {
ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR), errmsg("The tuple is updated, please use 'for update'.")));
}
new_tuple = heapCopyTuple((HeapTuple)tuple, relation->rd_att, NULL);
ReleaseBuffer(user_buf);
} else {
heap_close(relation, NoLock);
ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR), errmsg("The tuple is not found")));
}
heap_freetuple(tuple);
return new_tuple;
}

View File

@ -296,5 +296,7 @@ inline Datum fetch_real_lob_if_need(Datum toast_pointer)
return ret;
}
extern HeapTuple ctid_get_tuple(Relation relation, ItemPointer tid);
#endif /* TUPTOASTER_H */