X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 68A18329ED7 for ; Fri, 8 Oct 2004 21:05:17 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44059-06 for ; Fri, 8 Oct 2004 20:04:49 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id B5DEF32A518 for ; Fri, 8 Oct 2004 21:04:48 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i98K4g31015494; Fri, 8 Oct 2004 16:04:43 -0400 (EDT) To: "Gary Doades" Cc: pgsql-performance@postgresql.org Subject: Re: Odd planner choice? In-reply-to: <4166F956.21282.29EC515A@localhost> References: <4166F956.21282.29EC515A@localhost> Comments: In-reply-to "Gary Doades" message dated "Fri, 08 Oct 2004 20:32:22 +0100" Date: Fri, 08 Oct 2004 16:04:42 -0400 Message-ID: <15493.1097265882@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM X-Spam-Level: * X-Archive-Number: 200410/109 X-Sequence-Number: 8585 "Gary Doades" writes: > If I remove the redundant clauses, the planner now estimates 1000 rows returned from > the table, not unreasonable since it has no statistics. But *why* in that case, with *more* > estimated rows does it choose to materialize that table (26 rows) 573416 times!!! It isn't. It's materializing that once and scanning it 573416 times, once for each row in the outer relation. And this is not a bad plan given the estimates. If it had stuck to what you call the good plan, and there *had* been 1000 rows in the temp table, that plan would have run 1000 times longer than it did. As a general rule, if your complaint is that you get a bad plan for an unanalyzed table, the response is going to be "so analyze the table". regards, tom lane