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 1q9AIF-0008En-Fd for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Jun 2023 20:07:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q9AIE-0002Z4-Av for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Jun 2023 20:07:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q9AIE-0002Yv-2U for pgsql-bugs@lists.postgresql.org; Tue, 13 Jun 2023 20:07:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q9AI7-0021oM-VQ for pgsql-bugs@lists.postgresql.org; Tue, 13 Jun 2023 20:07:04 +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 35DK6vcj1798407; Tue, 13 Jun 2023 16:06:57 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17972: Assert failed in pull_varattnos_walker() for view with subquery and security qual In-reply-to: <17972-f422c094237847d0@postgresql.org> References: <17972-f422c094237847d0@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 13 Jun 2023 16:00:01 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1798405.1686686817.1@sss.pgh.pa.us> Date: Tue, 13 Jun 2023 16:06:57 -0400 Message-ID: <1798406.1686686817@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > The following script: > CREATE TABLE t1(a int); > CREATE VIEW v1 WITH (security_barrier = true) AS SELECT a FROM t1; > CREATE RULE v1_upd_rule AS ON UPDATE TO v1 DO INSTEAD UPDATE t1 SET a = > NEW.a WHERE a = OLD.a; > CREATE VIEW v2 WITH (security_barrier = true) AS SELECT a FROM v1 WHERE > EXISTS (SELECT 1); > UPDATE v2 SET a = 1; > leads to a failed assertion with the stack trace: Thanks for the report! pull_varattnos is not at fault here. The problem is that we missed converting that SubLink to a SubPlan earlier, because hasSubLinks wasn't set in the parent Query, so we never called SS_process_sublinks. After some digging, I found the cause: rewriteRuleAction neglected to check for SubLink nodes in the securityQuals of range table entries. > `git bisect` for this anomaly pointed at 215b43cdc. I think this is just accidental, probably an artifact of the specific test case. The oversight in rewriteRuleAction is as old as the existence of RangeTblEntry.securityQuals, unless it was impossible to write a SubLink in security quals before, which I doubt. regards, tom lane