Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aLQ5q-0001lJ-8d for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jan 2016 06:48:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aLQ5p-0004Iu-N6 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jan 2016 06:48:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aLQ4U-0002px-Lf for pgsql-hackers@postgresql.org; Tue, 19 Jan 2016 06:47:18 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aLQ4Q-0007RB-OW for pgsql-hackers@postgresql.org; Tue, 19 Jan 2016 06:47:17 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id u0J6l9w2020221; Tue, 19 Jan 2016 15:47:09 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id A2F9F5F58E; Tue, 19 Jan 2016 15:47:09 +0900 (JST) Received: from imail3.m.ecl.ntt.co.jp (imail3.m.ecl.ntt.co.jp [129.60.5.248]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 94B465F63F; Tue, 19 Jan 2016 15:47:09 +0900 (JST) Received: from [IPv6:::1] ([129.60.241.75]) by imail3.m.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id u0J6kbdm018579; Tue, 19 Jan 2016 15:47:09 +0900 Subject: Re: Minor code improvements to create_foreignscan_plan/ExecInitForeignScan References: <20160111173627.GA734623@alvherre.pgsql> <5694C092.5030409@lab.ntt.co.jp> <5698C339.1030708@lab.ntt.co.jp> From: Etsuro Fujita Message-ID: <569DDB73.7000906@lab.ntt.co.jp> Date: Tue, 19 Jan 2016 15:45:07 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <5698C339.1030708@lab.ntt.co.jp> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit To: Alvaro Herrera Cc: Robert Haas , Michael Paquier , PostgreSQL mailing lists X-TM-AS-MML: disable X-Pg-Spam-Score: -2.6 (--) 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 On 2016/01/15 19:00, Etsuro Fujita wrote: > On 2016/01/12 18:00, Etsuro Fujita wrote: >> On 2016/01/12 2:36, Alvaro Herrera wrote: >>> 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. >> Seems like a good idea. Will update the patch. > Done. Attached is an updated version of the patch. On second thought, I noticed that detecting whether we see a system column that way needs more cycles in cases where the reltargetlist and the restriction clauses don't contain any system columns. ISTM that such cases are rather common, so I'm inclined to keep that code as-is. Best regards, Etsuro Fujita -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers