pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marc Schablewski <ms@clickware.de>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Optimizer problem with multi-column index
Date: Mon, 29 Apr 2013 11:22:58 -0400
Message-ID: <2999.1367248978@sss.pgh.pa.us> (raw)
In-Reply-To: <517E5435.9060801@clickware.de>
References: <517E5435.9060801@clickware.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Marc Schablewski <ms@clickware.de> writes:
> we have an issue concerning multi-column indexes not being used by the planner.

I see no particular bug here, just a rational response to an artificial
test case.  The planner is being discouraged by the random character of
the data in your first index column: that means that an indexscan on
that index would jump all over the place while accessing the table.
In contrast, the other index is *exactly* in heap order and so using it
will result in nice sequential touches of the heap.  So with default
random_page_cost, the cost to use the two-column index comes out quite
a bit higher than the cost to use the one-column index.  A bitmap scan
is less subject to the random-access problem, but it still loses out
compared to following an index that's exactly in heap order.  Whether
this test case corresponds very well to your real use case is hard to
say, but it seems a bit extreme from here.

BTW, had you vacuumed the table, the planner would've preferred an
index-only scan of the two-column index, since with the table marked
all-visible the potential for lots of random fetches from the heap goes
away.  But you didn't.

If these plan choices don't correspond to the actual runtimes you're
seeing, that probably suggests that you need to lower random_page_cost
for your environment.  This test case is small enough to fit in RAM on
most machines, so you'd have to set random_page_cost to 1 to expect
to get accurate predictions for the test case as-is.  I don't know
how large your real table is ...

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)

Message-ID: <2999.1367248978@sss.pgh.pa.us>
Permalink:  ../2999.1367248978@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2999.1367248978@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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ms@clickware.de
  Subject: Re: Optimizer problem with multi-column index
  In-Reply-To: <2999.1367248978@sss.pgh.pa.us>
  References: <517E5435.9060801@clickware.de> <2999.1367248978@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