Re: [PERFORM] Estimation question...

2013-02-28 Thread Matt Daw
I get it now... project_id=115 has a frequency of 0.09241 in pg_stats. So if ((project_id = 115) AND (project_id = 115)) is considered as two independent conditions, the row estimate ends up being 0.09241 * 0.09241 * 1.20163e+07 (reltuples from pg_class) = 102614.

Re: [PERFORM] Estimation question...

2013-02-27 Thread Matt Daw
Quick follow up... I've found that the row estimate in: explain select count(id) from versions where project_id IN (80,115) AND project_id=115; QUERY PLAN

[PERFORM] Estimation question...

2013-02-26 Thread Matt Daw
Howdy, the query generator in my app sometimes creates redundant filters of the form: project_id IN ( list of projects user has permission to see ) AND project_id = single project user is looking at ... and this is leading to a bad estimate (and thus a bad plan) on a few complex queries. I've