Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cX6yV-0001G7-2s for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Jan 2017 13:53:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cX6yU-0003ig-5R for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Jan 2017 13:53:58 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cX6yT-0003iZ-NC for pgsql-bugs@postgresql.org; Fri, 27 Jan 2017 13:53:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cX6yP-0005E8-V9 for pgsql-bugs@postgresql.org; Fri, 27 Jan 2017 13:53:57 +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 v0RDrpLp027965; Fri, 27 Jan 2017 08:53:51 -0500 From: Tom Lane To: grau.fran@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14518: FTS index not triggered when using function to provide the tsquery In-reply-to: <20170127103939.1431.54363@wrigleys.postgresql.org> References: <20170127103939.1431.54363@wrigleys.postgresql.org> Comments: In-reply-to grau.fran@gmail.com message dated "Fri, 27 Jan 2017 10:39:39 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27963.1485525231.1@sss.pgh.pa.us> Date: Fri, 27 Jan 2017 08:53:51 -0500 Message-ID: <27964.1485525231@sss.pgh.pa.us> X-Pg-Spam-Score: -5.1 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org grau.fran@gmail.com writes: > But I need to run the query through a function to generate a custom tsquery > sometimes. So if I run: > SELECT pub.publication_id > FROM publication pub > WHERE > pub.fts @@ x_get_tsquery('Omnis') > "Seq Scan on publication pub (cost=0.00..5939.89 rows=50 width=8)" > " Filter: (fts @@ x_get_tsquery('Omnis'::text))" > As you can see it uses a sequential scan... not good. Most likely you've marked that function volatile (or allowed it to be so marked by default). That disables using it in an index condition, because the planner has to assume that the function's result might change for every row. You need to mark it stable or immutable instead, per https://www.postgresql.org/docs/devel/static/xfunc-volatility.html regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs