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 1s5SpC-005W1n-DM for pgsql-bugs@arkaria.postgresql.org; Fri, 10 May 2024 16:10:22 +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 1s5SpA-00GxLA-JD for pgsql-bugs@arkaria.postgresql.org; Fri, 10 May 2024 16:10:20 +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 1s5SpA-00GxKy-BP for pgsql-bugs@lists.postgresql.org; Fri, 10 May 2024 16:10:20 +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 1s5Sp8-000MFy-3H for pgsql-bugs@lists.postgresql.org; Fri, 10 May 2024 16:10:19 +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 44AGAHsC1542000; Fri, 10 May 2024 12:10:17 -0400 From: Tom Lane To: Jacques Combrink cc: pgsql-bugs@lists.postgresql.org Subject: Re: Security barrier view index on join condition In-reply-to: References: Comments: In-reply-to Jacques Combrink message dated "Fri, 10 May 2024 17:40:02 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1541998.1715357417.1@sss.pgh.pa.us> Date: Fri, 10 May 2024 12:10:17 -0400 Message-ID: <1541999.1715357417@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jacques Combrink writes: > I have the following situation where I don't understand why the underlying > index will not be used through the security_barrier view. [ shrug ... ] A security barrier is a pretty crippling restriction on what the optimizer can do. The barrier view will always be planned separately, which is why you usually end up with a seqscan on join_test_2. > Although when I change the query WHERE condition to a straight up equals, > it somehow works: > EXPLAIN ANALYZE > SELECT l2_security_view.id FROM join_test > LEFT JOIN l2_security_view USING(id) > WHERE join_test.id = 6; This happens to work because the implied USING qual is combined with the equality clause from WHERE to produce the replacement conditions "join_test.id = 6 AND l2_security_view.id = 6". Then, after verifying that the subquery's restriction clause "l2_security_view.id = 6" is leakproof, it's allowed to be pushed down into the subquery, becoming "join_test_2.id = 6", from which the subquery can produce an indexscan plan. But that doesn't work for normal join conditions, since those can't be pushed into the subquery. It also doesn't get applied with WHERE conditions that are anything but simple equality to a constant. Certainly there's work that could be done to make this a little better, but it would be a lot of work and probably would not move the goalposts very far. You should expect security barriers to hurt performance-wise. regards, tom lane