Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aIgOd-0003Ou-K5 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jan 2016 17:36:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aIgOd-0004eD-4T for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Jan 2016 17:36:47 +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) (envelope-from ) id 1aIgOc-0004cT-EK for pgsql-hackers@postgresql.org; Mon, 11 Jan 2016 17:36:46 +0000 Received: from out.smtp-auth.no-ip.com ([8.23.224.60]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aIgOU-0006Xz-Hk for pgsql-hackers@postgresql.org; Mon, 11 Jan 2016 17:36:45 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [200.104.53.52]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 33B73400DD3; Mon, 11 Jan 2016 09:36:29 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 585C95D2; Mon, 11 Jan 2016 14:36:27 -0300 (CLT) Date: Mon, 11 Jan 2016 14:36:27 -0300 From: Alvaro Herrera To: Etsuro Fujita Cc: Robert Haas , Michael Paquier , PostgreSQL mailing lists Subject: Re: Minor code improvements to create_foreignscan_plan/ExecInitForeignScan Message-ID: <20160111173627.GA734623@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5680DBC8.4000204@lab.ntt.co.jp> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -1.1 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org I wonder, > --- 2166,2213 ---- > } > > /* > ! * If rel is a base relation, detect whether any system columns are > ! * requested from the rel. (If rel is a join relation, rel->relid will be > ! * 0, but there can be no Var in the target list with relid 0, so we skip > ! * this in that case. Note that any such system columns are assumed to be > ! * contained in fdw_scan_tlist, so we never need fsSystemCol to be true in > ! * the joinrel case.) This is a bit of a kluge and might go away someday, > ! * so we intentionally leave it out of the API presented to FDWs. > */ > ! scan_plan->fsSystemCol = false; > ! if (scan_relid > 0) > { > ! Bitmapset *attrs_used = NULL; > ! ListCell *lc; > ! int i; > > ! /* > ! * First, examine all the attributes needed for joins or final output. > ! * Note: we must look at reltargetlist, not the attr_needed data, > ! * because attr_needed isn't computed for inheritance child rels. > ! */ > ! pull_varattnos((Node *) rel->reltargetlist, scan_relid, &attrs_used); > > ! /* Add all the attributes used by restriction clauses. */ > ! foreach(lc, rel->baserestrictinfo) > { > ! RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc); > ! > ! pull_varattnos((Node *) rinfo->clause, scan_relid, &attrs_used); > } > > ! /* Now, are any system columns requested from rel? */ > ! for (i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++) > ! { > ! if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber, attrs_used)) > ! { > ! scan_plan->fsSystemCol = true; > ! break; > ! } > ! } > ! > ! bms_free(attrs_used); > ! } > > return scan_plan; > } Would it make sense to call pull_varattnos(reltargetlist), then walk the bitmapset and break if we see a system column, then call pull_varattnos() on the rinfo->clause? That way, if the targetlist request a system column we don't have to walk the RestrictInfos. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers