Sorry, for delayed response - It was very busy week. 2008/11/7 David Wilson <[EMAIL PROTECTED]>
> On Fri, Nov 7, 2008 at 4:14 AM, Віталій Тимчишин <[EMAIL PROTECTED]> wrote: > > "Merge Join (cost=518771.07..62884559.80 rows=1386158171 width=32) > (actual > > time=30292.802..755751.242 rows=34749 loops=1)" > > Have you tried increasing the default_statistics_target? The planner > is expecting 1.3 billion rows to be produced from a query that's only > actually producting 35k, which probably indicates some very bad > statistics. The planner seems to think that every second pair from company<->company join will succeed with this join expression (1386158171 ~ 52648^2 / 2). That is not true. Anyway, I've tried to set default_statistics_target to 1000, then analyze. Nothing've changed At the same time, the materialize step produces 242 > million rows when the planner only expects to produce 2.3, indicating > a similar problem in the opposite direction. This probably means that > the planner is choosing plans that would be optimal if it was making > good guesses but are decidedly sub-optimal for your actual data. > > That is even more strange, because materialize step must produce exactly the rows it takes from sort, that is 2316503, so I don't get how table scan + sort + materialize can multiply number of rows by 100.