Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZZcLC-0001W0-Sn for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2015 10:10:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZZcLC-0007M3-EN for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Sep 2015 10:10:58 +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 1ZZcJt-0005q3-7r for pgsql-hackers@postgresql.org; Wed, 09 Sep 2015 10:09:37 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZZcJq-00040l-0X for pgsql-hackers@postgresql.org; Wed, 09 Sep 2015 10:09:36 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id t89A9Wis012134 for ; Wed, 9 Sep 2015 19:09:32 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 3C1875F612 for ; Wed, 9 Sep 2015 19:09:32 +0900 (JST) Received: from imail3.m.ecl.ntt.co.jp (imail3.m.ecl.ntt.co.jp [129.60.5.248]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 2E4675F590 for ; Wed, 9 Sep 2015 19:09:32 +0900 (JST) Received: from [127.0.0.1] ([129.60.241.75]) by imail3.m.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id t89A9RSc006408 for ; Wed, 9 Sep 2015 19:09:32 +0900 Subject: Re: Minor code improvements to create_foreignscan_plan/ExecInitForeignScan To: pgsql-hackers@postgresql.org References: <559F9323.4080403@lab.ntt.co.jp> From: Etsuro Fujita Message-ID: <55F0051E.1020505@lab.ntt.co.jp> Date: Wed, 9 Sep 2015 19:08:30 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <559F9323.4080403@lab.ntt.co.jp> Content-Type: multipart/mixed; boundary="------------040206020804090400060204" 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 This is a multi-part message in MIME format. --------------040206020804090400060204 Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit On 2015/07/10 18:40, Etsuro Fujita wrote: > To save cycles, I modified create_foreignscan_plan so that it detects > whether any system columns are requested if scanning a base relation. > Also, I revised other code there a little bit. Attached is an updated version of the patch. The previous version contained changes to ExecInitForeignScan, but I've dropped that part, as discussed before. Best regards, Etsuro Fujita --------------040206020804090400060204 Content-Type: text/x-patch; name="create-foreignscan-plan.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="create-foreignscan-plan.patch" *** a/src/backend/optimizer/plan/createplan.c --- b/src/backend/optimizer/plan/createplan.c *************** *** 2058,2066 **** create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path, RelOptInfo *rel = best_path->path.parent; Index scan_relid = rel->relid; Oid rel_oid = InvalidOid; - Bitmapset *attrs_used = NULL; - ListCell *lc; - int i; Assert(rel->fdwroutine != NULL); --- 2058,2063 ---- *************** *** 2120,2155 **** create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path, } /* ! * Detect whether any system columns are requested from rel. This is a ! * bit of a kluge and might go away someday, so we intentionally leave it ! * out of the API presented to FDWs. ! * ! * 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, rel->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, rel->relid, &attrs_used); ! } ! /* Now, are any system columns requested from rel? */ ! scan_plan->fsSystemCol = false; ! 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; } --- 2117,2161 ---- } /* ! * If we're scanning a base relation, detect whether any system columns ! * are requested from the rel. (Irrelevant if scanning a join relation.) ! * 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; } --------------040206020804090400060204 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --------------040206020804090400060204--