@@ -2099,10 +2099,7 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
2099
2099
RelOptInfo * rel = best_path -> path .parent ;
2100
2100
Index scan_relid = rel -> relid ;
2101
2101
Oid rel_oid = InvalidOid ;
2102
- Bitmapset * attrs_used = NULL ;
2103
2102
Plan * outer_plan = NULL ;
2104
- ListCell * lc ;
2105
- int i ;
2106
2103
2107
2104
Assert (rel -> fdwroutine != NULL );
2108
2105
@@ -2180,36 +2177,48 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
2180
2177
}
2181
2178
2182
2179
/*
2183
- * Detect whether any system columns are requested from rel. This is a
2184
- * bit of a kluge and might go away someday, so we intentionally leave it
2185
- * out of the API presented to FDWs.
2186
- *
2187
- * First, examine all the attributes needed for joins or final output.
2188
- * Note: we must look at reltargetlist, not the attr_needed data, because
2189
- * attr_needed isn't computed for inheritance child rels .
2180
+ * If rel is a base relation, detect whether any system columns are
2181
+ * requested from the rel. (If rel is a join relation, rel->relid will be
2182
+ * 0, but there can be no Var with relid 0 in the reltargetlist or the
2183
+ * restriction clauses, so we skip this in that case. Note that any such
2184
+ * columns in base relations that were joined are assumed to be contained
2185
+ * in fdw_scan_tlist.) This is a bit of a kluge and might go away someday,
2186
+ * so we intentionally leave it out of the API presented to FDWs .
2190
2187
*/
2191
- pull_varattnos ((Node * ) rel -> reltargetlist , rel -> relid , & attrs_used );
2192
-
2193
- /* Add all the attributes used by restriction clauses. */
2194
- foreach (lc , rel -> baserestrictinfo )
2188
+ scan_plan -> fsSystemCol = false;
2189
+ if (scan_relid > 0 )
2195
2190
{
2196
- RestrictInfo * rinfo = (RestrictInfo * ) lfirst (lc );
2191
+ Bitmapset * attrs_used = NULL ;
2192
+ ListCell * lc ;
2193
+ int i ;
2197
2194
2198
- pull_varattnos ((Node * ) rinfo -> clause , rel -> relid , & attrs_used );
2199
- }
2195
+ /*
2196
+ * First, examine all the attributes needed for joins or final output.
2197
+ * Note: we must look at reltargetlist, not the attr_needed data,
2198
+ * because attr_needed isn't computed for inheritance child rels.
2199
+ */
2200
+ pull_varattnos ((Node * ) rel -> reltargetlist , scan_relid , & attrs_used );
2200
2201
2201
- /* Now, are any system columns requested from rel? */
2202
- scan_plan -> fsSystemCol = false;
2203
- for (i = FirstLowInvalidHeapAttributeNumber + 1 ; i < 0 ; i ++ )
2204
- {
2205
- if (bms_is_member (i - FirstLowInvalidHeapAttributeNumber , attrs_used ))
2202
+ /* Add all the attributes used by restriction clauses. */
2203
+ foreach (lc , rel -> baserestrictinfo )
2206
2204
{
2207
- scan_plan -> fsSystemCol = true;
2208
- break ;
2205
+ RestrictInfo * rinfo = (RestrictInfo * ) lfirst (lc );
2206
+
2207
+ pull_varattnos ((Node * ) rinfo -> clause , scan_relid , & attrs_used );
2209
2208
}
2210
- }
2211
2209
2212
- bms_free (attrs_used );
2210
+ /* Now, are any system columns requested from rel? */
2211
+ for (i = FirstLowInvalidHeapAttributeNumber + 1 ; i < 0 ; i ++ )
2212
+ {
2213
+ if (bms_is_member (i - FirstLowInvalidHeapAttributeNumber , attrs_used ))
2214
+ {
2215
+ scan_plan -> fsSystemCol = true;
2216
+ break ;
2217
+ }
2218
+ }
2219
+
2220
+ bms_free (attrs_used );
2221
+ }
2213
2222
2214
2223
return scan_plan ;
2215
2224
}
0 commit comments