Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 024671DCB2B2 for ; Mon, 27 Feb 2012 20:17:14 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2Aki-0007iT-GS for pgsql-performance@postgresql.org; Tue, 28 Feb 2012 00:17:13 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q1S0Gu2m022246; Mon, 27 Feb 2012 19:16:56 -0500 (EST) To: Mark Hills cc: pgsql-performance@postgresql.org Subject: Re: Index condition in a Nested Loop In-reply-to: References: <16098.1330290020@sss.pgh.pa.us> Comments: In-reply-to Mark Hills message dated "Mon, 27 Feb 2012 23:13:57 +0000" Date: Mon, 27 Feb 2012 19:16:56 -0500 Message-ID: <22245.1330388216@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/240 X-Sequence-Number: 46412 Mark Hills writes: > I hadn't realised that sub-queries restrict the planner so much. Although > at some point I've picked up a habit of avoiding them, presumably for this > reason. > If you have time to explain, I'd be interested in a suggestion for any > change to the planner that could make a small contribution towards > improving this. eg. a small project that could get me into the planner > code. Well, if it were easy to do, we'd probably have done it already ... Plain subqueries might perhaps be turned into joins (with special join types no doubt), but I'm not sure what we'd do about subqueries with grouping or aggregation, as your examples had. There was some talk a month or three back about allowing such subqueries to have parameterized paths a la the recently-added parameterized path mechanism, but it didn't get further than idle speculation. regards, tom lane