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 1t7fYe-0036b7-2k for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Nov 2024 18:42:40 +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 1t7fYc-00DRfN-C2 for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Nov 2024 18:42:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t7fYc-00DRf9-1r for pgsql-hackers@lists.postgresql.org; Sun, 03 Nov 2024 18:42:38 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t7fYZ-004K3h-Am for pgsql-hackers@postgresql.org; Sun, 03 Nov 2024 18:42:36 +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 4A3IgXrw2436265; Sun, 3 Nov 2024 13:42:34 -0500 From: Tom Lane To: Yugo Nagata cc: pgsql-hackers@postgresql.org Subject: Re: EphemeralNamedRelation and materialized view In-reply-to: <20240726160714.e74d0db579f2c017e1ca0b7e@sraoss.co.jp> References: <20240726160714.e74d0db579f2c017e1ca0b7e@sraoss.co.jp> Comments: In-reply-to Yugo Nagata message dated "Fri, 26 Jul 2024 16:07:14 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2436263.1730659353.1@sss.pgh.pa.us> Date: Sun, 03 Nov 2024 13:42:33 -0500 Message-ID: <2436264.1730659353@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Yugo Nagata writes: > While looking into the commit b4da732fd64e936970f38c792f8b32c4bdf2bcd5, > I noticed that we can create a materialized view using Ephemeral Named > Relation in PostgreSQL 16 or earler. Yeah, we should reject that, but I feel like this patch is not ambitious enough, because the 17-and-up behavior isn't exactly polished either. I tried variants of this function in HEAD: 1. With "create table mv as select * from enr", it works and does what you'd expect. 2. With "create view mv as select * from enr", you get regression=# insert into tbl values (10); ERROR: relation "enr" does not exist LINE 1: create view mv as select * from enr ^ QUERY: create view mv as select * from enr CONTEXT: PL/pgSQL function f() line 2 at SQL statement regression=# \errverbose ERROR: 42P01: relation "enr" does not exist LINE 1: create view mv as select * from enr ^ QUERY: create view mv as select * from enr CONTEXT: PL/pgSQL function f() line 2 at SQL statement LOCATION: parserOpenTable, parse_relation.c:1452 3. With "create materialized view ..." you get regression=# insert into tbl values (10); ERROR: executor could not find named tuplestore "enr" CONTEXT: SQL statement "create materialized view mv as select * from enr" PL/pgSQL function f() line 2 at SQL statement regression=# \errverbose ERROR: XX000: executor could not find named tuplestore "enr" CONTEXT: SQL statement "create materialized view mv as select * from enr" PL/pgSQL function f() line 2 at SQL statement LOCATION: ExecInitNamedTuplestoreScan, nodeNamedtuplestorescan.c:107 I don't think hitting an internal error is good enough. Why doesn't this case act like case 2? You could even argue that case 2 isn't good enough either, and we should be delivering a specific error message saying that an ENR can't be used in a view/matview. To do that, we'd likely need to pass down the QueryEnvironment in more places not fewer. regards, tom lane