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 1oQwim-0001u4-91 for pgsql-general@arkaria.postgresql.org; Wed, 24 Aug 2022 20:11:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oQwil-0004CN-56 for pgsql-general@arkaria.postgresql.org; Wed, 24 Aug 2022 20:11:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQwik-0004CD-Nk for pgsql-general@lists.postgresql.org; Wed, 24 Aug 2022 20:11:26 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oQwig-0007P8-9K for pgsql-general@lists.postgresql.org; Wed, 24 Aug 2022 20:11:26 +0000 Received: by mail-pl1-x632.google.com with SMTP id p13so5253484pld.6 for ; Wed, 24 Aug 2022 13:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=to:date:message-id:subject:mime-version:from:from:to:cc; bh=KsaML6Jr3fIt9CCCris6b29qPPgMgV6q3CBClE5ZbiY=; b=iMEgkv2HXsL/gMvI0U0MGeFroqjostryk+2SuBAFIgX2uCU5gFeOxRmevnju1yA8HC UAGoaeuwMp8AarBYX2iKqG7lxWIOhNa6YMCpHSt4mArlg0jYsxMM1f/kBHQ+uWdbMIhP TnmtjKigCZ8g+c0yY8FAWGkpHKbFPA4cZIW0M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc; bh=KsaML6Jr3fIt9CCCris6b29qPPgMgV6q3CBClE5ZbiY=; b=oj/UXt+xaaOdsVdHyDYy7hhx6Vim22M4nYrqYdiMtIUviulqlROSCW6YwyL/lIl6KM kMXURW/QN0HG84MfpLuJ61G/pj4mg+g/Z67cLluNNfyaenQVBduEpWUS47qtWwiS5JCJ cc7hO09G0EYYRxUBUYSm7slpVFEU3DdJuxG2sAeQkuCz5YhVCjPTpS7ugGw/5txNNBzG x+yaC6pf77vFXzj+enUBRy2BRAsQfguS21VhiQqBAZxnBZl3K3ZpbN8XId8I61jG6zwV /gPMiG4PKfIhlEK98nnz3ivi9BeCMwv3jRO3Y4dd1wTa8K59B6LD9EeWhqD3US1F2ba3 VUPQ== X-Gm-Message-State: ACgBeo1XNXTsZQ8kfhPtPBkpp2trJAlOHe55x1ogFFtz33x4DrpvODJH gv6skNTIBOwtH5Frc/p64M54GsZsPsH9/g== X-Google-Smtp-Source: AA6agR4lnEXOPT+5/eBwDEXDT2KkXQjIi9qo32GhS5cAagOgUWnxdAv/2/wbwtsp/gzuWET16e1djA== X-Received: by 2002:a17:90a:e586:b0:1fa:d28b:ab9b with SMTP id g6-20020a17090ae58600b001fad28bab9bmr792630pjz.47.1661371879332; Wed, 24 Aug 2022 13:11:19 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:71c6:9287:90fc:5fee]) by smtp.gmail.com with ESMTPSA id o20-20020a17090a421400b001fabc3da687sm1789179pjg.51.2022.08.24.13.11.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Aug 2022 13:11:18 -0700 (PDT) From: Bryn Llewellyn Content-Type: multipart/alternative; boundary="Apple-Mail=_FB5E44D2-4DD9-4BBC-94B8-C4C2F5432F8F" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Two questions about "pg_constraint" Message-Id: <496793CE-A048-434B-ABC0-6BFC0C65C3EC@yugabyte.com> Date: Wed, 24 Aug 2022 13:11:17 -0700 To: pgsql-general list X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_FB5E44D2-4DD9-4BBC-94B8-C4C2F5432F8F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 *Question 1: why does "pg_constraint" have a "connamespace" column?* I created this temporary view (using PG 14.4): create temporary view all_constraints(t_owner, t_schema, t_name, c_name, = same) as select r.rolname, s.nspname, c.relname, x.conname, (x.connamespace =3D c.relnamespace) from pg_class c inner join pg_roles r on c.relowner =3D r.oid inner join pg_namespace s on c.relnamespace =3D s.oid inner join pg_constraint x on c.oid =3D x.conrelid where c.relkind =3D 'r'; I created three tables, each with a user-created constraint. The tables = also have implicitly created primary key constraints. Then I did this: select count(*) from all_constraints; It said that the count is over a hundred. (All but the rows for my three = tables are for rows for tables in the "pg_catalog" schema.) Then I did this: select exists(select 1 from all_constraints where not same)::text; It said "false". Over one hundred seems to be a fair sample size. So it seems to be = reasonable to assume that "pg_constraint.connamespace =3D = pg_class.relnamespace" is always true. Ordinary common-sense analysis of = the query suggests this too. If the hypothesis is right, then = "connamespace" is simply a derived value. And this would be a departure = from usual table design practice. What do you think? *Question 2: what happened to the column "consrc"?* The PG 11 account of "pg_constraint" https://www.postgresql.org/docs/11/catalog-pg-constraint.html describes "consrc" (text) thus: =C2=AB If a check constraint, a human-readable representation of the = expression =C2=BB Ad hoc queries in my PG 11.9 env show results like =C2=AB (v =3D = lower(v)) =C2=BB in this column for my tables. This is useful = information. But the PG 14 version of "pg_constraint" has no such column = (and nor does the doc mention it). Is this information now exposed = somewhere else? --Apple-Mail=_FB5E44D2-4DD9-4BBC-94B8-C4C2F5432F8F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
*Question 1: why does "pg_constraint" have a "connamespace" = column?*

I = created this temporary view (using PG 14.4):

create temporary view = all_constraints(t_owner, t_schema, t_name, c_name, same) as
select
  r.rolname,
  s.nspname,
  c.relname,
  x.conname,
  (x.connamespace =3D c.relnamespace)
from
  pg_class c
  inner join
  pg_roles = r
  on c.relowner =3D r.oid
  inner join
  pg_namespace = s
  on c.relnamespace =3D s.oid
  inner join pg_constraint x
  on c.oid =3D x.conrelid
where = c.relkind =3D 'r';

I created three tables, each with a = user-created constraint. The tables also have implicitly created primary = key constraints.

Then I did this:

select count(*) from all_constraints;

It = said that the count is over a hundred. (All but the rows for my three = tables are for rows for tables in the "pg_catalog" schema.)

Then I did = this:

select exists(select 1 from = all_constraints where not same)::text;
It said "false".

Over one hundred seems = to be a fair sample size. So it seems to be reasonable to assume that = "pg_constraint.connamespace =3D pg_class.relnamespace" is always true. = Ordinary common-sense analysis of the query suggests this too. If the = hypothesis is right, then "connamespace" is simply a derived value. And = this would be a departure from usual table design practice.

What do you = think?

*Question= 2: what happened to the column "consrc"?*

The PG 11 account of = "pg_constraint"




= --Apple-Mail=_FB5E44D2-4DD9-4BBC-94B8-C4C2F5432F8F--