X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 542C19FB300 for ; Tue, 22 Aug 2006 15:50:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 28179-01 for ; Tue, 22 Aug 2006 18:50:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from lists.commandprompt.com (host-130.commandprompt.net [207.173.203.130]) by postgresql.org (Postfix) with ESMTP id B60C89FA50F for ; Tue, 22 Aug 2006 15:50:37 -0300 (ADT) Received: from alvh.no-ip.org (201-221-200-187.bk11-dsl.surnet.cl [201.221.200.187]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id k7MIoWu8012978; Tue, 22 Aug 2006 11:50:33 -0700 Received: by alvh.no-ip.org (Postfix, from userid 1000) id 53A01C2DC58; Tue, 22 Aug 2006 14:49:57 -0400 (CLT) Date: Tue, 22 Aug 2006 14:49:57 -0400 From: Alvaro Herrera To: Thomas Samson Cc: Ulrich Habel , pgsql-performance@postgresql.org Subject: Re: query planner: automatic rescribe of LIKE to BETWEEN ? Message-ID: <20060822184957.GE25475@alvh.no-ip.org> Mail-Followup-To: Thomas Samson , Ulrich Habel , pgsql-performance@postgresql.org References: <200608221922.59734.espero7757@gmx.net> <20060822174539.GD25475@alvh.no-ip.org> <4e96c6600608221121p2afc603bx90fcf879aab47d96@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4e96c6600608221121p2afc603bx90fcf879aab47d96@mail.gmail.com> User-Agent: Mutt/1.5.12-2006-07-14 X-Virus-Scanned: ClamAV version 0.88.3, clamav-milter version 0.88.3 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Tue, 22 Aug 2006 11:50:33 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.951 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, SPF_HELO_SOFTFAIL, SPF_SOFTFAIL X-Spam-Level: *** X-Archive-Number: 200608/352 X-Sequence-Number: 20537 Thomas Samson wrote: > On 8/22/06, Alvaro Herrera wrote: > >Ulrich Habel wrote: > >> Hello all, > >> had an idea of optimizing a query that may work generally. > >> > >> In case a 'column' is indexed, following two alterations could be done > >> I think: > >> > >> A) > >> > >> select ... where column ~ '^Foo' --> Seq Scan > > > >This is not true. You can make this query use an index if you create it > >with opclass varchar_pattern_ops or text_pattern_ops, as appropiate. > > > >Thus you don't need any hack here. > > > > And in the case of more general expression, like: > select ... where column ~ 'something'; > > Is there a way to optimise this ? (in the case where 'something' is not > a word, but a part of a word) Not sure. I'd try tsearch2 or pg_trgm (or pg_tgrm, whatever it's called). It's trigram indexing. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support