X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 784639DC82A for ; Tue, 21 Feb 2006 12:34:21 -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 00749-06 for ; Tue, 21 Feb 2006 12:34:19 -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 4D0409DC9DD for ; Tue, 21 Feb 2006 12:34:18 -0400 (AST) Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165]) by mx2.surnet.cl with ESMTP; 21 Feb 2006 13:53:44 -0300 X-IronPort-AV: i="3.99,385,1131332400"; d="scan'208"; a="29103468:sNHT18527272" Received: from alvh.no-ip.org (201.220.122.204) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 43A978FD007C15AF; Tue, 21 Feb 2006 13:34:17 -0300 Received: by alvh.no-ip.org (Postfix, from userid 1000) id F17B8C2C2DD; Tue, 21 Feb 2006 13:34:16 -0300 (CLST) Date: Tue, 21 Feb 2006 13:34:16 -0300 From: Alvaro Herrera To: Scott Marlowe Cc: Ibrahim Tekin , pgsql-performance@postgresql.org Subject: Re: LIKE query on indexes Message-ID: <20060221163416.GC6541@surnet.cl> Mail-Followup-To: Scott Marlowe , Ibrahim Tekin , pgsql-performance@postgresql.org References: <1140538679.5777.3.camel@state.g2switchworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1140538679.5777.3.camel@state.g2switchworks.com> User-Agent: Mutt/1.5.11+cvs20060126 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.743 required=5 tests=[AWL=-0.176, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 1.743 X-Spam-Level: * X-Archive-Number: 200602/329 X-Sequence-Number: 17315 Scott Marlowe wrote: > On Tue, 2006-02-21 at 09:57, Ibrahim Tekin wrote: > > hi, > > i have btree index on a text type field. i want see rows which starts > > with certain characters on that field. so i write a query like this: > > > > SELECT * FROM mytable WHERE myfield LIKE 'john%' > > > > since this condition is from start of the field, query planner should > > use index to find such elements but explain command shows me it will > > do a sequential scan. > > > > is this lack of a feature or i am wrong somewhere? > > This is an artifact of how PostgreSQL handles locales other than ASCII. > > If you want such a query to use an index, you need to back up your > database, and re-initdb with --locale=C as an argument. ... or you can choose to create an index with the text_pattern_ops operator class, which would be used in a LIKE constraint regardless of locale. http://www.postgresql.org/docs/8.1/static/indexes-opclass.html -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.