Re: LIMIT confuses the planner - Mailing list pgsql-performance

From Tom Lane
Subject Re: LIMIT confuses the planner
Date
Msg-id 18725.1235412110@sss.pgh.pa.us
Whole thread Raw
In response to Re: LIMIT confuses the planner  (Kouber Saparev <kouber@saparev.com>)
Responses Re: LIMIT confuses the planner  (Kouber Saparev <kouber@saparev.com>)
List pgsql-performance
Kouber Saparev <kouber@saparev.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

pgsql-performance by date:

Previous
From: Kouber Saparev
Date:
Subject: Re: LIMIT confuses the planner
Next
From: Sergio Lopez
Date:
Subject: Re: Benchmark comparing PostgreSQL, MySQL and Oracle