X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 269A63A3D1A for ; Fri, 5 Nov 2004 15:32:46 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50069-08 for ; Fri, 5 Nov 2004 15:32:40 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by svr1.postgresql.org (Postfix) with ESMTP id 510123A3CA7 for ; Fri, 5 Nov 2004 15:32:43 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 58so60137wri for ; Fri, 05 Nov 2004 07:32:44 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=Y3Fd8sVRdzRup6A0r84AEXTCOQ4WVoNWhLbYLlTS6POJvUKcu9uwzLiJpgpzKJ+V/EHjqyQECh112h1aMezy7a1QyIN0z+ibBe/2FLkhtdQ4nPLt+DKWu4H2kIAfv5UibQMw7e+6DWKuwR6elxG47uh2QJjPOh/PWcNBiNLPhis= Received: by 10.54.21.71 with SMTP id 71mr26832wru; Fri, 05 Nov 2004 07:32:44 -0800 (PST) Received: by 10.54.43.36 with HTTP; Fri, 5 Nov 2004 07:32:43 -0800 (PST) Message-ID: <88f1825a041105073245010974@mail.gmail.com> Date: Fri, 5 Nov 2004 10:32:43 -0500 From: Allen Landsidel Reply-To: Allen Landsidel To: Postgresql Performance Subject: Re: Strange (?) Index behavior? In-Reply-To: <1099667258.1647.827.camel@home> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <88f1825a041105063955367088@mail.gmail.com> <1099667258.1647.827.camel@home> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/97 X-Sequence-Number: 9051 On Fri, 05 Nov 2004 10:07:38 -0500, Rod Taylor wrote: > > It seems to me that a query saying "SELECT column FROM table WHERE > > column LIKE 'AA%';" should be just as fast or very close to the first > > case up above. However, explain tells me that this query is not using > > the index above, which is what's not making sense to me. > > It looks for an exact expression match, and doesn't know about values > which are equal. > > You can provide both clauses. > > WHERE column LIKE 'A%' and column LIKE 'AA%'; I see. That's not really optimal either however as you can probably see already.. adding AB, AC, AD...AZ is likely to be pretty bogus and at the least is time consuming. Matt Clark was right that it will use a standard index, which is in fact what it's doing right now in the "SELECT column WHERE column LIKE 'AA%';" case.. however as I said, the table has millions of rows -- currently about 76 million, so even a full index scan is fairly slow. The machine isn't all that hot performance wise either, a simple dual 800 P3 with a single 47GB Seagate SCSI. The only redeeming factor is that it has 2GB of memory, which I'm trying to make the most of with these indexes. So assuming this partial index situation isn't going to change (it seems like it would be a fairly simple fix for someone that knows the pg code however) I'm wondering if a subselect may speed things up any, so I'm going to investigate that next. Perhaps.. SELECT column FROM (SELECT column FROM table WHERE column LIKE 'A%') AS sq WHERE column LIKE 'AA%'; The query planner thinks this will be pretty fast indeed, and does use the index I am after. OS is, of course, FreeBSD.