X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7A26D9DC98B for ; Tue, 17 Jan 2006 17:04:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18280-03 for ; Tue, 17 Jan 2006 17:04:06 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by postgresql.org (Postfix) with ESMTP id 637F29DC988 for ; Tue, 17 Jan 2006 17:04:03 -0400 (AST) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO [192.168.1.27]) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 8836262; Tue, 17 Jan 2006 13:06:51 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: sum of left join greater than its parts Date: Tue, 17 Jan 2006 13:09:53 -0800 User-Agent: KMail/1.8 Cc: Robert Treat References: <1137517669.28011.728.camel@camel> In-Reply-To: <1137517669.28011.728.camel@camel> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200601171309.53377.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.076 required=5 tests=[AWL=0.076] X-Spam-Score: 0.076 X-Spam-Level: X-Archive-Number: 200601/265 X-Sequence-Number: 16743 Hmmm, this looks like a planner bug to me: > Hash > Join (cost=870.00..992.56 rows=1 width=96) (actual time=90.566..125.782 > rows=472 loops=1) Hash Cond: (("outer".host_id = "inner".host_id) AND > ("outer"."?column2?" = "inner".mtime)) -> HashAggregate > (cost=475.88..495.32 rows=1555 width=16) (actual time=51.300..70.761 > rows=10870 loops=1) >-- Nested Loop (cost=1733.79..4620.38 rows=1 width=20) (actual > time=81.160..89.826 rows=238 loops=1) -> Nested Loop > (cost=1733.79..4615.92 rows=1 width=20) (actual time=81.142..86.826 > rows=238 loops=1) Join Filter: ("outer".rmsbinaryid = > "inner".rmsbinaryid) -> HashAggregate (cost=1733.79..1740.92 rows=570 > width=12) (actual time=81.105..81.839 rows=323 loops=1) -> Bitmap Heap > Scan on msg306u (cost=111.75..1540.65 rows=25752 width=12) (actual > time=4.490..41.233 rows=25542 loops=1) Notice that for both queries, the estimates are reasonably accurate (within +/- 4x) until they get to left joining the subquery, at which point the estimate of rows joined becomes exactly "1". That looks suspicios to me ... Tom? Neil? -- --Josh Josh Berkus Aglio Database Solutions San Francisco