14
14
#include "postgres.h"
15
15
16
16
#include "access/genam.h"
17
- #include "access/heapam.h"
18
- #include "access/tableam.h"
19
- #include "access/sysattr.h"
20
17
#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"
21
22
#include "access/xact.h"
22
23
#include "catalog/catalog.h"
23
24
#include "catalog/dependency.h"
@@ -3379,42 +3380,12 @@ GetTupleForTrigger(EState *estate,
3379
3380
}
3380
3381
else
3381
3382
{
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
-
3395
3383
/*
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.
3402
3386
*/
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" );
3418
3389
}
3419
3390
3420
3391
return true;
@@ -4193,8 +4164,6 @@ AfterTriggerExecute(EState *estate,
4193
4164
AfterTriggerShared evtshared = GetTriggerSharedData (event );
4194
4165
Oid tgoid = evtshared -> ats_tgoid ;
4195
4166
TriggerData LocTriggerData ;
4196
- HeapTupleData tuple1 ;
4197
- HeapTupleData tuple2 ;
4198
4167
HeapTuple rettuple ;
4199
4168
int tgindx ;
4200
4169
bool should_free_trig = false;
@@ -4271,19 +4240,12 @@ AfterTriggerExecute(EState *estate,
4271
4240
default :
4272
4241
if (ItemPointerIsValid (& (event -> ate_ctid1 )))
4273
4242
{
4274
- Buffer buffer ;
4275
-
4276
4243
LocTriggerData .tg_trigslot = ExecGetTriggerOldSlot (estate , relInfo );
4277
4244
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 ))
4280
4246
elog (ERROR , "failed to fetch tuple1 for AFTER trigger" );
4281
- ExecStorePinnedBufferHeapTuple (& tuple1 ,
4282
- LocTriggerData .tg_trigslot ,
4283
- buffer );
4284
4247
LocTriggerData .tg_trigtuple =
4285
- ExecFetchSlotHeapTuple (LocTriggerData .tg_trigslot , false,
4286
- & should_free_trig );
4248
+ ExecFetchSlotHeapTuple (LocTriggerData .tg_trigslot , false, & should_free_trig );
4287
4249
}
4288
4250
else
4289
4251
{
@@ -4295,19 +4257,12 @@ AfterTriggerExecute(EState *estate,
4295
4257
AFTER_TRIGGER_2CTID &&
4296
4258
ItemPointerIsValid (& (event -> ate_ctid2 )))
4297
4259
{
4298
- Buffer buffer ;
4299
-
4300
4260
LocTriggerData .tg_newslot = ExecGetTriggerNewSlot (estate , relInfo );
4301
4261
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 ))
4304
4263
elog (ERROR , "failed to fetch tuple2 for AFTER trigger" );
4305
- ExecStorePinnedBufferHeapTuple (& tuple2 ,
4306
- LocTriggerData .tg_newslot ,
4307
- buffer );
4308
4264
LocTriggerData .tg_newtuple =
4309
- ExecFetchSlotHeapTuple (LocTriggerData .tg_newslot , false,
4310
- & should_free_new );
4265
+ ExecFetchSlotHeapTuple (LocTriggerData .tg_newslot , false, & should_free_new );
4311
4266
}
4312
4267
else
4313
4268
{
0 commit comments