X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 469A19DCB6E for ; Wed, 15 Feb 2006 18:33:53 -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 34392-09 for ; Wed, 15 Feb 2006 18:33:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 21C769DC89F for ; Wed, 15 Feb 2006 18:33:49 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:33917 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1F9VDb-000EWv-AT for pgsql-sql@postgresql.org; Wed, 15 Feb 2006 17:33:51 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 9D53B4051; Wed, 15 Feb 2006 17:33:46 -0500 (EST) Date: Wed, 15 Feb 2006 17:33:46 -0500 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: How to force PostgreSQL using an index Message-ID: <20060215223346.GG6562@phlogiston.dyndns.org> References: <1E293D3FF63A3740B10AD5AAD88535D20190926B@UBIMAIL1.ubisoft.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1E293D3FF63A3740B10AD5AAD88535D20190926B@UBIMAIL1.ubisoft.org> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.097 required=5 tests=[AWL=0.097] X-Spam-Score: 0.097 X-Spam-Level: X-Archive-Number: 200602/191 X-Sequence-Number: 24201 On Wed, Feb 15, 2006 at 05:26:57PM -0500, Daniel Caune wrote: > I have an index on EVENT_DATE_CREATED that does it job. But I though > that I can help my favourite PostgreSQL if I create a composite index on > EVENT_DATE_CREATED and EVENT_NAME (in that order as EVENT_DATE_CREATED > is more dense that EVENT_NAME). > > PostgreSQL prefer the simple index rather than the composite index (for > I/O consideration, I suppose). I wanted to know how bad the composite > index would be if it was used (the estimate cost). You could do that by turning up the data the planner spits out, to see why it picks this index. It doesn't do so automatically, I think: I _think_ it's cost based (Tom will probably chime in here and remind me how little I know). My bet is that the second column isn't adding enough selectivity to help. One thing that might affect this is to fiddle with the SET STATISTICS settings on the column(s) in question. You might find that as the samples get better, your index turns out to be usefully selective, and it gets chosen. But to answer your question, no, you can't tell it "use index foo". A -- Andrew Sullivan | ajs@crankycanuck.ca This work was visionary and imaginative, and goes to show that visionary and imaginative work need not end up well. --Dennis Ritchie