Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSqom-00GKXW-Mg for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jan 2024 03:54:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rSqok-00BhU0-TQ for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Jan 2024 03:54:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSqok-00BhTs-Kw for pgsql-bugs@lists.postgresql.org; Thu, 25 Jan 2024 03:54:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSqof-003aAG-4e for pgsql-bugs@lists.postgresql.org; Thu, 25 Jan 2024 03:54:18 +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 40P3sA7h264097; Wed, 24 Jan 2024 22:54:10 -0500 From: Tom Lane To: "David G. Johnston" cc: "rekgrpth@gmail.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #18307: system columns does not support using join In-reply-to: References: <18307-16a12cbeb212d742@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Wed, 24 Jan 2024 07:26:50 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <264095.1706154850.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 24 Jan 2024 22:54:10 -0500 Message-ID: <264096.1706154850@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tuesday, January 23, 2024, PG Bug reporting form > wrote: >> create table t(i int); >> = >> explain (costs off) select * from t join t tt on t.xmin =3D tt.xmin; >> QUERY PLAN >> --------------------------------- >> Hash Join >> Hash Cond: (t.xmin =3D tt.xmin) >> -> Seq Scan on t >> -> Hash >> -> Seq Scan on t tt >> (5 rows) >> = >> explain (costs off) select * from t join t tt using (xmin); >> ERROR: column "xmin" specified in USING clause does not exist in left >> table > I don=E2=80=99t this being worth the effort to change, and really seems = like > completely expected behavior. =E2=80=9CSelect *=E2=80=9D doesn=E2=80=99t= output xmin, it requires > explicit table qualification to see it. This is the same thing. Well, it is odd that "using (xmin)" isn't equivalent to the allegedly equivalent "on t.xmin =3D tt.xmin". This is down to the infrastructure in transformFromClauseItem(), which searches the lists of (regular, non-system) relation output column names to expand USING(). But like you, I can't get excited about changing it. There are a couple of practical reasons why not: * NATURAL JOIN is defined in terms of USING. But we *certainly* don't want "x NATURAL JOIN y" deciding that it should equate all the system columns of x to those of y. So there's going to be inconsistency at one level or the other no matter what. * I really find it hard to imagine a valid use case for joining on any system column. There are use-cases for joining on TID in an UPDATE involving a self-join to the target table; but you can't write that with JOIN USING syntax. regards, tom lane