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 1gjlXY-0003UU-L3 for pgsql-admin@arkaria.postgresql.org; Wed, 16 Jan 2019 13:47:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gjlXX-000730-1x for pgsql-admin@arkaria.postgresql.org; Wed, 16 Jan 2019 13:47:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjlXW-00072t-NF for pgsql-admin@lists.postgresql.org; Wed, 16 Jan 2019 13:47:30 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjlXS-0002jR-3v for pgsql-admin@lists.postgresql.org; Wed, 16 Jan 2019 13:47:29 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.14.3/8.14.3/Debian-9.4) with ESMTP id x0GDlCaQ020810 for ; Wed, 16 Jan 2019 15:47:17 +0200 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id x0GDlCO4053060 for ; Wed, 16 Jan 2019 15:47:12 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Subject: Re: extracting the domain from an email address To: pgsql-admin@lists.postgresql.org References: From: Achilleas Mantzios Message-ID: <0729dd40-9448-7529-155e-458676681b5e@matrix.gatewaynet.com> Date: Wed, 16 Jan 2019 15:47:12 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------F3B3366802D0CFB06B5CAD1E" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.98.7 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-27.0 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL,DYN_SPAM_MED6,HTML_MESSAGE autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------F3B3366802D0CFB06B5CAD1E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 16/1/19 3:20 μ.μ., Mark Steben wrote: > Good morning, > I am searching for a better more efficient way to extract the domain portion of an email address.  The two I have been using are very expensive. >    The one extract I mostly use: substring(email from '@(.*)$') >        also has an index on the email column which is the full email address: > btree (email DESC) WHERE email::text = "substring"(email::text, '@(.*)$'::text) AND length(email::text) > 0, >   The other extract: > substr(e.email,(strpos(e.email, '@') + 1)) > Currently has no index. Why don't you create an index on the extracted part including the where clause? create index your_table_email_domain ON your_table(substring(email from '@(.*)$')) WHERElength(email::text) > 0 ; > > The referenced table has 72 million rows.  The email column can be empty (ergo the length = 0 check.  I am running postgresql 9.4. > > Any insights/observations welcome. > > -- > *Mark Steben* >  Database Administrator > @utoRevenue | Autobase > CRM division of Dominion Dealer Solutions > 95D Ashley Ave. > West Springfield, MA 01089 > t: 413.327-3045 > f: 413.383-9567 > > www.fb.com/DominionDealerSolutions > www.twitter.com/DominionDealer > www.drivedominion.com > > > > > -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------F3B3366802D0CFB06B5CAD1E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 16/1/19 3:20 μ.μ., Mark Steben wrote:
Good morning,
I am searching for a better more efficient way to extract the domain portion of an email address.  The two I have been using are very expensive.
   The one extract I mostly use:  substring(email from '@(.*)$')
       also has an index on the email column which is the full email address:
              btree (email DESC) WHERE email::text = "substring"(email::text, '@(.*)$'::text) AND length(email::text) > 0,
      The other extract:
      substr(e.email,(strpos(e.email, '@') + 1))
   Currently has no index.
Why don't you create an index on the extracted part including the where clause?
create index your_table_email_domain ON your_table(substring(email from '@(.*)$')) WHERE length(email::text) > 0 ;

The referenced table has 72 million rows.  The email column can be empty (ergo the length = 0 check.  I am running postgresql 9.4.

Any insights/observations welcome.
            
         
     

--
Mark Steben
 Database Administrator
@utoRevenue | Autobase 
  CRM division of Dominion Dealer Solutions 
95D Ashley Ave.
West Springfield, MA 01089

t: 413.327-3045
f: 413.383-9567

www.fb.com/DominionDealerSolutions
www.twitter.com/DominionDealer
 www.drivedominion.com







-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------F3B3366802D0CFB06B5CAD1E--