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 1kKixC-0002rf-Nk for pgsql-admin@arkaria.postgresql.org; Tue, 22 Sep 2020 14:07:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKixA-0000K9-Iq for pgsql-admin@arkaria.postgresql.org; Tue, 22 Sep 2020 14:07:32 +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 1kKixA-0000K0-BS for pgsql-admin@lists.postgresql.org; Tue, 22 Sep 2020 14:07:32 +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 1kKix7-00021c-Nc for pgsql-admin@lists.postgresql.org; Tue, 22 Sep 2020 14:07:31 +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 08ME7Qgc1176452; Tue, 22 Sep 2020 10:07:26 -0400 From: Tom Lane To: Shrikant Bhende cc: Jeff Janes , Avinash Kumar , dbatoCloud Solution , pgsql-admin@lists.postgresql.org Subject: Re: Query taking seq scan on a table In-reply-to: References: Comments: In-reply-to Shrikant Bhende message dated "Tue, 22 Sep 2020 18:29:19 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1176450.1600783646.1@sss.pgh.pa.us> Date: Tue, 22 Sep 2020 10:07:26 -0400 Message-ID: <1176451.1600783646@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Shrikant Bhende writes: > *create index concurrently lname_test_btree_txt_pat_ops on wldbowner.member > (lname text_pattern_ops) where fname like LOWER(unaccent_string(lname) || > '%')* > Is this the correct way to create a b-tree index with text_pattern_ops for > my requirement ? No. What you're trying to optimize is Filter: ((lower(unaccent_string((lname)::text)) ~~ 'info%'::text) AND (lower(unaccent_string((fname)::text)) ~~ 'travel%'::text)) so you need one or both of create index on member (lower(unaccent_string(lname)) text_pattern_ops); create index on member (lower(unaccent_string(fname)) text_pattern_ops); If one of those two conditions is reliably more selective than the other, perhaps just one index would do. regards, tom lane