Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 98DA09FBA47 for ; Thu, 24 May 2007 19:07:14 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 65791-06 for ; Thu, 24 May 2007 19:07:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from h07.llord.com (unknown [195.140.142.194]) by postgresql.org (Postfix) with ESMTP id 211409FBA37 for ; Thu, 24 May 2007 19:07:11 -0300 (ADT) Received: from par69-8-88-161-102-87.fbx.proxad.net ([88.161.102.87] helo=apollo13) by h07.llord.com with esmtpa (Exim 4.63) (envelope-from ) id 1HrLSG-0000cR-C3; Fri, 25 May 2007 00:06:44 +0200 Date: Fri, 25 May 2007 00:09:15 +0200 To: "Mark Lewis" , "James Mansion" Subject: Re: LIKE search and performance From: PFC Cc: "Magnus Hagander" , "Alexander Staubo" , Andy , pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <009501c79d4c$445428f0$0b00a8c0@mpsro.dom> <88daf38c0705230905u1a981102k691b47bd36011a80@mail.gmail.com> <4655DE75.4080506@mansionfamily.plus.com> <4655E64B.5050503@hagander.net> <4655FB8A.1040707@mansionfamily.plus.com> <1180040560.31471.262.camel@archimedes> Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <1180040560.31471.262.camel@archimedes> User-Agent: Opera Mail/9.10 (Linux) X-PopBeforeSMTPSenders: junk@peufeu.com, lists@peufeu.com, peufeu@peufeu.com, pfcaillaud@peufeu.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - h07.llord.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - peufeu.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.89 tagged_above=0 required=5 tests=AWL=-0.145, BAYES_20=-0.74, RCVD_IN_NJABL_SPAM=2.775 X-Spam-Level: * X-Archive-Number: 200705/484 X-Sequence-Number: 24874 > PG could scan the index looking for matches first and only load the > actual rows if it found a match, but that could only be a possible win= > if there were very few matches, because the difference in cost between= a > full index scan and a sequential scan would need to be greater than th= e > cost of randomly fetching all of the matching data rows from the table= > to look up the visibility information. If you need to do that kind of thing, ie. seq scanning a table checking= = only one column among a large table of many columns, then don't use an = index. An index, being a btree, needs to be traversed in order (or else,= a = lot of locking problems come up) which means some random accesses. So, you could make a table, with 2 columns, updated via triggers : your= = text field, and the primary key of your main table. Scanning that would = be = faster. Still, a better solution for searching in text is : - tsearch2 if you need whole words - trigrams for any substring match - xapian for full text search with wildcards (ie. John* =3D Johnny) Speed-wise those three will beat any seq scan on a large table by a hug= e = margin.