8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.120 2001/06/27 23:31:38 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.121 2001/06/29 21:08:23 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
@@ -202,8 +202,7 @@ heapgettup(Relation relation,
202
202
203
203
* buffer = ReleaseAndReadBuffer (* buffer ,
204
204
relation ,
205
- ItemPointerGetBlockNumber (tid ),
206
- false);
205
+ ItemPointerGetBlockNumber (tid ));
207
206
if (!BufferIsValid (* buffer ))
208
207
elog (ERROR , "heapgettup: failed ReadBuffer" );
209
208
@@ -238,8 +237,7 @@ heapgettup(Relation relation,
238
237
239
238
* buffer = ReleaseAndReadBuffer (* buffer ,
240
239
relation ,
241
- page ,
242
- false);
240
+ page );
243
241
if (!BufferIsValid (* buffer ))
244
242
elog (ERROR , "heapgettup: failed ReadBuffer" );
245
243
@@ -280,8 +278,7 @@ heapgettup(Relation relation,
280
278
281
279
* buffer = ReleaseAndReadBuffer (* buffer ,
282
280
relation ,
283
- page ,
284
- false);
281
+ page );
285
282
if (!BufferIsValid (* buffer ))
286
283
elog (ERROR , "heapgettup: failed ReadBuffer" );
287
284
@@ -374,8 +371,7 @@ heapgettup(Relation relation,
374
371
375
372
* buffer = ReleaseAndReadBuffer (* buffer ,
376
373
relation ,
377
- page ,
378
- false);
374
+ page );
379
375
if (!BufferIsValid (* buffer ))
380
376
elog (ERROR , "heapgettup: failed ReadBuffer" );
381
377
@@ -1088,8 +1084,8 @@ heap_insert(Relation relation, HeapTuple tup)
1088
1084
heap_tuple_toast_attrs (relation , tup , NULL );
1089
1085
#endif
1090
1086
1091
- /* Find buffer for this tuple */
1092
- buffer = RelationGetBufferForTuple (relation , tup -> t_len , 0 );
1087
+ /* Find buffer to insert this tuple into */
1088
+ buffer = RelationGetBufferForTuple (relation , tup -> t_len , InvalidBuffer );
1093
1089
1094
1090
/* NO ELOG(ERROR) from here till changes are logged */
1095
1091
START_CRIT_SECTION ();
@@ -1501,18 +1497,16 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
1501
1497
* buffer locks on both old and new pages. To avoid deadlock against
1502
1498
* some other backend trying to get the same two locks in the other
1503
1499
* order, we must be consistent about the order we get the locks in.
1504
- * We use the rule "lock the higher -numbered page of the relation
1500
+ * We use the rule "lock the lower -numbered page of the relation
1505
1501
* first". To implement this, we must do RelationGetBufferForTuple
1506
- * while not holding the lock on the old page, and we must tell it
1507
- * to give us a page beyond the old page .
1502
+ * while not holding the lock on the old page, and we must rely on it
1503
+ * to get the locks on both pages in the correct order .
1508
1504
*/
1509
1505
if (newtupsize > pagefree )
1510
1506
{
1511
1507
/* Assume there's no chance to put newtup on same page. */
1512
1508
newbuf = RelationGetBufferForTuple (relation , newtup -> t_len ,
1513
- BufferGetBlockNumber (buffer ) + 1 );
1514
- /* Now reacquire lock on old tuple's page. */
1515
- LockBuffer (buffer , BUFFER_LOCK_EXCLUSIVE );
1509
+ buffer );
1516
1510
}
1517
1511
else
1518
1512
{
@@ -1529,8 +1523,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
1529
1523
*/
1530
1524
LockBuffer (buffer , BUFFER_LOCK_UNLOCK );
1531
1525
newbuf = RelationGetBufferForTuple (relation , newtup -> t_len ,
1532
- BufferGetBlockNumber (buffer ) + 1 );
1533
- LockBuffer (buffer , BUFFER_LOCK_EXCLUSIVE );
1526
+ buffer );
1534
1527
}
1535
1528
else
1536
1529
{
@@ -1550,7 +1543,8 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
1550
1543
1551
1544
/*
1552
1545
* At this point newbuf and buffer are both pinned and locked,
1553
- * and newbuf has enough space for the new tuple.
1546
+ * and newbuf has enough space for the new tuple. If they are
1547
+ * the same buffer, only one pin is held.
1554
1548
*/
1555
1549
1556
1550
/* NO ELOG(ERROR) from here till changes are logged */
0 commit comments