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 1hxcEI-0000eN-7r for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2019 19:13:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hxcEH-0005td-1Y for pgsql-general@arkaria.postgresql.org; Tue, 13 Aug 2019 19:13:09 +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 1hxcEF-0005pN-62 for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2019 19:13:08 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hxcEB-0002Jx-3D for pgsql-general@lists.postgresql.org; Tue, 13 Aug 2019 19:13:06 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 0567536C; Tue, 13 Aug 2019 15:12:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 13 Aug 2019 15:13:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=3 WtphRCrcQlGr7iWCfKxBYg83wE7l1VRz/U/RBka0h4=; b=WlQRr2vTueFIlrYtN xDz+44yzv0mcAA+vilSUhUXo3q6hgOG6TxnAmw4mFE5qLpBrr/ywsFfGugFL9Yhs UWVK+bfUqxWF1SL32KsmB3aWU0eEANx7aEDOp88a2t/oVVpXTwdKzvchrr+0HFov UtoN4307+uhJm9tPs/2Q1Yau2MnqfnxhH+y9o5JTthDrdkVSI3COkYbYX61UEK8K 6fTGdE+iZzkZHGivWqfllLSVQTW8wqPqLcjdMkJ1tOoUM4PE69U8P7aD7xwuz1lk 6uq2avuZnpJnE8sSuPtY9Ddw2mB41+UUtyp5tdjmPDu3lSkvZhNHPwe3DrHtPflf 3iZaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=3WtphRCrcQlGr7iWCfKxBYg83wE7l1VRz/U/RBka0 h4=; b=dbsWGgu3Ro65Kbxt5RiaILG9g/UgnajHH59Ai1P00dfBLF2esOV+IY7kP /V4PPsiIcD9Hr0ulIPueVdZ1R1rrT/nq0VoPxm5TRbHqYllz0+vPxHiaJia0eU0b KDd2hsBcLV02ZpMrnX1uu4d7xdHKN3c9GZdMb9vceAP0az9oKObrzdb//wEDM6eD 4Tx9OcihuHvXxxi27KF3a3GVi7yz0aVG+UAPF9IJBAZPPAE7ieiCOzgMoMTka8mD quffjZnvjahGGqiCPrpHdsaPUccz6yaXusACA14CQusv4yKlYq0jtffQKAqjXKp9 Yw1JHafLRikls8EzzN6dXm8iUcFYA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddruddviedgudeftdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecukfhppeejuddrvdduvddrudehtddrvddtvdenucfrrghrrghmpehmrghilhhf rhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id B33378005A; Tue, 13 Aug 2019 15:12:58 -0400 (EDT) Subject: Re: GIST/GIN index not used with Row Level Security To: Derek Hans , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <40c05723-d462-8718-bc9c-2c4048c642e7@aklaver.com> Date: Tue, 13 Aug 2019 12:12:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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  | > Skype: derek.hans -- Adrian Klaver adrian.klaver@aklaver.com