*/
#include "postgres.h"
-#include "access/genam.h"
-#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
*/
bool
LargeObjectExists(Oid loid)
+{
+ return LargeObjectExistsWithSnapshot(loid, NULL);
+}
+
+/*
+ * Same as LargeObjectExists(), except snapshot to read with can be specified.
+ */
+bool
+LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot)
{
Relation pg_lo_meta;
ScanKeyData skey[1];
sd = systable_beginscan(pg_lo_meta,
LargeObjectMetadataOidIndexId, true,
- NULL, 1, skey);
+ snapshot, 1, skey);
tuple = systable_getnext(sd);
if (HeapTupleIsValid(tuple))
#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"
}
-/*
- * 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 *),
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)));
#include "catalog/genbki.h"
#include "catalog/pg_largeobject_d.h"
+#include "utils/snapshot.h"
/* ----------------
* pg_largeobject definition. cpp turns this into
extern Oid LargeObjectCreate(Oid loid);
extern void LargeObjectDrop(Oid loid);
extern bool LargeObjectExists(Oid loid);
+extern bool LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot);
#endif /* PG_LARGEOBJECT_H */