From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Derek Hans <derek.hans@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: GIST/GIN index not used with Row Level Security
Date: Tue, 13 Aug 2019 12:12:57 -0700
Message-ID: <40c05723-d462-8718-bc9c-2c4048c642e7@aklaver.com> (raw)
In-Reply-To: <CAGrP7a2t+JbeuxpQY+RSvNe4fr3+==UmyimwV0GCD+wcrSSb=w@mail.gmail.com>
References: <CAGrP7a2t+JbeuxpQY+RSvNe4fr3+==UmyimwV0GCD+wcrSSb=w@mail.gmail.com>
On 8/13/19 11:57 AM, Derek Hans wrote:
> When using row level security, GIN and GIST indexes appear to get
> ignored. Is this expected behavior? Can I change the query to get
> PostgreSQL using the index? For example, with RLS enabled, this query:
What are the RLS policies on the table?
What is the definition of the GIN index?
Best guess is the RLS is preventing access to the field needed by the index.
>
> select * from search where search like '%yo'
>
> Creates this query plan:
> "Seq Scan on search (cost=0.00..245.46 rows=1 width=163)"
> " Filter: (((tenant_name)::name = CURRENT_USER) AND (search ~~
> '%yo'::text))"
>
> Running this same query with the owner of the table, thereby disabling
> RLS, the index gets used as expected:
> "Bitmap Heap Scan on search (cost=4.49..96.33 rows=44 width=163)"
> " Recheck Cond: (search ~~ '%yo'::text)"
> " -> Bitmap Index Scan on search__gist (cost=0.00..4.48 rows=44 width=0)"
> " Index Cond: (search ~~ '%yo'::text)"
>
> I see the same behavior with more complex queries, switching to GIN
> index, more complex RLS rules, using word_similarity instead of like,
> using full text search and larger data sets (e.g. 100k rows). This is on
> PostgreSQL v11.1 on Windows 10.
>
> --
> *Derek*
> +1 (415) 754-0519 |derek.hans@gmail.com <mailto:derek.hans@gmail.com> |
> Skype: derek.hans
--
Adrian Klaver
adrian.klaver@aklaver.com
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: adrian.klaver@aklaver.com, derek.hans@gmail.com
Subject: Re: GIST/GIN index not used with Row Level Security
In-Reply-To: <40c05723-d462-8718-bc9c-2c4048c642e7@aklaver.com>
References: <CAGrP7a2t+JbeuxpQY+RSvNe4fr3+==UmyimwV0GCD+wcrSSb=w@mail.gmail.com> <40c05723-d462-8718-bc9c-2c4048c642e7@aklaver.com>
* 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