pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Add primary keys to system catalogs
Date: Thu, 21 Jan 2021 12:15:56 -0500
Message-ID: <906053.1611249356@sss.pgh.pa.us> (raw)
In-Reply-To: <4b5a1272-b6ea-d2e0-9b8f-3bec20109eb5@2ndquadrant.com>
References: <dc5f44d9-5ec1-a596-0251-dadadcdede98@2ndquadrant.com>
	<348f3158-bf7e-c5f0-f33b-9e552e3d5481@2ndquadrant.com>
	<266949.1610921277@sss.pgh.pa.us>
	<4b5a1272-b6ea-d2e0-9b8f-3bec20109eb5@2ndquadrant.com>

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> 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

Attachments:

catalog-primary-keys-comments.patch (text/x-diff, 3.2K) download 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 FirstBootstrapObjectId\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 catalog's + * primary key; currently this is only cosmetically different from a regular + * unique index. By convention, we usually make a catalog's OID column its + * pkey, if it has one.) The first two arguments are the index's name and + * 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 actual 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 = 0 OR refobjid = 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 views. do $$ declare relnm text; reloid oid; diff --git a/src/test/regress/sql/misc_sanity.sql b/src/test/regress/sql/misc_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 = 0 OR refobjid = 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 views. do $$ declare relnm text;

view thread (39+ messages)  latest in thread

Message-ID: <906053.1611249356@sss.pgh.pa.us>
Permalink:  ../906053.1611249356@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/906053.1611249356@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, peter.eisentraut@2ndquadrant.com
  Subject: Re: Add primary keys to system catalogs
  In-Reply-To: <906053.1611249356@sss.pgh.pa.us>
  References: <dc5f44d9-5ec1-a596-0251-dadadcdede98@2ndquadrant.com> <348f3158-bf7e-c5f0-f33b-9e552e3d5481@2ndquadrant.com> <266949.1610921277@sss.pgh.pa.us> <4b5a1272-b6ea-d2e0-9b8f-3bec20109eb5@2ndquadrant.com> <906053.1611249356@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox