1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

Remove unnecessary overhead in backend's large-object operations.

Do read/write permissions checks at most once per large object descriptor,
not once per lo_read or lo_write call as before.  The repeated tests were
quite useless in the read case since the snapshot-based tests were
guaranteed to produce the same answer every time.  In the write case,
the extra tests could in principle detect revocation of write privileges
after a series of writes has started --- but there's a race condition there
anyway, since we'd check privileges before performing and certainly before
committing the write.  So there's no real advantage to checking every
single time, and we might as well redefine it as "only check the first
time".

On the same reasoning, remove the LargeObjectExists checks in inv_write
and inv_truncate.  We already checked existence when the descriptor was
opened, and checking again doesn't provide any real increment of safety
that would justify the cost.
This commit is contained in:
Tom Lane
2012-10-09 16:38:00 -04:00
parent 2d8c81ac86
commit 7e0cce0265
3 changed files with 92 additions and 93 deletions

View File

@@ -27,6 +27,10 @@
* offset is the current seek offset within the LO
* flags contains some flag bits
*
* NOTE: in current usage, flag bit IFS_RDLOCK is *always* set, and we don't
* bother to test for it. Permission checks are made at first read or write
* attempt, not during inv_open(), so we have other bits to remember that.
*
* NOTE: before 7.1, we also had to store references to the separate table
* and index of a specific large object. Now they all live in pg_largeobject
* and are accessed via a common relation descriptor.
@@ -38,11 +42,13 @@ typedef struct LargeObjectDesc
Snapshot snapshot; /* snapshot to use */
SubTransactionId subid; /* owning subtransaction ID */
uint64 offset; /* current seek pointer */
int flags; /* locking info, etc */
int flags; /* see flag bits below */
/* flag bits: */
#define IFS_RDLOCK (1 << 0)
#define IFS_WRLOCK (1 << 1)
/* bits in flags: */
#define IFS_RDLOCK (1 << 0) /* LO was opened for reading */
#define IFS_WRLOCK (1 << 1) /* LO was opened for writing */
#define IFS_RD_PERM_OK (1 << 2) /* read permission has been verified */
#define IFS_WR_PERM_OK (1 << 3) /* write permission has been verified */
} LargeObjectDesc;