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 1lxVsF-0007yq-RF for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Jun 2021 14:35:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lxVsE-0001IZ-D4 for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Jun 2021 14:35:02 +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 1lxVsE-0001ID-5P for pgsql-hackers@lists.postgresql.org; Sun, 27 Jun 2021 14:35:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lxVs7-00028s-6M for pgsql-hackers@lists.postgresql.org; Sun, 27 Jun 2021 14:35:01 +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 15REYqQK3176555; Sun, 27 Jun 2021 10:34:52 -0400 From: Tom Lane To: Julien Rouhaud cc: pgsql-hackers@lists.postgresql.org Subject: Re: Deparsing rewritten query In-reply-to: <20210627041138.zklczwmu3ms4ufnk@nol> References: <20210627041138.zklczwmu3ms4ufnk@nol> Comments: In-reply-to Julien Rouhaud message dated "Sun, 27 Jun 2021 12:11:38 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3176553.1624804492.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 27 Jun 2021 10:34:52 -0400 Message-ID: <3176554.1624804492@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Julien Rouhaud writes: > As an alternative, maybe we could expose a simple SRF that would take ca= re of > rewriting the query and deparsing the resulting query tree(s)? I'm not really excited by this, as it seems like it's exposing internal decisions we could change someday; to wit, first that there is any such thing as a separate rewriting pass, and second that its output is interpretable as pure SQL. (TBH, I'm not 100% sure that the second assumption is true even today, although I know there are ancient comments that claim that.) It's not very hard to imagine someday moving view expansion into the planner on efficiency grounds, leaving the rewriter handling only the rare uses of INSERT/UPDATE/DELETE rules. If there's functions in ruleutils.c that we'd need to make public to let somebody write a debugging extension that does this kind of thing, I'd be happier with that approach than with creating a core-server SQL function for it. There might be more than one use-case for the exposed bits. regards, tom lane