X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 629879FA4A5 for ; Tue, 4 Jul 2006 17:27:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 78491-03 for ; Tue, 4 Jul 2006 17:27:46 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.225]) by postgresql.org (Postfix) with ESMTP id 211069FA0EC for ; Tue, 4 Jul 2006 17:27:46 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id i7so833952wra for ; Tue, 04 Jul 2006 13:27:45 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=IYw+skfUeyxnGdCYfTVeTxUpOMEoN4TKlr+9+4++oHjx+5z4xNCL4OHeivRLSaBUqGrwJvAl/gYkKXI6lgKPXnJ2wLvKpVg7wH8LnCtY3S4aO9IM2bVBaViV/qr2w1gxmSaHzX/6rVgmstq+/VaX+6NHnVBEyAuPJ7dHOkOGHjY= Received: by 10.65.176.17 with SMTP id d17mr4538854qbp; Tue, 04 Jul 2006 13:27:44 -0700 (PDT) Received: by 10.65.114.11 with HTTP; Tue, 4 Jul 2006 13:27:44 -0700 (PDT) Message-ID: <430d92a20607041327r4bcd6306ofec4adec6856c037@mail.gmail.com> Date: Tue, 4 Jul 2006 16:27:44 -0400 From: Gene Reply-To: genekhart@gmail.com To: "Tarhon-Onu Victor" Subject: Re: optimizing LIKE '%2345' queries Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <430d92a20607021450i1d228350j292d68e987ed58de@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/20 X-Sequence-Number: 19880 Thanks for the suggestion. Actually I went ahead and created a reverse function using plpgsql, created an index using reverse column and now my queries use "where reverse(column) like reverse('%2345') and it's using the index like i hoped it would! Now if I could figure out how to optimize like '%2345%' queries. I don't want to create many indexes though the table is very write heavy. > > Is the only way to create a reverse function and create an index using > > the reverse function and modify queries to use: > > > > where reverse(column) like reverse('%2345') ? > > Hmm.. interesting. > If (and only if) the records stored in "column" column have fixed > length (say, all are 50 characters in length) you could create and index > on, say, substring(column,45,50), and use this in the WHERE clauses in > your queries. > Or if the length of those records is not the same maybe it is > feasible to create an ondex on substring(column, length(column)-5, > length(column)). > > -- > Any views or opinions presented within this e-mail are solely those of > the author and do not necessarily represent those of any company, unless > otherwise expressly stated. >