pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Caune <daniel.caune@ubisoft.com>
To: Owen Jacobson <ojacobson@osl.com>
To: pgsql-sql@postgresql.org
Subject: Re: How to force PostgreSQL using an index
Date: Wed, 15 Feb 2006 17:48:06 -0500
Message-ID: <1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org> (raw)



> > > > Is there a way to force PostgreSQL using an index for a SELECT
> > > > statement?
> > >
> > > Your best bet is to do
> > >
> > > set enable_indexscan=false;
> > >
> > > 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.
> 
> (snip)
> 
> > 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).
> 
> Drop the simple index and re-create it when you're done?
> 

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.
> 

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 /*+ <HINT> */
or WITH(INDEX(...)) help in such situations, even if that really sucks
for the reason you know.


Daniel



view thread (11+ messages)  latest in thread

Message-ID: <1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org>
Permalink:  ../1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org/
Also on:    postgresql.org/message-id/1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: daniel.caune@ubisoft.com, ojacobson@osl.com
  Subject: Re: How to force PostgreSQL using an index
  In-Reply-To: <1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org>
  References: <1E293D3FF63A3740B10AD5AAD88535D2019092A7@UBIMAIL1.ubisoft.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox