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 6A21155F03 for ; Tue, 8 Mar 2005 20:42:14 +0000 (GMT) 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 91413-04 for ; Tue, 8 Mar 2005 20:42:08 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id CE35A54D3A for ; Tue, 8 Mar 2005 20:42:06 +0000 (GMT) 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 j28Kg3JI013881; Tue, 8 Mar 2005 15:42:04 -0500 (EST) To: Richard Huxton Cc: Gaetano Mendola , "pgsql-performance@postgresql.org" Subject: Re: bad plan In-reply-to: <422E0A1E.1080804@archonet.com> References: <422D7F23.7000109@bigfoot.com> <422D8F0E.8000906@archonet.com> <422D9904.5010904@bigfoot.com> <13634.1110312075@sss.pgh.pa.us> <422E0A1E.1080804@archonet.com> Comments: In-reply-to Richard Huxton message dated "Tue, 08 Mar 2005 20:25:02 +0000" Date: Tue, 08 Mar 2005 15:42:03 -0500 Message-ID: <13880.1110314523@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/141 X-Sequence-Number: 10846 Richard Huxton writes: > There are also a lot of views involved here for very few output columns. > Tom - is the planner smart enough to optimise-out unneeded columns from > a SELECT * view if it's part of a join/subquery and you only use one or > two columns? If the view gets flattened, yes, but I believe that it's not bright enough to do so when it can't flatten the view. You could tell easily enough by looking at the row-width estimates at various levels of the plan. (Let's see ... in Gaetano's plan the SubqueryScan is returning 12-byte rows where its input MergeJoin is returning 130-byte rows, so sure enough the view is computing a lot of stuff that then gets thrown away.) > Would I be right in thinking the planner doesn't materialise the > subquery because it's expecting 1 loop not 31? If there were 1 row the > plan would seem OK to me. Right; it doesn't see any predicted gain from the extra cost of materializing. But to me the main problem here is not that, it is that the entire shape of the plan would likely be different if it weren't for the "optimization fence" that the Subquery Scan node represents. I suspect too that the use of mergejoin as opposed to anything else within the vsp subplan is driven more by the need to produce sorted output than by what is the cheapest way to get the rows. regards, tom lane