Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id CA3B31337C87 for ; Mon, 14 Feb 2011 03:03:30 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 39396-01-4 for ; Mon, 14 Feb 2011 07:03:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from rs73.luxsci.com (rs73.luxsci.com [64.49.254.135]) by mail.postgresql.org (Postfix) with ESMTP id 55E611337BF5 for ; Mon, 14 Feb 2011 03:02:26 -0400 (AST) Received: from GNANAM ([180.151.61.10]) (authenticated bits=0) by rs73.luxsci.com (8.13.8/8.13.8) with ESMTP id p1E72NRe014261; Mon, 14 Feb 2011 01:02:24 -0600 Reply-To: From: "Gnanakumar" To: Subject: How to boost performance of queries containing pattern matching characters Date: Mon, 14 Feb 2011 12:29:04 +0530 Organization: Zoniac Software Private Limited Message-ID: <004601cbcc14$acfe99d0$06fbcd70$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcvMFKousvyANEy/Thiuh0xtm7zlIA== Content-Language: en-us X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/369 X-Sequence-Number: 42507 Hi, How can we boost performance of queries containing pattern matching characters? In my case, we're using a percent sign (%) that matches any string of zero or more characters. QUERY: DELETE FROM MYTABLE WHERE EMAIL ILIKE '%domain.com%' EMAIL column is VARCHAR(256). As it is clear from the above query, email is matched "partially and case-insensitively", which my application requirement demands. In case, if it were a full match, I could easily define a functional INDEX on EMAIL column (lower(EMAIL)) and I could rewrite my DELETE where criteria like lower(EMAIL) = 'someemail@domain.com'. MYTABLE currently contains 2 million records and grows consistently. Regards, Gnanam