aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/large_object/inv_api.c
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2024-09-12 21:45:42 +0900
committerFujii Masao <fujii@postgresql.org>2024-09-12 21:45:42 +0900
commit412229d197f894a01c163b9e9fdfec1a1855f7ab (patch)
tree076fe66d6b93aaf9ed8ce5c66a9b3342054abd2f /src/backend/storage/large_object/inv_api.c
parent23d0b48468b8971b35d713754f7d5ecf54e5f78f (diff)
downloadpostgresql-412229d197f894a01c163b9e9fdfec1a1855f7ab.tar.gz
postgresql-412229d197f894a01c163b9e9fdfec1a1855f7ab.zip
Deduplicate code in LargeObjectExists and myLargeObjectExists.
myLargeObjectExists() and LargeObjectExists() had nearly identical code, except for handling snapshots. This commit renames myLargeObjectExists() to LargeObjectExistsWithSnapshot() and refactors LargeObjectExists() to call it internally, reducing duplication. Author: Yugo Nagata Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/20240702163444.ab586f6075e502eb84f11b1a@sranhm.sraoss.co.jp
Diffstat (limited to 'src/backend/storage/large_object/inv_api.c')
-rw-r--r--src/backend/storage/large_object/inv_api.c40
1 files changed, 1 insertions, 39 deletions
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index f9510833241..afce51c1674 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -41,7 +41,6 @@
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_largeobject.h"
-#include "catalog/pg_largeobject_metadata.h"
#include "libpq/libpq-fs.h"
#include "miscadmin.h"
#include "storage/large_object.h"
@@ -124,43 +123,6 @@ close_lo_relation(bool isCommit)
/*
- * Same as pg_largeobject.c's LargeObjectExists(), except snapshot to
- * read with can be specified.
- */
-static bool
-myLargeObjectExists(Oid loid, Snapshot snapshot)
-{
- Relation pg_lo_meta;
- ScanKeyData skey[1];
- SysScanDesc sd;
- HeapTuple tuple;
- bool retval = false;
-
- ScanKeyInit(&skey[0],
- Anum_pg_largeobject_metadata_oid,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(loid));
-
- pg_lo_meta = table_open(LargeObjectMetadataRelationId,
- AccessShareLock);
-
- sd = systable_beginscan(pg_lo_meta,
- LargeObjectMetadataOidIndexId, true,
- snapshot, 1, skey);
-
- tuple = systable_getnext(sd);
- if (HeapTupleIsValid(tuple))
- retval = true;
-
- systable_endscan(sd);
-
- table_close(pg_lo_meta, AccessShareLock);
-
- return retval;
-}
-
-
-/*
* Extract data field from a pg_largeobject tuple, detoasting if needed
* and verifying that the length is sane. Returns data pointer (a bytea *),
* data length, and an indication of whether to pfree the data pointer.
@@ -279,7 +241,7 @@ inv_open(Oid lobjId, int flags, MemoryContext mcxt)
snapshot = GetActiveSnapshot();
/* Can't use LargeObjectExists here because we need to specify snapshot */
- if (!myLargeObjectExists(lobjId, snapshot))
+ if (!LargeObjectExistsWithSnapshot(lobjId, snapshot))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("large object %u does not exist", lobjId)));