Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUcTo-0008VB-VB for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jan 2017 16:56:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cUcTo-0002iN-IF for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jan 2017 16:56:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cUcTn-0002hz-OO for pgsql-bugs@postgresql.org; Fri, 20 Jan 2017 16:55:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cUcTk-0004dD-CU for pgsql-bugs@postgresql.org; Fri, 20 Jan 2017 16:55:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v0KGtlVg014720; Fri, 20 Jan 2017 11:55:48 -0500 From: Tom Lane To: Jeff Janes cc: Pg Bugs Subject: Re: BUG #14505: explain verbose for postgresql_fdw In-reply-to: References: <20170118234359.1430.69705@wrigleys.postgresql.org> <20910.1484789276@sss.pgh.pa.us> Comments: In-reply-to Jeff Janes message dated "Fri, 20 Jan 2017 08:40:40 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14718.1484931347.1@sss.pgh.pa.us> Date: Fri, 20 Jan 2017 11:55:47 -0500 Message-ID: <14719.1484931347@sss.pgh.pa.us> X-Pg-Spam-Score: -5.1 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Jeff Janes writes: > On Wed, Jan 18, 2017 at 5:27 PM, Tom Lane wrote: >> jeff.janes@gmail.com writes: >>> The "Output:" line of explain verbose lists columns of foreign table that >>> are not actually output, or at least ought not be output. >> That's an optimization to avoid an unnecessary projection step. It has >> nothing to do with what's retrieved from the remote, and for that matter >> it's not specific to foreign tables. > Is all of that data actually being transferred from the foreign to the > local? Well, that would depend on the particular FDW, but postgres_fdw doesn't transfer unneeded columns, as you can tell by looking at the "Remote SQL" command. The key point here is that the output of the ForeignScan plan node has to match the declared rowtype of the foreign table. So what postgres_fdw is going to do, after retrieving the subset of columns that it detected were used in the query, is construct a dummy tuple that has all the columns but fills in nulls for the unused ones. The point of what the planner is doing with the node output is that we don't need to run ExecProject just to throw away those nulls again; we can pass the dummy tuple up to the join node as-is. (In some cases, like if we had to pass the tuples through a sort, it'd be worth projecting to remove unused columns ... but the planner knows that, and generates a minimal output tlist in those cases. This isn't one of those cases.) > If so, I don't think the optimization is a good choice in this case. I think you're mistaken. The alternative that we could have used is to require FDWs to emit tuples containing only used columns --- but that would *require* all FDWs to contain the logic about identifying used columns, and for at least some kinds of FDW it would add processing not subtract it. It'd also complicate matters elsewhere, because ForeignScan would act quite a bit different from scans on regular tables. In those scans, the raw tuples are necessarily going to contain all columns. > Do you know where can I find the relevant source code which decides > on this? See use_physical_tlist in createplan.c. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs