Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j9LYZ-0003OK-2s for pgsql-general@arkaria.postgresql.org; Wed, 04 Mar 2020 04:22:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9LYX-0003Cn-TN for pgsql-general@arkaria.postgresql.org; Wed, 04 Mar 2020 04:22:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j9LYX-0003Cg-Fz for pgsql-general@lists.postgresql.org; Wed, 04 Mar 2020 04:22:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9LYU-00074m-U0 for pgsql-general@lists.postgresql.org; Wed, 04 Mar 2020 04:22:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 0244MdYP022264; Tue, 3 Mar 2020 23:22:40 -0500 From: Tom Lane To: Alastair McKinley cc: "pgsql-general@lists.postgresql.org" Subject: Re: Poor plan choice with partial unique indexes on jsonb column and simple RLS policy (with test script) In-reply-to: References: ,<11492.1583280280@sss.pgh.pa.us> Comments: In-reply-to Alastair McKinley message dated "Wed, 04 Mar 2020 00:37:41 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22262.1583295759.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 03 Mar 2020 23:22:39 -0500 Message-ID: <22263.1583295759@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alastair McKinley writes: > Thank you for having a look at this. In the interim I discovered that I= could trigger the issue by creating a security barrier view, whereas a re= gular view worked fine, so I think that also points to your conclusion abo= ut leakyness? > I attempted to workaround the issue with a leakproof function, so far wi= th no success. > ... > Is this an approach that could fundamentally work? Forcing the expression to be considered leakproof should work. I'm not sure that your partial index is OK for the purpose of collecting stats, though -- does it help if you make a non-partial index on that function expression? Otherwise, it's possible that I guessed wrong about which part of the WHERE clause is problematic. You could try doing EXPLAINs with different portions of the WHERE to see how the rowcount estimate changes. BTW, just marking something "leakproof" when it isn't really so is possibly a security problem. You should think twice about what threat model you're hoping RLS will protect against. regards, tom lane