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 1tGyjf-002D84-Ih for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Nov 2024 11:00:31 +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 1tGyjc-006cx3-VW for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Nov 2024 11:00:30 +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 1tGyjc-006cwu-Kq for pgsql-hackers@lists.postgresql.org; Fri, 29 Nov 2024 11:00:29 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tGyja-0009W9-My for pgsql-hackers@postgresql.org; Fri, 29 Nov 2024 11:00:28 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2ffb0bbe9c8so20816821fa.0 for ; Fri, 29 Nov 2024 03:00:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732878025; x=1733482825; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xz2sgdOzS8IhiMLS3VnOegW5hgLYITlJLdMB18T0Ghs=; b=D3ZjkSXaMStbriSNB2Hp9f1p+h84xFtvVUgSvSDIV3cgDTudCQt7GlreZPGw86X3nx vGCQGmJQQaHFQqIHZloUgfPR65qKpnXioImc3eA+zeJvOeffFq3bSFnzpCaBXOFmns3K XCaJEHvWxjrxvoaZ7AvyU7VK+BYmI25qEN5Vn+IH911q1VsraeSmf2jFBIYPfMHF8PID P8ZipRkUlLnxw0yVW37fDElhjcFVYuEwZHIRY77rvc4e7ee0TIwl7MliPGMABYkoWkxe CqnxigCWxL4bdeo6JQwrpZaEV7HRutDcwnLhqfUoHoQeEidItm8Pui4sZGNdyVbn+YzE dc7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732878025; x=1733482825; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xz2sgdOzS8IhiMLS3VnOegW5hgLYITlJLdMB18T0Ghs=; b=uxNrtiKE6d64pIse6JRts7s9xWmld6tQjb/fINzc22DcdfVcYiRP6+QeyTvI7fQJWs 0C0lIsTHZTORsFjRb+mnMm1oE+jN6MkDv+4w6eo2RNYanwLQI9n5sKtVfnSXGxFlRw7C MAurKXUrxvZ788N3RFlYJVYtBFj+CWWCIqElTAQVKJPfbTW9adD5/tVHxuaDlQ2QB0JO NlszFnvtN1djRqZusDCfsUgBdHE2fUcDPP8bmzHAV+NVTxkSDLRl/uNKpYAWEEsN/o9Y auKV8e/XsaHnqDXo9MzOkueiEjfoV3OGLXc9Kagcuqmu5xkhzWLx2+2MirGVFiFEggB8 kwGg== X-Forwarded-Encrypted: i=1; AJvYcCUS3oucbVk9XTp67tUbcAjCkTugZrCORXNiIJAq8ZYSxqB5H42q/b3ZzKs07pKKyG/NgdXf88A66sbdW8U8@postgresql.org X-Gm-Message-State: AOJu0Yw50siRbIUMTlNuKPkG7rFWOeGLQFVA885bO9DMAL9kRXndHZLq qrSvZ81x/5wOmZRM5B+2AswSAIxgpcFCaa20/NfKN8ibr6OdM32abaS656fY7yzJPgJX7E8x3Db /b+TBfoMnEcom+46HZYNlEFGE3K2JbqK9gcU= X-Gm-Gg: ASbGnctJLQI3oeeCgPTBVBCSavhMuDYrOYv5OyF7AiqXZroltxSicn/oZHVybk1BsX8 le5N04JudNraFWvjbJrVMef54Pme5JPIaLo7/189FJVbGiE78nyHEMgjVmg6z X-Google-Smtp-Source: AGHT+IHAT5a227E6kF4k5aig8U8GPDn+loPQXlw8u200RLsuIfCTITzrozxMywIl1/+/ZHgdIZXgwCfHlxPJ6ST1cgM= X-Received: by 2002:a05:651c:1502:b0:2fa:cdd1:4f16 with SMTP id 38308e7fff4ca-2ffd606d091mr61460841fa.14.1732878024493; Fri, 29 Nov 2024 03:00:24 -0800 (PST) MIME-Version: 1.0 References: <20240726160714.e74d0db579f2c017e1ca0b7e@sraoss.co.jp> <2436264.1730659353@sss.pgh.pa.us> <20241115173647.a62d3eaa0eaa9c4502b2504b@sraoss.co.jp> In-Reply-To: <20241115173647.a62d3eaa0eaa9c4502b2504b@sraoss.co.jp> From: Kirill Reshke Date: Fri, 29 Nov 2024 16:00:13 +0500 Message-ID: Subject: Re: EphemeralNamedRelation and materialized view To: Yugo NAGATA Cc: Tom Lane , pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 15 Nov 2024 at 13:37, Yugo NAGATA wrote: > > On Sun, 03 Nov 2024 13:42:33 -0500 > Tom Lane wrote: > > > 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? > > I agree that raising an internal error is not enough. I attached a updated > patch that outputs a message saying that an ENR can't be used in a matview. > > > 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. > > We can raise a similar error for (not materialized) views by passing > QueryEnv to DefineView() (or in ealier stage) , but there are other > objects that can contain ENR in their definition, for examle, functions, > cursor, or RLS policies. Is it worth introducing this version of error > message for all these objects? > > Regards, > Yugo Nagata > > -- > Yugo NAGATA Hi! There are review comments that need to be addressed. Commitfest status is now waiting on the author. [0] https://www.postgresql.org/message-id/ZzrHUEaWB67EAZpW%40paquier.xyz [1] https://www.postgresql.org/message-id/222722.1732124596%40sss.pgh.pa.us -- Best regards, Kirill Reshke