From a236dd9536bd4624b259759e08cb2b8d4585ab0f Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Sun, 14 Nov 2004 02:04:14 +0000 Subject: [PATCH] There is no need for ReadBuffer() call sites to check that the returned buffer is valid, as ReadBuffer() will elog on error. Most of the call sites of ReadBuffer() got this right, but this patch fixes those call sites that did not. --- src/backend/access/heap/heapam.c | 32 +------------------------------- src/backend/commands/analyze.c | 4 +--- src/backend/commands/sequence.c | 9 +-------- src/backend/commands/trigger.c | 5 +---- 4 files changed, 4 insertions(+), 46 deletions(-) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index c2d4395807..f8331d7394 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.180 2004/10/26 16:05:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.181 2004/11/14 02:04:12 neilc Exp $ * * * INTERFACE ROUTINES @@ -191,8 +191,6 @@ heapgettup(Relation relation, *buffer = ReleaseAndReadBuffer(*buffer, relation, ItemPointerGetBlockNumber(tid)); - if (!BufferIsValid(*buffer)) - elog(ERROR, "ReadBuffer failed"); LockBuffer(*buffer, BUFFER_LOCK_SHARE); @@ -226,8 +224,6 @@ heapgettup(Relation relation, *buffer = ReleaseAndReadBuffer(*buffer, relation, page); - if (!BufferIsValid(*buffer)) - elog(ERROR, "ReadBuffer failed"); LockBuffer(*buffer, BUFFER_LOCK_SHARE); @@ -266,8 +262,6 @@ heapgettup(Relation relation, *buffer = ReleaseAndReadBuffer(*buffer, relation, page); - if (!BufferIsValid(*buffer)) - elog(ERROR, "ReadBuffer failed"); LockBuffer(*buffer, BUFFER_LOCK_SHARE); @@ -360,8 +354,6 @@ heapgettup(Relation relation, *buffer = ReleaseAndReadBuffer(*buffer, relation, page); - if (!BufferIsValid(*buffer)) - elog(ERROR, "ReadBuffer failed"); LockBuffer(*buffer, BUFFER_LOCK_SHARE); dp = (Page) BufferGetPage(*buffer); @@ -941,11 +933,6 @@ heap_release_fetch(Relation relation, buffer = ReleaseAndReadBuffer(*userbuf, relation, ItemPointerGetBlockNumber(tid)); - if (!BufferIsValid(buffer)) - elog(ERROR, "ReadBuffer(\"%s\", %lu) failed", - RelationGetRelationName(relation), - (unsigned long) ItemPointerGetBlockNumber(tid)); - /* * Need share lock on buffer to examine tuple commit status. */ @@ -1049,14 +1036,7 @@ heap_get_latest_tid(Relation relation, * get the buffer from the relation descriptor Note that this does a * buffer pin. */ - buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); - - if (!BufferIsValid(buffer)) - elog(ERROR, "ReadBuffer(\"%s\", %lu) failed", - RelationGetRelationName(relation), - (unsigned long) ItemPointerGetBlockNumber(tid)); - LockBuffer(buffer, BUFFER_LOCK_SHARE); /* @@ -1304,10 +1284,6 @@ heap_delete(Relation relation, ItemPointer tid, Assert(ItemPointerIsValid(tid)); buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); - - if (!BufferIsValid(buffer)) - elog(ERROR, "ReadBuffer failed"); - LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); dp = (PageHeader) BufferGetPage(buffer); @@ -1528,8 +1504,6 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup, Assert(ItemPointerIsValid(otid)); buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(otid)); - if (!BufferIsValid(buffer)) - elog(ERROR, "ReadBuffer failed"); LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); dp = (PageHeader) BufferGetPage(buffer); @@ -1863,10 +1837,6 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer, int result; *buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); - - if (!BufferIsValid(*buffer)) - elog(ERROR, "ReadBuffer failed"); - LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); dp = (PageHeader) BufferGetPage(*buffer); diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 872edc4298..3157d1dfd6 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.78 2004/10/26 16:05:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.79 2004/11/14 02:04:13 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -811,8 +811,6 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows, * tuples. */ targbuffer = ReadBuffer(onerel, targblock); - if (!BufferIsValid(targbuffer)) - elog(ERROR, "ReadBuffer failed"); LockBuffer(targbuffer, BUFFER_LOCK_SHARE); targpage = BufferGetPage(targbuffer); maxoffset = PageGetMaxOffsetNumber(targpage); diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index de71560d1d..98763cf0b2 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.117 2004/09/16 16:58:28 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.118 2004/11/14 02:04:14 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -192,10 +192,6 @@ DefineSequence(CreateSeqStmt *seq) /* Initialize first page of relation with special magic number */ buf = ReadBuffer(rel, P_NEW); - - if (!BufferIsValid(buf)) - elog(ERROR, "ReadBuffer failed"); - Assert(BufferGetBlockNumber(buf) == 0); page = (PageHeader) BufferGetPage(buf); @@ -850,9 +846,6 @@ read_info(SeqTable elm, Relation rel, Buffer *buf) Form_pg_sequence seq; *buf = ReadBuffer(rel, 0); - if (!BufferIsValid(*buf)) - elog(ERROR, "ReadBuffer failed"); - LockBuffer(*buf, BUFFER_LOCK_EXCLUSIVE); page = (PageHeader) BufferGetPage(*buf); diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index a477fc8469..62071a6878 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.174 2004/10/30 20:52:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.175 2004/11/14 02:04:14 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -1625,9 +1625,6 @@ ltrmark:; buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); - if (!BufferIsValid(buffer)) - elog(ERROR, "ReadBuffer failed"); - dp = (PageHeader) BufferGetPage(buffer); lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid));