Re: oddly slow query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jessi Berkelhammer <jberkelhammer(at)desc(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: oddly slow query
Date: 2008-01-14 19:43:37
Message-ID: 24707.1200339817@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jessi Berkelhammer <jberkelhammer(at)desc(dot)org> writes:
> Tom Lane wrote:
>> For some reason it's estimating only one row out of the
>> clinical_reg_current view will satisfy the
>> tier_program(benefit_type_code) = 'SAGE' constraint.

My math was off the other day --- actually, that's exactly what you'd
expect for the default estimate on an equality condition it has no stats
for, when the underlying scan is estimated to have only 117 rows. So
either you should do something about getting that underlying estimate
up closer to reality (perhaps increasing default_statistics_target would
improve matters?), or you need to fix things so that the planner can
apply its statistics to estimating what is happening with the
tier_program constraint. Expressed as a function this way, it's just a
black box to the planner so you get a default estimate. Given that the
function is just extracting from a table, I think you could remove the
function call and express the condition with a join instead, and that
might result in a better estimate.

>> I'm also wondering why the function call isn't getting pushed down
>> further into the plan --- what's the definition of that view look like?

> View definition:
> SELECT DISTINCT ON (clinical_reg.client_id)

Ah, it's the DISTINCT ON that's preventing any better optimization.
Not much to be done about that, unless you can recast things to not
need DISTINCT ON, which looks a bit hard.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adam Rich 2008-01-14 20:43:07 Locking & concurrency - best practices
Previous Message Jessi Berkelhammer 2008-01-14 19:14:10 Re: oddly slow query