| 1175 | */ |
| 1176 | |
| 1177 | ForeignScan * |
| 1178 | BuildForeignScan(Oid relid, Index scanrelid, List *qual, List *targetlist, Query *query, RangeTblEntry *rte) |
| 1179 | { |
| 1180 | PlannerInfo *root; |
| 1181 | root = makeNode(PlannerInfo); |
| 1182 | root->is_from_orca = true; |
| 1183 | root->parse = query; |
| 1184 | |
| 1185 | int targetlist_length = scanrelid + 1; |
| 1186 | /* Arrays are accessed using RT indexes (1..N) */ |
| 1187 | root->simple_rel_array_size = targetlist_length; |
| 1188 | |
| 1189 | /* simple_rel_array is initialized to all NULLs */ |
| 1190 | root->simple_rel_array = (RelOptInfo **) palloc0(targetlist_length * sizeof(RelOptInfo *)); |
| 1191 | |
| 1192 | /* simple_rte_array is an array equivalent of the rtable list */ |
| 1193 | root->simple_rte_array = (RangeTblEntry **) palloc0(targetlist_length * sizeof(RangeTblEntry *)); |
| 1194 | root->simple_rte_array[scanrelid] = rte; |
| 1195 | |
| 1196 | // We need to convert qual expression list to a list of restriction expressions |
| 1197 | // This is an assumption in the deparsing logic of the quals that is used |
| 1198 | // within the GetForeignPlan API calls |
| 1199 | ListCell *lc = NULL; |
| 1200 | List *restrictQuals = NIL; |
| 1201 | foreach(lc, qual) |
| 1202 | { |
| 1203 | Expr *expr = (Expr *) lfirst(lc); |
| 1204 | restrictQuals = lappend(restrictQuals, make_simple_restrictinfo(root, expr)); |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | RelOptInfo *rel = build_simple_rel(root, scanrelid, NULL /*parent*/); |
| 1209 | // baserestrictinfo is used when separating local vs remote calls |
| 1210 | rel->baserestrictinfo = restrictQuals; |
| 1211 | // Used by FDWs, which populate attrs_used from the reltarget |
| 1212 | rel->reltarget = make_pathtarget_from_tlist(targetlist); |
| 1213 | |
| 1214 | rel->fdwroutine->GetForeignRelSize(root, rel, relid); |
| 1215 | rel->fdwroutine->GetForeignPaths(root, rel, relid); |
| 1216 | |
| 1217 | // Use any path, we really just care about the fdw_private field here |
| 1218 | ForeignPath *path = (ForeignPath*) linitial(rel->pathlist); |
| 1219 | |
| 1220 | // We need to call GetForeignPlan as some FDWs (eg: the postgres fdw) populate fdw_private in this function |
| 1221 | ForeignScan *fscan = rel->fdwroutine->GetForeignPlan(root, rel, relid, |
| 1222 | path, |
| 1223 | targetlist, restrictQuals, |
| 1224 | NULL /*outer_plan*/); |
| 1225 | |
| 1226 | fscan->fs_server = rel->serverid; |
| 1227 | |
| 1228 | // Set fsSystemCol if any system attributes are projected |
| 1229 | fscan->fsSystemCol = false; |
| 1230 | if (scanrelid > 0) |
| 1231 | { |
| 1232 | Bitmapset *attrs_used = NULL; |
| 1233 | int i; |
| 1234 |
no test coverage detected