Re: LIMIT confuses the planner

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: kouber(at)saparev(dot)com
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: LIMIT confuses the planner
Date: 2009-02-23 18:01:50
Message-ID: 18725.1235412110@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Kouber Saparev <kouber(at)saparev(dot)com> writes:
> Now the planner believes there're 910 rows, which is a bit closer to the
> real data:

> swing=# select avg(length) from (select username, count(*) as length
> from login_attempt group by username) as freq;
> avg
> ----------------------
> 491.6087310427555479
> (1 row)

Hmph, that's still not real good. Ideally it should be estimating
*less* than the average frequency, because the estimate is made after
excluding all the most-common-values, which evidently 'kouber' is not
one of. I suppose there's quite a large number of infrequently-seen
usernames and the ndistinct estimate is much less than reality? (Look
at the pg_stats row for this column.) It might be worth going all the
way to stats target 1000 for this column.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Sergio Lopez 2009-02-23 18:29:06 Re: Benchmark comparing PostgreSQL, MySQL and Oracle
Previous Message Kouber Saparev 2009-02-23 17:42:18 Re: LIMIT confuses the planner