pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Ron Mayer <ron@intervideo.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Does "correlation" mislead the optimizer on large
Date: Fri, 24 Jan 2003 08:27:03 -0800 (PST)
Message-ID: <20030124081405.W30842-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <11025.1043390899@sss.pgh.pa.us>

On Fri, 24 Jan 2003, Tom Lane wrote:

> Ron Mayer <ron@intervideo.com> writes:
> >   In particular, if I have a large table t with columns 'a','b','c', etc,
> >   and I cluster the table as follows:
> >     create table t_ordered as select * from t order by a,b;
> >     vacuum analyze t_ordered;
> >   Column "b" will (correctly) get a very low "correlation" in
> >   the pg_stats table -- but I think the optimizer would do better
> >   assuming a high correlation because similar 'b' values are still
> >   grouped closely on the same disk pages.
>
> How would that be?  They'll be separated by the stride of 'a'.

I think it's a clumping effect.

For example, I made a table (ordered)  with 20 values of a, 50 values of b
(each showing up in each a) and 100 values of c (not used, just means 100
rows for each (a,b) combination. It's got 541 pages it looks like. Analyze
sets the correlation to about 0.08 on the table and so a query like:
select * from test1 where b=1; prefers a sequence scan (1791 vs 2231)
while the index scan actually performs about 5 times better.

I guess the reason is that in general, the index scan *really* is reading
something on the order of 40 pages rather than the much larger estimate
(I'd guess something on the order of say 300-400?  I'm not sure how to
find that except by trying to reverse engineer the estimate number),
because pretty much each value of a will probably have 1 or 2 pages with
b=1.

I'm not really sure how to measure that, however.





view thread (8+ messages)  latest in thread

Message-ID: <20030124081405.W30842-100000@megazone23.bigpanda.com>
Permalink:  ../20030124081405.W30842-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20030124081405.W30842-100000@megazone23.bigpanda.com

 · 

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-performance@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, tgl@sss.pgh.pa.us, ron@intervideo.com
  Subject: Re: Does "correlation" mislead the optimizer on large
  In-Reply-To: <20030124081405.W30842-100000@megazone23.bigpanda.com>
  References: <11025.1043390899@sss.pgh.pa.us> <20030124081405.W30842-100000@megazone23.bigpanda.com>

* 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