pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ken Geis <kgeis@speakeasy.org>
Cc: Richard Huxton <dev@archonet.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: plan problem
Date: Fri, 09 Apr 2004 12:50:35 -0400
Message-ID: <26675.1081529435@sss.pgh.pa.us> (raw)
In-Reply-To: <4073C3DF.2070307@speakeasy.org>
References: <40731252.2030002@speakeasy.org>
	<200404070938.11482.dev@archonet.com>
	<4073C3DF.2070307@speakeasy.org>

Ken Geis <kgeis@speakeasy.org> writes:
> Does anyone think that the planner issue has merit to address?  Can
> someone help me figure out what code I would look at?

The planner doesn't currently attempt to "drill down" into a sub-select-
in-FROM to find statistics about the variables emitted by the sub-select.
So it's just falling back to a default estimate of the number of
distinct values coming out of the sub-select.

The "drilling down" part is not hard; the difficulty comes from trying
to figure out whether and how the stats from the underlying column would
need to be adjusted for the behavior of the sub-select itself.  As an
example, the result of (SELECT DISTINCT foo FROM bar) would usually have
much different stats from the raw bar.foo column.  In your example, the
LIMIT clause potentially affects the stats by reducing the number of
distinct values.

Now in most situations where the sub-select wouldn't change the stats,
there's no issue anyway because the planner will flatten the sub-select
into the main query.  So we really have to figure out the adjustment
part before we can think about doing much here.

			regards, tom lane



view thread (5+ messages)

Message-ID: <26675.1081529435@sss.pgh.pa.us>
Permalink:  ../26675.1081529435@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26675.1081529435@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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kgeis@speakeasy.org, dev@archonet.com
  Subject: Re: plan problem
  In-Reply-To: <26675.1081529435@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