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 A1B2E9DCC8D for ; Wed, 15 Feb 2006 18:48:06 -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 39511-08 for ; Wed, 15 Feb 2006 18:48:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from relay01.mdc.ubisoft.com (relay01.mdc.ubisoft.com [216.98.56.134]) by postgresql.org (Postfix) with ESMTP id 9081C9DCC8B for ; Wed, 15 Feb 2006 18:48:04 -0400 (AST) Received: from mdc-owa01.ubisoft.org (srvowa1-mdc.ubisoft.org [10.129.1.20]) by smarthost.mdc.ubisoft.com (Postfix) with ESMTP id 2E1F24BBF1; Wed, 15 Feb 2006 17:48:07 -0500 (EST) Received: from UBIMAIL1.ubisoft.org ([10.129.1.15]) by mdc-owa01.ubisoft.org with Microsoft SMTPSVC(6.0.3790.1830); Wed, 15 Feb 2006 17:48:06 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: Re: How to force PostgreSQL using an index Date: Wed, 15 Feb 2006 17:48:06 -0500 Message-ID: <1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] How to force PostgreSQL using an index Thread-Index: AcYyf9K9I//CNs68QCW5E6RmdbNW5gAACuNw From: "Daniel Caune" To: "Owen Jacobson" , X-OriginalArrivalTime: 15 Feb 2006 22:48:06.0803 (UTC) FILETIME=[E30C1E30:01C63281] X-Ubisoft-MailScanner-Information: Please contact administrators@ubisoft.qc.ca X-Ubisoft-MailScanner: Found to be clean X-Ubisoft-MailScanner-SpamCheck: X-MailScanner-From: daniel.caune@ubisoft.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.123 required=5 tests=[AWL=0.123] X-Spam-Score: 0.123 X-Spam-Level: X-Archive-Number: 200602/193 X-Sequence-Number: 24203 > > > > Is there a way to force PostgreSQL using an index for a SELECT > > > > statement? > > > > > > Your best bet is to do > > > > > > set enable_indexscan=3Dfalse; > > > > > > and then do the EXPLAIN ANALYSE for your select. > > > > I see, but that doesn't explain whether it is possible to specify the > > index to use. It seems that those options just force PostgreSQL using > > another plan. >=20 > (snip) >=20 > > 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). >=20 > Drop the simple index and re-create it when you're done? >=20 Yes, that is a solution! I will try that! :-) > As I understand it, the problem with letting clients specify which indexes > to use is that they tend, on the whole, to be wrong about what's most > efficient, so it's a feature almost specifically designed for shooting > yourself in the foot with. I agree that it'd be useful for experimenting > with indexing schemes, but then, so is DROP INDEX. >=20 Yes, indeed, such a feature could be badly used. However it may happen sometimes that the planner is wrong; I already encountered such situations with both Oracle 9i and SQL Server 2000, even with statistics calculated. That is rare but that happens. Such options /*+ */ or WITH(INDEX(...)) help in such situations, even if that really sucks for the reason you know. Daniel