Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLsdE-0000y7-Ub for pgsql-general@arkaria.postgresql.org; Thu, 02 Sep 2021 19:44:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mLsdD-00008p-EB for pgsql-general@arkaria.postgresql.org; Thu, 02 Sep 2021 19:44:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLsdD-00008h-5U for pgsql-general@lists.postgresql.org; Thu, 02 Sep 2021 19:44:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLsdA-0000P0-UG for pgsql-general@lists.postgresql.org; Thu, 02 Sep 2021 19:44:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 182Ji90c2266572; Thu, 2 Sep 2021 15:44:09 -0400 From: Tom Lane To: Michael Lewis cc: Ninad Shah , balasubramanian c r , pgsql-general Subject: Re: Querying a table with jaccard similarity with 1.6 million records take 12 seconds In-reply-to: References: Comments: In-reply-to Michael Lewis message dated "Thu, 02 Sep 2021 09:27:28 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2266570.1630611849.1@sss.pgh.pa.us> Date: Thu, 02 Sep 2021 15:44:09 -0400 Message-ID: <2266571.1630611849@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michael Lewis writes: > This is showing many false positives from the index scan that get removed > when the actual values are examined. With such a long search parameter, > that does not seem surprising. I would expect a search on "raj nagar > ghaziabad 201017" or something like that to yield far fewer results from > the index scan. I don't know GIN indexes super well, but I would guess that > including words that are very common will yield false positives that get > filtered out later. Yeah, the huge "Rows Removed" number shows that this index is very poorly adapted to the query. I don't think the problem is with GIN per se, but with a poor choice of how to use it. The given example looks like what the OP really wants to do is full text search. If so, a GIN index should be fine as long as you put tsvector/tsquery filtering in front of it. If that's not a good characterization of the goal, it'd help to tell us what the goal is. (Just saying "I want to use jaccard similarity" sounds a lot like a man whose only tool is a hammer, therefore his problem must be a nail, despite evidence to the contrary.) regards, tom lane