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 1jz46W-0003rA-Sc for pgsql-general@arkaria.postgresql.org; Fri, 24 Jul 2020 20:15:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jz46V-0002LH-Jt for pgsql-general@arkaria.postgresql.org; Fri, 24 Jul 2020 20:15:39 +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 1jz46V-0002Ie-Bu for pgsql-general@lists.postgresql.org; Fri, 24 Jul 2020 20:15:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jz46P-0003pN-2A for pgsql-general@postgresql.org; Fri, 24 Jul 2020 20:15:38 +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 06OKFVhO575914; Fri, 24 Jul 2020 16:15:31 -0400 From: Tom Lane To: Ted Toth cc: pgsql-general Subject: Re: when is RLS policy applied In-reply-to: References: Comments: In-reply-to Ted Toth message dated "Fri, 24 Jul 2020 14:34:48 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <575912.1595621731.1@sss.pgh.pa.us> Date: Fri, 24 Jul 2020 16:15:31 -0400 Message-ID: <575913.1595621731@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ted Toth writes: > I'm trying to understand when RLS select policy is applied so I created the > follow to test but I don't understand why the query filter order is > different for the 2 queries can anyone explain? The core reason why not is that the ~~ operator isn't considered leakproof. Plain text equality is leakproof, so it's safe to evaluate ahead of the RLS filter --- and we'd rather do so because the plpgsql function is assumed to be much more expensive than a built-in operator. (~~ isn't leakproof because it can throw errors that expose information about the pattern argument.) regards, tom lane