From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ted Toth <txtoth@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: when is RLS policy applied
Date: Fri, 24 Jul 2020 16:15:31 -0400
Message-ID: <575913.1595621731@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFPpqQEs4qDXybQGaydQNYorHhzAW8KBK_7uSqDLNp2rm7a7zw@mail.gmail.com>
References: <CAFPpqQEs4qDXybQGaydQNYorHhzAW8KBK_7uSqDLNp2rm7a7zw@mail.gmail.com>
Ted Toth <txtoth@gmail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, txtoth@gmail.com
Subject: Re: when is RLS policy applied
In-Reply-To: <575913.1595621731@sss.pgh.pa.us>
References: <CAFPpqQEs4qDXybQGaydQNYorHhzAW8KBK_7uSqDLNp2rm7a7zw@mail.gmail.com> <575913.1595621731@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox