summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-09-16 14:47:27 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-09-16 14:47:27 -0400
commite5b86c93b66b5caeb25a65bae26b04fc7a068957 (patch)
tree4b5e7b8f78b609785ae4be2f3c463f8303649e49
parent57d3dc2035fe8267e877620eddc3823360c7878f (diff)
downloadpostgresql-e5b86c93b66b5caeb25a65bae26b04fc7a068957.tar.gz
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.
-rw-r--r--src/backend/access/heap/heapam.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 450bb15ff8..cc8b45fd48 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -1921,17 +1921,22 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
else
heaptup = tup;
+ /*
+ * We're about to do the actual insert -- but check for conflict first,
+ * to avoid possibly having to roll back work we've just done.
+ *
+ * For a heap insert, we only need to check for table-level SSI locks.
+ * Our new tuple can't possibly conflict with existing tuple locks, and
+ * heap page locks are only consolidated versions of tuple locks; they do
+ * not lock "gaps" as index page locks do. So we don't need to identify
+ * a buffer before making the call.
+ */
+ CheckForSerializableConflictIn(relation, NULL, InvalidBuffer);
+
/* Find buffer to insert this tuple into */
buffer = RelationGetBufferForTuple(relation, heaptup->t_len,
InvalidBuffer, options, bistate);
- /*
- * We're about to do the actual insert -- check for conflict at the
- * relation or buffer level first, to avoid possibly having to roll back
- * work we've just done.
- */
- CheckForSerializableConflictIn(relation, NULL, buffer);
-
/* NO EREPORT(ERROR) from here till changes are logged */
START_CRIT_SECTION();