A slightly misleading comment in GetNewObjectId()
Hi hackers,
While contemplating plans to use new kinds of OIDs in buffer tags, I
noticed $SUBJECT. It says:
* Check for wraparound of the OID counter. We *must* not return 0
* (InvalidOid); and as long as we have to check that, it seems a good
* idea to skip over everything below FirstNormalObjectId too. (This
* basically just avoids lots of collisions with bootstrap-assigned OIDs
* right after a wrap occurs, so as to avoid a possibly large number of
* iterations in GetNewOid.) Note we are relying on unsigned comparison.
That makes it sound like a mere optimisation, but since commit
8e18d04d4da user-created objects are not allowed to have OIDs below
that threshold. So I propose the attached tweak.
--
Thomas Munro
http://www.enterprisedb.com
Attachments:
0001-Improve-comment-in-GetNewObjectId.patchapplication/octet-stream; name=0001-Improve-comment-in-GetNewObjectId.patchDownload
From de4452ea50a4b51ca62f38faf4a95a3dc485edb8 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Thu, 16 Aug 2018 16:00:28 +1200
Subject: [PATCH] Improve comment in GetNewObjectId().
The previous comment gave the impression that skipping OIDs before
FirstNormalObjectId was merely an optimization to avoid stepping over
collisions in a known populated range. In fact other parts of
the system have been relying on this threshold to detect system-created
objects since commit 8e18d04d4da, so adjust the wording.
Thomas Munro
---
src/backend/access/transam/varsup.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index 394843f7e9..cede579d73 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -476,11 +476,9 @@ GetNewObjectId(void)
/*
* Check for wraparound of the OID counter. We *must* not return 0
- * (InvalidOid); and as long as we have to check that, it seems a good
- * idea to skip over everything below FirstNormalObjectId too. (This
- * basically just avoids lots of collisions with bootstrap-assigned OIDs
- * right after a wrap occurs, so as to avoid a possibly large number of
- * iterations in GetNewOid.) Note we are relying on unsigned comparison.
+ * (InvalidOid), and in normal operation we mustn't return anything below
+ * FirstNormalObjectId since that range is reserved for initdb (see
+ * IsCatalogClass()). Note we are relying on unsigned comparison.
*
* During initdb, we start the OID generator at FirstBootstrapObjectId, so
* we only wrap if before that point when in bootstrap or standalone mode.
--
2.17.0
Thomas Munro <thomas.munro@enterprisedb.com> writes:
That makes it sound like a mere optimisation, but since commit
8e18d04d4da user-created objects are not allowed to have OIDs below
that threshold. So I propose the attached tweak.
+1
regards, tom lane
On Thu, Aug 16, 2018 at 12:47 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Thomas Munro <thomas.munro@enterprisedb.com> writes:
That makes it sound like a mere optimisation, but since commit
8e18d04d4da user-created objects are not allowed to have OIDs below
that threshold. So I propose the attached tweak.+1
Looks good to me, too.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Thu, Aug 16, 2018 at 11:36:58AM -0400, Robert Haas wrote:
On Thu, Aug 16, 2018 at 12:47 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Thomas Munro <thomas.munro@enterprisedb.com> writes:
That makes it sound like a mere optimisation, but since commit
8e18d04d4da user-created objects are not allowed to have OIDs below
that threshold. So I propose the attached tweak.+1
Looks good to me, too.
+1 and thanks for pointing to the commit which makes this a reality.
--
Shawn Debnath