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 4B03A9DCA0C for ; Wed, 15 Feb 2006 18:26:59 -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 34810-07 for ; Wed, 15 Feb 2006 18:27:00 -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 E75119DC86D for ; Wed, 15 Feb 2006 18:26:56 -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 A4CB04BB4C; Wed, 15 Feb 2006 17:26:57 -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:26:57 -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:26:57 -0500 Message-ID: <1E293D3FF63A3740B10AD5AAD88535D20190926B@UBIMAIL1.ubisoft.org> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] How to force PostgreSQL using an index Thread-Index: AcYyfD7btng6QOR9Q/OgL9NhDX6CtQAAQ8Pg From: "Daniel Caune" To: "Andrew Sullivan" , X-OriginalArrivalTime: 15 Feb 2006 22:26:57.0320 (UTC) FILETIME=[EE606280:01C6327E] 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/189 X-Sequence-Number: 24199 > On Wed, Feb 15, 2006 at 04:58:54PM -0500, Daniel Caune wrote: > > Hi, > > > > > > > > Is there a way to force PostgreSQL using an index for a SELECT > > statement? I just want to confirm that the index PostgreSQL decides to > > use is better than the index I supposed PostgreSQL would use (I already > > analyze the table). >=20 > Your best bet is to do >=20 > set enable_indexscan=3Dfalse; >=20 > and then do the EXPLAIN ANALYSE for your select. >=20 > You might also find that fiddling with other settings affects the > planner's idea of what would be a good plan. The planner is > sensitive to what it thinks it knows about your environment. >=20 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. For example, I have a table that contains historical data from which I try to get a subset for a specified period of time: SELECT FROM GSLOG_EVENT WHERE EVENT_NAME =3D 'player-status-update' AND EVENT_DATE_CREATED >=3D AND EVENT_DATE_CREATED < 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). Daniel