Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Jeff Janes
On Wed, Mar 25, 2015 at 1:00 PM, Feike Steenbergen < feikesteenber...@gmail.com> wrote: > On 25 March 2015 at 19:07, Jeff Janes wrote: > > > Also, I doubt that that is the problem in the first place. If you > collect a > > sample of 30,000 (which the default target size of 100 does), and the > >

Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Feike Steenbergen
On 25 March 2015 at 19:07, Jeff Janes wrote: > Also, I doubt that that is the problem in the first place. If you collect a > sample of 30,000 (which the default target size of 100 does), and the > frequency of the second most common is really 0.00307333 at the time you > sampled it, you would ex

Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Jeff Janes
On Wed, Mar 25, 2015 at 9:07 AM, Feike Steenbergen < feikesteenber...@gmail.com> wrote: > I'm posting this as I am trying to understand what has happened. > TLDR: The problem seems to be fixed now. > > By bumping the statistics_target we see that most_common_vals is > having its contents filled mo

Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Tom Lane
Feike Steenbergen writes: > On 25 March 2015 at 13:45, Tomas Vondra wrote: >>> We can also increase the 'Stats target' for this table, which will >>> cause the statistics to contain information about 'NOT_YET_PRINTED' >>> more often, but even then, it may not find any of these records, as >>> the

Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Feike Steenbergen
I'm posting this as I am trying to understand what has happened. TLDR: The problem seems to be fixed now. By bumping the statistics_target we see that most_common_vals is having its contents filled more often, causing way better estimates: attname| status inherited

Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Feike Steenbergen
Hi, thanks for having a look and thinking with us On 25 March 2015 at 13:45, Tomas Vondra wrote: > Can you post results for this query? > > SELECT stats, COUNT(*) FROM print_list group by 1 status | count +- ERROR | 159 PREPARED | 10162 PRINT

Re: [PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Tomas Vondra
On 25.3.2015 13:04, Feike Steenbergen wrote: ... > When analyzing pg_stats we have sometimes have the following: (Note: > 'NOT_YET_PRINTED' has not been found during this analyze, these are > real values) > > attname| status > inherited | f > null_frac

[PERFORM] Index only scan sometimes switches to sequential scan for small amount of rows

2015-03-25 Thread Feike Steenbergen
Hi, Situation: We have a table with 3,500,000+ rows, which contain items that need to be printed or have been printed previously. Most of these records have a status of 'PRINTED', we have a partial index on this table WHERE status <> 'PRINTED'. During normal operation there will be < 10 records