Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 608C59FB900 for ; Thu, 24 May 2007 16:15:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 74771-06 for ; Thu, 24 May 2007 16:15:17 -0300 (ADT) X-Greylist: delayed 00:28:15.610642 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 66C749FB949 for ; Thu, 24 May 2007 16:15:18 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from pih-relay04.plus.net (pih-relay04.plus.net [212.159.14.131]) by svr4.postgresql.org (Postfix) with ESMTP id 93FD95AF043 for ; Thu, 24 May 2007 18:47:02 +0000 (GMT) Received: from [80.229.150.39] (helo=mansionfamily.plus.com) by pih-relay04.plus.net with esmtp (Exim) id 1HrIKw-0002Dm-Qa for pgsql-performance@postgresql.org; Thu, 24 May 2007 19:46:59 +0100 Received: from [192.168.0.87] ([192.168.0.87]:3648) by mansionfamily.plus.com with [XMail 1.22 ESMTP Server] id for from ; Thu, 24 May 2007 19:48:23 +0100 Message-ID: <4655DE75.4080506@mansionfamily.plus.com> Date: Thu, 24 May 2007 19:50:29 +0100 From: James Mansion User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: Alexander Staubo Cc: Andy , pgsql-performance@postgresql.org Subject: Re: LIKE search and performance References: <009501c79d4c$445428f0$0b00a8c0@mpsro.dom> <88daf38c0705230905u1a981102k691b47bd36011a80@mail.gmail.com> In-Reply-To: <88daf38c0705230905u1a981102k691b47bd36011a80@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/476 X-Sequence-Number: 24866 Alexander Staubo wrote: > On 5/23/07, Andy wrote: >> An example would be: >> SELECT * FROM table >> WHERE name like '%john%' or street like >> '%srt%' >> >> Anyway, the query planner always does seq scan on the whole table and >> that >> takes some time. How can this be optimized or made in another way to be >> faster? > > There's no algorithm in existence that can "index" arbitrary > substrings the way you think. The only rational way to accomplish this > is to first break the text into substrings using some algorithm (eg., > words delimited by whitespace and punctuation), and index the > substrings individually. That seems rather harsh. If I'd put an index on each of these colomns I'd certainly expect it to use the indices - and I'm pretty sure that Sybase would. I'd expect it to scan the index leaf pages instead of the table itself - they should be much more compact and also likely to be hot in cache. Why *wouldn't* the planner do this? James