Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 1FBBA9FBD86 for ; Wed, 17 Oct 2007 15:49:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 25157-03 for ; Wed, 17 Oct 2007 15:49:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8A7BE9FBDC8 for ; Wed, 17 Oct 2007 15:49:35 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l9HInYtk009263; Wed, 17 Oct 2007 14:49:34 -0400 (EDT) To: Chris Kratz cc: Postgresql Performance Subject: Re: Incorrect estimates on columns In-reply-to: <200710171334.24526.chris.kratz@vistashare.com> References: <200710171334.24526.chris.kratz@vistashare.com> Comments: In-reply-to Chris Kratz message dated "Wed, 17 Oct 2007 13:34:24 -0400" Date: Wed, 17 Oct 2007 14:49:34 -0400 Message-ID: <9262.1192646974@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/209 X-Sequence-Number: 27231 Chris Kratz writes: > I'm struggling to get postgres to run a particular query quickly. The key problem seems to be the join size misestimate here: > -> Hash Join (cost=45.92..1251.07 rows=21 width=8) (actual time=0.948..10.439 rows=1199 loops=1) > Hash Cond: (par.activity = a.activityid) > -> Bitmap Heap Scan on rpt_agencyquestioncache_171_0 par (cost=21.92..1222.19 rows=1247 width=8) (actual time=0.415..3.081 rows=1199 loops=1) > -> Hash (cost=19.21..19.21 rows=383 width=4) (actual time=0.513..0.513 rows=383 loops=1) Evidently it's not realizing that every row of par will have a join partner, but why not? I suppose a.activityid is unique, and in most cases that I've seen the code seems to get that case right. Would you show us the pg_stats rows for par.activity and a.activityid? regards, tom lane