aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2016-02-02 19:20:02 +0100
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2016-02-02 19:20:02 +0100
commit3cb5867b7d346eff4abcb69ca182ba658d5faecc (patch)
tree3d9c42c113f5ddbe742210432bd0e419e9b70a12
parent2ad83fff221eec2cc76f8823b0043763d0dfe0c3 (diff)
downloadpostgresql-3cb5867b7d346eff4abcb69ca182ba658d5faecc.tar.gz
postgresql-3cb5867b7d346eff4abcb69ca182ba658d5faecc.zip
Don't test for system columns on join relations
create_foreignscan_plan needs to know whether any system columns are requested from a relation (this flag is needed by ForeignNext during execution). However, for join relations this is a pointless test, because it's not possible to request system columns from them, so remove the check. Author: Etsuro Fujita Discussion: http://www.postgresql.org/message-id/56AA0FC5.9000207@lab.ntt.co.jp Reviewed-by: David Rowley, Robert Haas
-rw-r--r--src/backend/optimizer/plan/createplan.c61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index bdac0b1860b..54ff7f623d4 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -2099,10 +2099,7 @@ 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);
@@ -2180,36 +2177,48 @@ 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.
+ * 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.
*/
- pull_varattnos((Node *) rel->reltargetlist, rel->relid, &attrs_used);
-
- /* Add all the attributes used by restriction clauses. */
- foreach(lc, rel->baserestrictinfo)
+ scan_plan->fsSystemCol = false;
+ if (scan_relid > 0)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+ Bitmapset *attrs_used = NULL;
+ ListCell *lc;
+ int i;
- pull_varattnos((Node *) rinfo->clause, rel->relid, &attrs_used);
- }
+ /*
+ * 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);
- /* 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))
+ /* Add all the attributes used by restriction clauses. */
+ foreach(lc, rel->baserestrictinfo)
{
- scan_plan->fsSystemCol = true;
- break;
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
+
+ pull_varattnos((Node *) rinfo->clause, scan_relid, &attrs_used);
}
- }
- bms_free(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;
}