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.89) (envelope-from ) id 1hxcE1-0000dW-51 for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2019 19:12:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hxcE0-0002hO-11 for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2019 19:12:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxcDz-0002e1-Lg for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2019 19:12:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxcDx-0002Jf-Er for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2019 19:12:51 +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 x7DJCknf012553; Tue, 13 Aug 2019 15:12:46 -0400 From: Tom Lane To: Derek Hans cc: pgsql-general@lists.postgresql.org Subject: Re: GIST/GIN index not used with Row Level Security In-reply-to: References: Comments: In-reply-to Derek Hans message dated "Tue, 13 Aug 2019 14:57:59 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12551.1565723566.1@sss.pgh.pa.us> Date: Tue, 13 Aug 2019 15:12:46 -0400 Message-ID: <12552.1565723566@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Derek Hans writes: > 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: Your example is obscuring the issue by incorporating a tenant_name condition (where did that come from, anyway?) in one case and not the other. Without knowing how selective that is, it's hard to compare the EXPLAIN results. However, wild-guess time: it might be that without access to the table statistics, the "search like '%yo'" condition is estimated to be too unselective to make an indexscan profitable. And putting RLS in the way would disable that access if the ~~ operator is not marked leakproof, which it isn't. I'm not sure that you should get too excited about this, however. You're evidently testing on a toy-size table, else the seqscan cost estimate would be a lot higher. With a table large enough to make it really important to guess right, even the default selectivity estimate might be enough to get an indexscan. regards, tom lane