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 1l2dZ3-0003j0-7d for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 17:16:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2dYz-0003Yq-Tb for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jan 2021 17:16:05 +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 1l2dYz-0003Yj-MN for pgsql-hackers@lists.postgresql.org; Thu, 21 Jan 2021 17:16:05 +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 1l2dYt-0001qd-2t for pgsql-hackers@postgresql.org; Thu, 21 Jan 2021 17:16:04 +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 10LHFufk906054; Thu, 21 Jan 2021 12:15:56 -0500 From: Tom Lane To: Peter Eisentraut cc: pgsql-hackers Subject: Re: Add primary keys to system catalogs In-reply-to: <4b5a1272-b6ea-d2e0-9b8f-3bec20109eb5@2ndquadrant.com> References: <348f3158-bf7e-c5f0-f33b-9e552e3d5481@2ndquadrant.com> <266949.1610921277@sss.pgh.pa.us> <4b5a1272-b6ea-d2e0-9b8f-3bec20109eb5@2ndquadrant.com> Comments: In-reply-to Peter Eisentraut message dated "Thu, 21 Jan 2021 10:40:52 +0100" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <905899.1611249154.0@sss.pgh.pa.us> Date: Thu, 21 Jan 2021 12:15:56 -0500 Message-ID: <906053.1611249356@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <905899.1611249154.1@sss.pgh.pa.us> Peter Eisentraut writes: > On 2021-01-17 23:07, Tom Lane wrote: >> I've reviewed this patch. It looks pretty solid to me, with a couple >> trivial nits as mentioned below, and one bigger thing that's perhaps >> in the category of bikeshedding. Namely, do we really want to prefer >> using the OID indexes as the primary keys? > I chose this because the notional foreign keys point to the OID. > If you design some basic business database with customer IDs, product > IDs, etc., you'd also usually make the ID the primary key, even if you > have, say, a unique constraint on the product name. But this is of > course a matter of taste to some degree. Fair enough. As I said upthread, I just wanted to be sure we'd considered the alternative. I'm content to use the OIDs as pkeys, although I think that decision should be explicitly recorded somewhere (cf attachment). >> The contents of system_constraints.sql seem pretty randomly ordered, >> and I bet the order isn't stable across machines. > They follow the order in which the catalogs are processed byt genbki.pl. Looking closer, I see the data structure is an array not a hash, so I withdraw the concern about instability. After reading the patch again, I have a couple more nits about comments, which I'll just present as a proposed delta patch. Otherwise it's good. I'll mark it RFC. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="catalog-primary-keys-comments.patch"; charset="us-ascii" Content-ID: <905899.1611249154.2@sss.pgh.pa.us> Content-Description: catalog-primary-keys-comments.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 6747996ce3..b68c1752c0 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -663,6 +663,8 @@ die "genbki OID counter reached $GenbkiNextOid, overrunning FirstBootstrapO= bjectId\n" if $GenbkiNextOid > $FirstBootstrapObjectId; = +# Now generate system_constraints.sql + foreach my $c (@system_constraints) { print $constraints $c, "\n"; diff --git a/src/include/catalog/genbki.h b/src/include/catalog/genbki.h index 296765d987..5d05fafb5d 100644 --- a/src/include/catalog/genbki.h +++ b/src/include/catalog/genbki.h @@ -55,12 +55,15 @@ #define DECLARE_TOAST(name,toastoid,indexoid) extern int no_such_variable = /* - * These lines processed by genbki.pl to create the statements + * These lines are processed by genbki.pl to create the statements * the bootstrap parser will turn into DefineIndex calls. * - * The keyword is DECLARE_INDEX or DECLARE_UNIQUE_INDEX or DECLARE_UNIQUE= _INDEX_PKEY. The first two - * arguments are the index name and OID, the rest is much like a standard - * 'create index' SQL command. + * The keyword is DECLARE_INDEX or DECLARE_UNIQUE_INDEX or + * DECLARE_UNIQUE_INDEX_PKEY. ("PKEY" marks the index as being the catal= og's + * primary key; currently this is only cosmetically different from a regu= lar + * unique index. By convention, we usually make a catalog's OID column i= ts + * pkey, if it has one.) The first two arguments are the index's name an= d + * OID, the rest is much like a standard 'create index' SQL command. * * For each index, we also provide a #define for its OID. References to * the index in the C code should always use these #defines, not the actu= al diff --git a/src/test/regress/expected/misc_sanity.out b/src/test/regress/= expected/misc_sanity.out index ae85817c61..9ebe28a78d 100644 --- a/src/test/regress/expected/misc_sanity.out +++ b/src/test/regress/expected/misc_sanity.out @@ -43,6 +43,9 @@ WHERE refclassid =3D 0 OR refobjid =3D 0 OR -- whatever OID the test is complaining about must have been added later -- in initdb, where it intentionally isn't pinned. Legitimate exceptions -- to that rule are listed in the comments in setup_depend(). +-- Currently, pg_rewrite is also listed by this check, even though it is +-- covered by setup_depend(). That happens because there are no rules in +-- the pinned data, but initdb creates some intentionally-not-pinned view= s. do $$ declare relnm text; reloid oid; diff --git a/src/test/regress/sql/misc_sanity.sql b/src/test/regress/sql/m= isc_sanity.sql index ea80cf1f10..9699f5cc3b 100644 --- a/src/test/regress/sql/misc_sanity.sql +++ b/src/test/regress/sql/misc_sanity.sql @@ -44,6 +44,9 @@ WHERE refclassid =3D 0 OR refobjid =3D 0 OR -- whatever OID the test is complaining about must have been added later -- in initdb, where it intentionally isn't pinned. Legitimate exceptions -- to that rule are listed in the comments in setup_depend(). +-- Currently, pg_rewrite is also listed by this check, even though it is +-- covered by setup_depend(). That happens because there are no rules in +-- the pinned data, but initdb creates some intentionally-not-pinned view= s. = do $$ declare relnm text; ------- =_aaaaaaaaaa0--