X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 596C09DC85E for ; Sat, 25 Feb 2006 14:13:49 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31994-06 for ; Sat, 25 Feb 2006 14:13:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx2.surnet.cl (mx2.surnet.cl [216.155.73.181]) by postgresql.org (Postfix) with ESMTP id 21D1D9DC848 for ; Sat, 25 Feb 2006 14:13:46 -0400 (AST) Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165]) by mx2.surnet.cl with ESMTP; 25 Feb 2006 15:34:13 -0300 X-IronPort-AV: i="3.99,385,1131332400"; d="scan'208"; a="31112775:sNHT18177476" Received: from alvh.no-ip.org (201.221.201.125) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 43A978FD0083F945; Sat, 25 Feb 2006 15:13:47 -0300 Received: by alvh.no-ip.org (Postfix, from userid 1000) id E4B1AC2C2DD; Sat, 25 Feb 2006 15:13:46 -0300 (CLST) Date: Sat, 25 Feb 2006 15:13:46 -0300 From: Alvaro Herrera To: Florian Weimer Cc: Tom Lane , pgsql-sql@postgresql.org Subject: Re: Index to support LIKE '%suffix' queries Message-ID: <20060225181346.GA6092@surnet.cl> Mail-Followup-To: Florian Weimer , Tom Lane , pgsql-sql@postgresql.org References: <87mzgfh69m.fsf@mid.deneb.enyo.de> <11673.1140888147@sss.pgh.pa.us> <877j7jfhqs.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877j7jfhqs.fsf@mid.deneb.enyo.de> User-Agent: Mutt/1.5.11+cvs20060126 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.577 required=5 tests=[AWL=-0.342, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.577 X-Spam-Level: * X-Archive-Number: 200602/318 X-Sequence-Number: 24328 > > Florian Weimer writes: > >> Is it possible to create an index to support queries of the form > >> "column LIKE '%suffix'" (similar to an ordinary index for LIKE > >> 'prefix%', which I also need)? It is possible to create a functional index on the reverse of the string. You need to also reverse the patter at query-time as well. This will make the % be at the end of the pattern, making it an indexable condition. Whether or not this beats tsearch2 is something you should investigate ... -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.