1414#include "postgres.h"
1515
1616#include "access/genam.h"
17- #include "access/heapam.h"
18- #include "access/tableam.h"
19- #include "access/sysattr.h"
2017#include "access/htup_details.h"
18+ #include "access/relation.h"
19+ #include "access/sysattr.h"
20+ #include "access/table.h"
21+ #include "access/tableam.h"
2122#include "access/xact.h"
2223#include "catalog/catalog.h"
2324#include "catalog/dependency.h"
@@ -3379,42 +3380,12 @@ GetTupleForTrigger(EState *estate,
33793380 }
33803381 else
33813382 {
3382- Page page ;
3383- ItemId lp ;
3384- Buffer buffer ;
3385- BufferHeapTupleTableSlot * boldslot ;
3386- HeapTuple tuple ;
3387-
3388- Assert (TTS_IS_BUFFERTUPLE (oldslot ));
3389- ExecClearTuple (oldslot );
3390- boldslot = (BufferHeapTupleTableSlot * ) oldslot ;
3391- tuple = & boldslot -> base .tupdata ;
3392-
3393- buffer = ReadBuffer (relation , ItemPointerGetBlockNumber (tid ));
3394-
33953383 /*
3396- * Although we already know this tuple is valid, we must lock the
3397- * buffer to ensure that no one has a buffer cleanup lock; otherwise
3398- * they might move the tuple while we try to copy it. But we can
3399- * release the lock before actually doing the heap_copytuple call,
3400- * since holding pin is sufficient to prevent anyone from getting a
3401- * cleanup lock they don't already hold.
3384+ * We expect the tuple to be present, thus very simple error handling
3385+ * suffices.
34023386 */
3403- LockBuffer (buffer , BUFFER_LOCK_SHARE );
3404-
3405- page = BufferGetPage (buffer );
3406- lp = PageGetItemId (page , ItemPointerGetOffsetNumber (tid ));
3407-
3408- Assert (ItemIdIsNormal (lp ));
3409-
3410- tuple -> t_data = (HeapTupleHeader ) PageGetItem (page , lp );
3411- tuple -> t_len = ItemIdGetLength (lp );
3412- tuple -> t_self = * tid ;
3413- tuple -> t_tableOid = RelationGetRelid (relation );
3414-
3415- LockBuffer (buffer , BUFFER_LOCK_UNLOCK );
3416-
3417- ExecStorePinnedBufferHeapTuple (tuple , oldslot , buffer );
3387+ if (!table_fetch_row_version (relation , tid , SnapshotAny , oldslot ))
3388+ elog (ERROR , "failed to fetch tuple for trigger" );
34183389 }
34193390
34203391 return true;
@@ -4193,8 +4164,6 @@ AfterTriggerExecute(EState *estate,
41934164 AfterTriggerShared evtshared = GetTriggerSharedData (event );
41944165 Oid tgoid = evtshared -> ats_tgoid ;
41954166 TriggerData LocTriggerData ;
4196- HeapTupleData tuple1 ;
4197- HeapTupleData tuple2 ;
41984167 HeapTuple rettuple ;
41994168 int tgindx ;
42004169 bool should_free_trig = false;
@@ -4271,19 +4240,12 @@ AfterTriggerExecute(EState *estate,
42714240 default :
42724241 if (ItemPointerIsValid (& (event -> ate_ctid1 )))
42734242 {
4274- Buffer buffer ;
4275-
42764243 LocTriggerData .tg_trigslot = ExecGetTriggerOldSlot (estate , relInfo );
42774244
4278- ItemPointerCopy (& (event -> ate_ctid1 ), & (tuple1 .t_self ));
4279- if (!heap_fetch (rel , SnapshotAny , & tuple1 , & buffer , NULL ))
4245+ if (!table_fetch_row_version (rel , & (event -> ate_ctid1 ), SnapshotAny , LocTriggerData .tg_trigslot ))
42804246 elog (ERROR , "failed to fetch tuple1 for AFTER trigger" );
4281- ExecStorePinnedBufferHeapTuple (& tuple1 ,
4282- LocTriggerData .tg_trigslot ,
4283- buffer );
42844247 LocTriggerData .tg_trigtuple =
4285- ExecFetchSlotHeapTuple (LocTriggerData .tg_trigslot , false,
4286- & should_free_trig );
4248+ ExecFetchSlotHeapTuple (LocTriggerData .tg_trigslot , false, & should_free_trig );
42874249 }
42884250 else
42894251 {
@@ -4295,19 +4257,12 @@ AfterTriggerExecute(EState *estate,
42954257 AFTER_TRIGGER_2CTID &&
42964258 ItemPointerIsValid (& (event -> ate_ctid2 )))
42974259 {
4298- Buffer buffer ;
4299-
43004260 LocTriggerData .tg_newslot = ExecGetTriggerNewSlot (estate , relInfo );
43014261
4302- ItemPointerCopy (& (event -> ate_ctid2 ), & (tuple2 .t_self ));
4303- if (!heap_fetch (rel , SnapshotAny , & tuple2 , & buffer , NULL ))
4262+ if (!table_fetch_row_version (rel , & (event -> ate_ctid2 ), SnapshotAny , LocTriggerData .tg_newslot ))
43044263 elog (ERROR , "failed to fetch tuple2 for AFTER trigger" );
4305- ExecStorePinnedBufferHeapTuple (& tuple2 ,
4306- LocTriggerData .tg_newslot ,
4307- buffer );
43084264 LocTriggerData .tg_newtuple =
4309- ExecFetchSlotHeapTuple (LocTriggerData .tg_newslot , false,
4310- & should_free_new );
4265+ ExecFetchSlotHeapTuple (LocTriggerData .tg_newslot , false, & should_free_new );
43114266 }
43124267 else
43134268 {
0 commit comments