pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: nickf@ontko.com
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: A plan returned by explain doesn't make sense to me
Date: Fri, 05 Apr 2002 11:45:36 -0500
Message-ID: <24798.1018025136@sss.pgh.pa.us> (raw)
In-Reply-To: <NEBBLAAHGLEEPCGOBHDGEEGCELAA.nickf@ontko.com>
References: <NEBBLAAHGLEEPCGOBHDGEEGCELAA.nickf@ontko.com>

"Nick Fankhauser" <nickf@ontko.com> writes:
>> That seems strange to me also, particularly if the index column ordering
>> is indeed actor_id,case_id and not the other way round

> Actually, it *is* the other way around- I didn't realize that could make a
> difference.

Ah.  Okay, that eliminates the apparent impossibility.

> I think this solves my immediate problem, but it seems like even with the
> reversed order, the planner shouldn't have chosen the combined index to
> drive the query, so I'm happy for now, but I fear that I've added a task to
> someone's list in the developer's enclave.

The only reason the planner should choose a single-column index over
using the first column of a multi-column index is that the latter index
is likely to be physically larger and thus require more I/O to access.
So, there's no penalty in the cost calculations other than the
number-of-blocks-of-I/O estimated from the physical index size.  It
would be interesting to see the reltuples and relpages stats from
pg_class for your single- and multi-column indexes.  (However, it may be
too late now since you blew away and rebuilt the multi-column index;
we can't be entirely sure what stats the planner was seeing before.)

It's actually a standard recommendation that you not bother with an
index on a single column x if you also have one on (x,y).  Unless the
table is almost entirely read-only, the cost of updating two indexes
outweighs the I/O savings of using the smaller index for queries that
use only x.

			regards, tom lane



view thread (6+ messages)  latest in thread

Message-ID: <24798.1018025136@sss.pgh.pa.us>
Permalink:  ../24798.1018025136@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24798.1018025136@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, nickf@ontko.com
  Subject: Re: A plan returned by explain doesn't make sense to me
  In-Reply-To: <24798.1018025136@sss.pgh.pa.us>
  References: <NEBBLAAHGLEEPCGOBHDGEEGCELAA.nickf@ontko.com> <24798.1018025136@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