Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e5b86c9

Browse files
committed
Avoid unnecessary page-level SSI lock check in heap_insert().
As observed by Heikki, we need not conflict on heap page locks during an insert; heap page locks are only aggregated tuple locks, they don't imply locking "gaps" as index page locks do. So we can avoid some unnecessary conflicts, and also do the SSI check while not holding exclusive lock on the target buffer. Kevin Grittner, reviewed by Jeff Davis. Back-patch to 9.1.
1 parent 57d3dc2 commit e5b86c9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/backend/access/heap/heapam.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,17 +1921,22 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
19211921
else
19221922
heaptup = tup;
19231923

1924+
/*
1925+
* We're about to do the actual insert -- but check for conflict first,
1926+
* to avoid possibly having to roll back work we've just done.
1927+
*
1928+
* For a heap insert, we only need to check for table-level SSI locks.
1929+
* Our new tuple can't possibly conflict with existing tuple locks, and
1930+
* heap page locks are only consolidated versions of tuple locks; they do
1931+
* not lock "gaps" as index page locks do. So we don't need to identify
1932+
* a buffer before making the call.
1933+
*/
1934+
CheckForSerializableConflictIn(relation, NULL, InvalidBuffer);
1935+
19241936
/* Find buffer to insert this tuple into */
19251937
buffer = RelationGetBufferForTuple(relation, heaptup->t_len,
19261938
InvalidBuffer, options, bistate);
19271939

1928-
/*
1929-
* We're about to do the actual insert -- check for conflict at the
1930-
* relation or buffer level first, to avoid possibly having to roll back
1931-
* work we've just done.
1932-
*/
1933-
CheckForSerializableConflictIn(relation, NULL, buffer);
1934-
19351940
/* NO EREPORT(ERROR) from here till changes are logged */
19361941
START_CRIT_SECTION();
19371942

0 commit comments

Comments
 (0)