Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id F0D6E475E39 for ; Fri, 31 May 2002 12:45:54 -0400 (EDT) Received: from shire.ontko.com (shire.ontko.com [199.164.165.1]) by postgresql.org (Postfix) with ESMTP id 29238475DB6 for ; Fri, 31 May 2002 12:45:53 -0400 (EDT) Received: from nick (bilbo.ontko.com [199.164.165.101]) by shire.ontko.com (8.9.3/8.9.3/Debian 8.9.3-21) with SMTP id LAA31854; Fri, 31 May 2002 11:45:43 -0500 X-Authentication-Warning: shire.ontko.com: Host bilbo.ontko.com [199.164.165.101] claimed to be nick Reply-To: From: "Nick Fankhauser" To: "Marc Mitchell" , Subject: Re: LIKE operator and indexes Date: Fri, 31 May 2002 11:44:02 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: <01f301c208c0$a9b74ae0$7501050a@eisolution.com> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Archive-Number: 200205/259 X-Sequence-Number: 4434 Marc- I've just gone through some similar query optimizing work, and I can confirm that LIKE can definitely use an index if the initial characters are supplied as in the example you sent. -Nick -------------------------------------------------------------------------- Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788 Ray Ontko & Co. Software Consulting Services http://www.ontko.com/ > -----Original Message----- > From: pgsql-admin-owner@postgresql.org > [mailto:pgsql-admin-owner@postgresql.org]On Behalf Of Marc Mitchell > Sent: Friday, May 31, 2002 11:32 AM > To: pgsql-admin@postgresql.org > Subject: [ADMIN] LIKE operator and indexes > > > Can anyone provide definitive information and/or points of > reference within > the documentation about the ability of the query optimizer to use indexes > when processing a "LIKE" operator on a String column? > > My assumption is that > > "SELECT * FROM customer WHERE name LIKE 'GENERAL%';" > > should benefit from the existence of a BTREE index on the "customer.name" > column. I know this is the case is most other RDBMS's I've used including > Postgres's ancestor Ingres. > > However, experiments with EXPLAIN seem to always result in Seq Scans. > Furthermore, per the documentation: > > "7.2. Index Types... In particular, the PostgreSQL query optimizer will > consider using a B-tree index whenever an indexed column is involved in a > comparison using one of these operators: <, <=, =, >=, > ", > > the LIKE operator is conspicuously missing. However, I've yet to find a > reference specifically talking about LIKE and query plans. There is no > reference in "4.6.1. Pattern Matching with LIKE" . > > I'd like to know if indexes can be used and I've go something else setup > wrong or if indexes and LIKEs don't mix. > > Marc Mitchell - Senior Application Architect > Enterprise Information Solutions, Inc. > marcm@eisolution.com > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >