pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeremy Buchmann <jeremy@wellsgaming.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Using the correct index
Date: Wed, 21 Feb 2001 23:28:07 -0500
Message-ID: <13806.982816087@sss.pgh.pa.us> (raw)
In-Reply-To: <B6B997DF.1A35%jeremy@wellsgaming.com>
References: <B6B997DF.1A35%jeremy@wellsgaming.com>

Jeremy Buchmann <jeremy@wellsgaming.com> writes:
> I have a table I'll call SomeTable that has columns called id, date, and
> name along with a few others.  I created two indexes for this table, one was
> on id (called SomeTable_id) and the other was on id and date (called
> SomeTable_id_date).  When I do:
> EXPLAIN SELECT * FROM SomeTable WHERE id = '0101'
> it tells me:
> Index Scan using SomeTable_id_date on Sometable ...
> Even when I do:
> EXPLAIN SELECT id FROM SomeTable WHERE id = '0101'
> it still says it's using the SomeTable_id_date index.  Why is it using the
> multicolumn index when the date column isn't involved?

If the indexes are small then the cost estimates for scanning them will
be the same, and it's a random matter which one gets picked (in fact,
I suspect 7.0 may deliberately prefer the "more sorted" one).

Once the indexes get larger --- more than 100 pages or so --- the system
will notice that scanning the double-column index is more expensive, and
will avoid using it unless there's good reason.

			regards, tom lane



view thread (2+ messages)

Message-ID: <13806.982816087@sss.pgh.pa.us>
Permalink:  ../13806.982816087@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13806.982816087@sss.pgh.pa.us

 · 

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jeremy@wellsgaming.com
  Subject: Re: Using the correct index
  In-Reply-To: <13806.982816087@sss.pgh.pa.us>
  References: <B6B997DF.1A35%jeremy@wellsgaming.com> <13806.982816087@sss.pgh.pa.us>

* 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