Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 70C3F1336971 for ; Mon, 14 Feb 2011 03:18:59 -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 17559-02 for ; Mon, 14 Feb 2011 07:18:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by mail.postgresql.org (Postfix) with ESMTP id 89E2713364DE for ; Mon, 14 Feb 2011 03:18:49 -0400 (AST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by mail.archonet.com (Postfix) with ESMTP id 07E367C137; Mon, 14 Feb 2011 07:18:48 +0000 (GMT) Message-ID: <4D58D752.2000100@archonet.com> Date: Mon, 14 Feb 2011 07:18:42 +0000 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15pre) Gecko/20110202 Lightning/1.0b2 Shredder/3.1.9pre 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-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.918 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201102/370 X-Sequence-Number: 42508 On 14/02/11 06:59, Gnanakumar wrote: > > How can we boost performance of queries containing pattern matching > characters? > QUERY: DELETE FROM MYTABLE WHERE EMAIL ILIKE '%domain.com%' > As it is clear from the above query, email is matched "partially and > case-insensitively", which my application requirement demands. Well, for that exact pattern you're not going to find an index that's much help. Do you really need something so wide-ranging though? The above will match all of the following: user1@domain.com user2@sub.domain.com user3@domain.com.au user4@unrelated-domain.com user5@unrelated-domain.com.au user3@sub.domain.com.au user4@sub.unrelated-domain.com user5@sub.unrelated-domain.com.au user6@sub.unrelated-domain.completely-wrong.com Is that really what you are after? Or, did you just want to match: user1@domain.com user2@sub.domain.com -- Richard Huxton Archonet Ltd