Offering: openGaussDev

More detail: fixbug toast update

Match-id-e1c8f8cebd825f9509c89dc60e25d62af8a06474
This commit is contained in:
openGaussDev
2022-03-04 10:25:48 +08:00
committed by yanghao
parent 0319403518
commit 8191e214c6
2 changed files with 10 additions and 21 deletions

View File

@ -5967,7 +5967,7 @@ int ExecCleanTargetListLength(List* targetlist)
return len;
}
HeapTuple get_tuple(Relation relation, ItemPointer tid)
HeapTuple get_tuple(Relation relation, ItemPointer tid, bool update_check)
{
Buffer user_buf = InvalidBuffer;
HeapTuple tuple = NULL;
@ -5981,7 +5981,7 @@ HeapTuple get_tuple(Relation relation, ItemPointer tid)
tuple->t_self = *tid;
if (heap_fetch(relation, SnapshotAny, tuple, &user_buf, false, NULL)) {
result = HeapTupleSatisfiesUpdate(tuple, GetCurrentCommandId(true), user_buf, false);
result = update_check ? HeapTupleSatisfiesUpdate(tuple, GetCurrentCommandId(true), user_buf, false) : TM_Ok;
if (result != TM_Ok) {
ereport(ERROR, (errcode(ERRCODE_SYSTEM_ERROR), errmsg("Failed to get tuple")));
}
@ -6013,7 +6013,7 @@ Datum fetch_lob_value_from_tuple(varatt_lob_pointer* lob_pointer, Oid update_oid
tuple_ctid.ip_blkid.bi_lo = lob_pointer->bi_lo;
tuple_ctid.ip_posid = lob_pointer->ip_posid;
Relation relation = heap_open(lob_pointer->relid, RowExclusiveLock);
HeapTuple origin_tuple = get_tuple(relation, &tuple_ctid);
HeapTuple origin_tuple = get_tuple(relation, &tuple_ctid, false);
if (!HeapTupleIsValid(origin_tuple)) {
ereport(ERROR,
(errcode(ERRCODE_CACHE_LOOKUP_FAILED),
@ -6113,20 +6113,9 @@ static bool ExecTargetList(List* targetlist, ExprContext* econtext, Datum* value
if (VARATT_IS_EXTERNAL_LOB(values[resind])) {
struct varatt_lob_pointer* lob_pointer = (varatt_lob_pointer*)(VARDATA_EXTERNAL(values[resind]));
bool is_null = false;
if (econtext->ecxt_scantuple != NULL) {
Oid update_oid = ((HeapTuple)(econtext->ecxt_scantuple->tts_tuple))->t_tableOid;
values[resind] = fetch_lob_value_from_tuple(lob_pointer, update_oid, &is_null, NULL);
} else {
ItemPointerData tuple_ctid;
tuple_ctid.ip_blkid.bi_hi = lob_pointer->bi_hi;
tuple_ctid.ip_blkid.bi_lo = lob_pointer->bi_lo;
tuple_ctid.ip_posid = lob_pointer->ip_posid;
Relation relation = heap_open(lob_pointer->relid, RowExclusiveLock);
HeapTuple origin_tuple = get_tuple(relation, &tuple_ctid);
Datum attr = fastgetattr(origin_tuple, lob_pointer->columid, relation->rd_att, &is_null);
values[resind] = attr;
heap_close(relation, NoLock);
}
Oid update_oid = econtext->ecxt_scantuple != NULL ?
((HeapTuple)(econtext->ecxt_scantuple->tts_tuple))->t_tableOid : InvalidOid;
values[resind] = fetch_lob_value_from_tuple(lob_pointer, update_oid, &is_null, NULL);
isnull[resind] = is_null;
}
}

View File

@ -247,10 +247,7 @@ extern HeapTuple toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc);
*/
extern Datum toast_flatten_tuple_attribute(Datum value, Oid typeId, int32 typeMod);
extern text* text_catenate_huge(text* t1, text* t2, Oid toastOid);
extern Oid get_toast_oid();
extern int64 calculate_huge_length(text* t);
extern Datum fetch_lob_value_from_tuple(varatt_lob_pointer* lob_pointer, Oid update_oid,
bool* is_null, bool* is_huge_clob = NULL);
/* ----------
* toast_compress_datum -
@ -280,7 +277,10 @@ extern bool toastrel_valueid_exists(Relation toastrel, Oid valueid);
extern varlena* toast_huge_write_datum_slice(struct varlena* attr1, struct varlena* attr2, int64 sliceoffset, int32 length);
extern varlena* toast_pointer_fetch_data(TupleTableSlot* varSlot, Form_pg_attribute attr, int varNumber);
bool create_toast_by_sid(Oid *toastOid);
extern Datum fetch_lob_value_from_tuple(varatt_lob_pointer* lob_pointer, Oid update_oid,
bool* is_null, bool* is_huge_clob = NULL);
extern bool create_toast_by_sid(Oid *toastOid);
extern Oid get_toast_oid();
#endif /* TUPTOASTER_H */