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 1joVCE-00023l-6v for pgsql-admin@arkaria.postgresql.org; Thu, 25 Jun 2020 16:57:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1joVCC-0007WL-Ra for pgsql-admin@arkaria.postgresql.org; Thu, 25 Jun 2020 16:57:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joVCC-0007WE-JZ for pgsql-admin@lists.postgresql.org; Thu, 25 Jun 2020 16:57:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1joVCA-0008IR-JW for pgsql-admin@postgresql.org; Thu, 25 Jun 2020 16:57:51 +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 05PGvn8X2277796; Thu, 25 Jun 2020 12:57:49 -0400 From: Tom Lane To: Mark Steben cc: pgsql-admin Subject: Re: using regular expression queries with regular expression indexes In-reply-to: References: Comments: In-reply-to Mark Steben message dated "Thu, 25 Jun 2020 12:45:55 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2277794.1593104269.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 25 Jun 2020 12:57:49 -0400 Message-ID: <2277795.1593104269@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mark Steben writes: > We are currently running postgres version 12.2. I have a query that uses > regexp code to confirm if a text field is a date or not. It is resource > intensive and long running. I have made a regexp index (actually severa= l > flavors of regexp indexes) to aid in this queries performance. However I > cannot seem to 'convince' the planner to use the indexes I create. I don't understand your complaint. Your example shows that it *is* using the index: > -> Bitmap Index Scan on custattr_value (cost=3D0.00..9787.64 rows=3D= 479041 width=3D0) > Finally if I remove the 'ca.account_id is not null' expression > [ it doesn't use the index ] Well, of course not, because then the query doesn't match the index's WHERE condition (i.e., there could be rows the query needs to return that are not included in the index). But I imagine that restriction isn't very selective, so you could probably omit it from the index definition as well; then the index would work for queries with or without that restriction. regards, tom lane