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 1oBdLB-00070m-7Z for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jul 2022 14:27:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBdL9-000507-AB for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jul 2022 14:27:47 +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 1oBdL9-0004zy-2I for pgsql-bugs@lists.postgresql.org; Wed, 13 Jul 2022 14:27:47 +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 1oBdL6-0005R7-MQ for pgsql-bugs@lists.postgresql.org; Wed, 13 Jul 2022 14:27:46 +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 26DERdBt2221348; Wed, 13 Jul 2022 10:27:41 -0400 From: Tom Lane To: 875941708@qq.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17549: wrong index scan plan with RLS In-reply-to: <17549-5114159516d34c2d@postgresql.org> References: <17549-5114159516d34c2d@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 13 Jul 2022 11:45:54 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2221346.1657722459.1@sss.pgh.pa.us> Date: Wed, 13 Jul 2022 10:27:39 -0400 Message-ID: <2221347.1657722459@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: > # for RLS user, index scan can only use column a, and filter by lower(b) > set app.a=1; > explain analyse select * from abc where a=1 and lower(b)='1234'; > Index Scan using abc_a_lower_idx on abc > Index Cond: (a = 1) > Filter: (lower(b) = '1234'::text) AFAICS this is operating as designed. It's unsafe to apply the non-leakproof condition until we've verified that the row has a = 1. In the particular case shown here, it might be all right to do it, but cases such as bitmap indexscans or lossy index opclasses could result in live re-evaluations of the indexqual conditions at some rows. So we can't safely allow lower(b) to become part of the indexquals. regards, tom lane