Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lm1J1-0007FE-TE for pgsql-hackers@arkaria.postgresql.org; Wed, 26 May 2021 21:43:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lm1Iz-00045f-Bo for pgsql-hackers@arkaria.postgresql.org; Wed, 26 May 2021 21:43:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lm1Iy-00045X-W9 for pgsql-hackers@lists.postgresql.org; Wed, 26 May 2021 21:43:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lm1Iw-0003J8-6P for pgsql-hackers@lists.postgresql.org; Wed, 26 May 2021 21:43:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14QLh2W91665198; Wed, 26 May 2021 17:43:02 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org cc: Robert Haas , Tomas Vondra Subject: Reducing the range of OIDs consumed by genbki.pl MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1665187.1622065367.0@sss.pgh.pa.us> Date: Wed, 26 May 2021 17:43:02 -0400 Message-ID: <1665197.1622065382@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1665187.1622065367.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable The attached patch stems from the conversation at [1]; I'm starting a new thread to avoid confusing the cfbot. Briefly, the idea is to allow reverting the change made in commit ab596105b to increase FirstBootstrapObjectId from 12000 to 13000, by teaching genbki.pl to assign OIDs independently in each catalog rather than from a single OID counter. Thus, the OIDs in this range will not be globally unique anymore, but only unique per-catalog. The aforesaid commit had to increase FirstBootstrapObjectId because as of HEAD, genbki.pl needs to consume OIDs up through 12035, overrunning the old limit of 12000. But moving up that limit seems a bit risky, cf [2]. It'd be better if we could avoid doing that. Since the OIDs in question are spread across several catalogs, allocating them per-catalog seems to fix the problem quite effectively. With the attached patch, the ending OID counters are GenbkiNextOid(pg_amop) =3D 10945 GenbkiNextOid(pg_amproc) =3D 10697 GenbkiNextOid(pg_cast) =3D 10230 GenbkiNextOid(pg_opclass) =3D 10164 so we have quite a lot of daylight before we'll ever approach 12000 again. Per-catalog OID uniqueness shouldn't be a problem here, because any code that's assuming global uniqueness is broken anyway; no such guarantee exists after the OID counter has wrapped around. So I propose shoehorning this into v14, to avoid shipping a release where FirstBootstrapObjectId has been bumped up. regards, tom lane [1] https://www.postgresql.org/message-id/flat/3737988.1618451008%40sss.pg= h.pa.us [2] https://www.postgresql.org/message-id/flat/CAGPqQf3JYTrTB1E1fu_zOGj%2B= rG_kwTfa3UcUYPfNZL9o1bcYNw%40mail.gmail.com ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="change-genbki-oid-allocation.patch"; charset="us-ascii" Content-ID: <1665187.1622065367.2@sss.pgh.pa.us> Content-Description: change-genbki-oid-allocation.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/bki.sgml b/doc/src/sgml/bki.sgml index b33e59d5e4..db1b3d5e9a 100644 --- a/doc/src/sgml/bki.sgml +++ b/doc/src/sgml/bki.sgml @@ -418,11 +418,11 @@ If genbki.pl needs to assign an OID to a catalog entry that does not have a manually-assigned OID, it will use a value= in - the range 10000—12999. The server's OID counter is set to 1300= 0 + the range 10000—11999. The server's OID counter is set to 1200= 0 at the start of a bootstrap run. Thus objects created by regular SQL commands during the later phases of bootstrap, such as objects create= d while running the information_schema.sql script, - receive OIDs of 13000 or above. + receive OIDs of 12000 or above. = diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 112b3affdf..e5e774267e 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -167,15 +167,17 @@ foreach my $oid (keys %oidcounts) die "found $found duplicate OID(s) in catalog data\n" if $found; = = -# Oids not specified in the input files are automatically assigned, +# OIDs not specified in the input files are automatically assigned, # starting at FirstGenbkiObjectId, extending up to FirstBootstrapObjectId= . +# We allow such OIDs to be assigned independently within each catalog. my $FirstGenbkiObjectId =3D Catalog::FindDefinedSymbol('access/transam.h', $include_path, 'FirstGenbkiObjectId'); my $FirstBootstrapObjectId =3D Catalog::FindDefinedSymbol('access/transam.h', $include_path, 'FirstBootstrapObjectId'); -my $GenbkiNextOid =3D $FirstGenbkiObjectId; +# Hash of next available OID, indexed by catalog name. +my %GenbkiNextOids; = = # Fetch some special data that we will substitute into the output file. @@ -563,8 +565,7 @@ EOM # Assign oid if oid column exists and no explicit assignment in row if ($attname eq "oid" and not defined $bki_values{$attname}) { - $bki_values{$attname} =3D $GenbkiNextOid; - $GenbkiNextOid++; + $bki_values{$attname} =3D assign_next_oid($catname); } = # Replace OID synonyms with OIDs per the appropriate lookup rule. @@ -669,11 +670,6 @@ foreach my $declaration (@index_decls) # last command in the BKI file: build the indexes declared above print $bki "build indices\n"; = -# check that we didn't overrun available OIDs -die - "genbki OID counter reached $GenbkiNextOid, overrunning FirstBootstrapO= bjectId\n" - if $GenbkiNextOid > $FirstBootstrapObjectId; - # Now generate system_constraints.sql = foreach my $c (@system_constraints) @@ -1081,6 +1077,25 @@ sub form_pg_type_symbol return $name . $arraystr . 'OID'; } = +# Assign an unused OID within the specified catalog. +sub assign_next_oid +{ + my $catname =3D shift; + + # Initialize, if no previous request for this catalog. + $GenbkiNextOids{$catname} =3D $FirstGenbkiObjectId + if !defined($GenbkiNextOids{$catname}); + + my $result =3D $GenbkiNextOids{$catname}++; + + # Check that we didn't overrun available OIDs + die + "genbki OID counter for $catname reached $result, overrunning FirstBoo= tstrapObjectId\n" + if $result >=3D $FirstBootstrapObjectId; + + return $result; +} + sub usage { die <