pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>
Subject: Re: Minor code improvements to create_foreignscan_plan/ExecInitForeignScan
Date: Fri, 15 Jan 2016 19:00:25 +0900
Message-ID: <5698C339.1030708@lab.ntt.co.jp> (raw)
In-Reply-To: <5694C092.5030409@lab.ntt.co.jp>
References: <20160111173627.GA734623@alvherre.pgsql>
	<5694C092.5030409@lab.ntt.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

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.

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

Attachments:

create-foreignscan-plan-v3.patch (application/x-patch, 3.6K) download *** a/src/backend/optimizer/plan/createplan.c --- b/src/backend/optimizer/plan/createplan.c *************** *** 2097,2106 **** 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; Plan *outer_plan = NULL; - ListCell *lc; - int i; Assert(rel->fdwroutine != NULL); --- 2097,2103 ---- *************** *** 2169,2204 **** 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; } --- 2166,2229 ---- } /* ! * 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 with relid 0 in the reltargetlist or the ! * restriction clauses, so we skip this in that case. Note that any such ! * columns in base relations that were joined are assumed to be contained ! * in fdw_scan_tlist.) 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); ! /* 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; ! } } ! /* Examine all the attributes used by restriction clauses, if needed */ ! if (!scan_plan->fsSystemCol) ! { ! foreach(lc, rel->baserestrictinfo) ! { ! RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc); ! ! pull_varattnos((Node *) rinfo->clause, scan_relid, &attrs_used); ! ! /* 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; ! } ! } ! ! if (scan_plan->fsSystemCol) ! break; ! } ! } ! ! bms_free(attrs_used); ! } return scan_plan; }

view thread (22+ messages)  latest in thread

Message-ID: <5698C339.1030708@lab.ntt.co.jp>
Permalink:  ../5698C339.1030708@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/5698C339.1030708@lab.ntt.co.jp

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: fujita.etsuro@lab.ntt.co.jp, alvherre@2ndquadrant.com, robertmhaas@gmail.com, michael.paquier@gmail.com
  Subject: Re: Minor code improvements to create_foreignscan_plan/ExecInitForeignScan
  In-Reply-To: <5698C339.1030708@lab.ntt.co.jp>
  References: <20160111173627.GA734623@alvherre.pgsql> <5694C092.5030409@lab.ntt.co.jp> <5698C339.1030708@lab.ntt.co.jp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox