Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C97021337B98 for ; Mon, 14 Feb 2011 09:55:45 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 90771-01 for ; Mon, 14 Feb 2011 13:55:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.peak6.com (smtp2.peak6.com [38.98.137.9]) by mail.postgresql.org (Postfix) with ESMTP id DD76C133655C for ; Mon, 14 Feb 2011 09:55:36 -0400 (AST) X-AuditID: 0a02cb1e-b7bf8ae00000096d-11-4d59345840bb Message-ID: <4D593458.1020004@peak6.com> Date: Mon, 14 Feb 2011 07:55:36 -0600 From: Shaun Thomas Reply-To: sthomas@peak6.com Organization: Peak6 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.7) Gecko/20100720 Lightning/1.0b2 Thunderbird/3.1.1 MIME-Version: 1.0 To: "gnanam@zoniac.com" CC: "pgsql-performance@postgresql.org" Subject: Re: How to boost performance of queries containing pattern matching characters References: <004601cbcc14$acfe99d0$06fbcd70$@com> In-Reply-To: <004601cbcc14$acfe99d0$06fbcd70$@com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Brightmail-Tracker: AAAAAQAAAZE= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/384 X-Sequence-Number: 42522 On 02/14/2011 12:59 AM, Gnanakumar wrote: > QUERY: DELETE FROM MYTABLE WHERE EMAIL ILIKE '%domain.com%' > EMAIL column is VARCHAR(256). Honestly? You'd be better off normalizing this column and maybe hiding that fact in a view if your app requires email as a single column. Split it like this: So user@gmail.com becomes: email_acct (user) email_domain (gmail) email_tld (com) This would let you drop the first % on your like match and then traditional indexes would work just fine. You could also differentiate between domains with different TLDs without using wildcards, which is always faster. I might ask why you are checking email for wildcards after the TLD in the first place. Is it really so common you are trying to match .com, .com.au, .com.bar.baz.edu, or whatever? At the very least, splitting the account from the domain+tld would be beneficial, as it would remove the necessity of the first wildcard, which is really what's hurting you. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email_disclaimer.php for terms and conditions related to this email