Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit412229d

Browse files
committed
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 NagataReviewed-by: Fujii MasaoDiscussion:https://postgr.es/m/20240702163444.ab586f6075e502eb84f11b1a@sranhm.sraoss.co.jp
1 parent23d0b48 commit412229d

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

‎src/backend/catalog/pg_largeobject.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*/
1515
#include"postgres.h"
1616

17-
#include"access/genam.h"
18-
#include"access/htup_details.h"
1917
#include"access/table.h"
2018
#include"catalog/catalog.h"
2119
#include"catalog/indexing.h"
@@ -153,6 +151,15 @@ LargeObjectDrop(Oid loid)
153151
*/
154152
bool
155153
LargeObjectExists(Oidloid)
154+
{
155+
returnLargeObjectExistsWithSnapshot(loid,NULL);
156+
}
157+
158+
/*
159+
* Same as LargeObjectExists(), except snapshot to read with can be specified.
160+
*/
161+
bool
162+
LargeObjectExistsWithSnapshot(Oidloid,Snapshotsnapshot)
156163
{
157164
Relationpg_lo_meta;
158165
ScanKeyDataskey[1];
@@ -170,7 +177,7 @@ LargeObjectExists(Oid loid)
170177

171178
sd=systable_beginscan(pg_lo_meta,
172179
LargeObjectMetadataOidIndexId, true,
173-
NULL,1,skey);
180+
snapshot,1,skey);
174181

175182
tuple=systable_getnext(sd);
176183
if (HeapTupleIsValid(tuple))

‎src/backend/storage/large_object/inv_api.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include"catalog/indexing.h"
4242
#include"catalog/objectaccess.h"
4343
#include"catalog/pg_largeobject.h"
44-
#include"catalog/pg_largeobject_metadata.h"
4544
#include"libpq/libpq-fs.h"
4645
#include"miscadmin.h"
4746
#include"storage/large_object.h"
@@ -123,43 +122,6 @@ close_lo_relation(bool isCommit)
123122
}
124123

125124

126-
/*
127-
* Same as pg_largeobject.c's LargeObjectExists(), except snapshot to
128-
* read with can be specified.
129-
*/
130-
staticbool
131-
myLargeObjectExists(Oidloid,Snapshotsnapshot)
132-
{
133-
Relationpg_lo_meta;
134-
ScanKeyDataskey[1];
135-
SysScanDescsd;
136-
HeapTupletuple;
137-
boolretval= false;
138-
139-
ScanKeyInit(&skey[0],
140-
Anum_pg_largeobject_metadata_oid,
141-
BTEqualStrategyNumber,F_OIDEQ,
142-
ObjectIdGetDatum(loid));
143-
144-
pg_lo_meta=table_open(LargeObjectMetadataRelationId,
145-
AccessShareLock);
146-
147-
sd=systable_beginscan(pg_lo_meta,
148-
LargeObjectMetadataOidIndexId, true,
149-
snapshot,1,skey);
150-
151-
tuple=systable_getnext(sd);
152-
if (HeapTupleIsValid(tuple))
153-
retval= true;
154-
155-
systable_endscan(sd);
156-
157-
table_close(pg_lo_meta,AccessShareLock);
158-
159-
returnretval;
160-
}
161-
162-
163125
/*
164126
* Extract data field from a pg_largeobject tuple, detoasting if needed
165127
* and verifying that the length is sane. Returns data pointer (a bytea *),
@@ -279,7 +241,7 @@ inv_open(Oid lobjId, int flags, MemoryContext mcxt)
279241
snapshot=GetActiveSnapshot();
280242

281243
/* Can't use LargeObjectExists here because we need to specify snapshot */
282-
if (!myLargeObjectExists(lobjId,snapshot))
244+
if (!LargeObjectExistsWithSnapshot(lobjId,snapshot))
283245
ereport(ERROR,
284246
(errcode(ERRCODE_UNDEFINED_OBJECT),
285247
errmsg("large object %u does not exist",lobjId)));

‎src/include/catalog/pg_largeobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include"catalog/genbki.h"
2222
#include"catalog/pg_largeobject_d.h"
23+
#include"utils/snapshot.h"
2324

2425
/* ----------------
2526
*pg_largeobject definition. cpp turns this into
@@ -49,5 +50,6 @@ DECLARE_UNIQUE_INDEX_PKEY(pg_largeobject_loid_pn_index, 2683, LargeObjectLOidPNI
4950
externOidLargeObjectCreate(Oidloid);
5051
externvoidLargeObjectDrop(Oidloid);
5152
externboolLargeObjectExists(Oidloid);
53+
externboolLargeObjectExistsWithSnapshot(Oidloid,Snapshotsnapshot);
5254

5355
#endif/* PG_LARGEOBJECT_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp