| 155 | } |
| 156 | |
| 157 | ForeignScanState * |
| 158 | ExecInitForeignScanForPartition(ForeignScan *node, EState *estate, int eflags, Relation currentRelation) |
| 159 | { |
| 160 | ForeignScanState *scanstate; |
| 161 | Index scanrelid = node->scan.scanrelid; |
| 162 | Index tlistvarno; |
| 163 | FdwRoutine *fdwroutine; |
| 164 | |
| 165 | /* check for unsupported flags */ |
| 166 | Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK))); |
| 167 | |
| 168 | /* |
| 169 | * create state structure |
| 170 | */ |
| 171 | scanstate = makeNode(ForeignScanState); |
| 172 | scanstate->ss.ps.plan = (Plan *) node; |
| 173 | scanstate->ss.ps.state = estate; |
| 174 | scanstate->ss.ps.ExecProcNode = ExecForeignScan; |
| 175 | |
| 176 | /* |
| 177 | * Miscellaneous initialization |
| 178 | * |
| 179 | * create expression context for node |
| 180 | */ |
| 181 | ExecAssignExprContext(estate, &scanstate->ss.ps); |
| 182 | |
| 183 | /* |
| 184 | * open the scan relation, if any; also acquire function pointers from the |
| 185 | * FDW's handler |
| 186 | */ |
| 187 | if (scanrelid > 0) |
| 188 | { |
| 189 | scanstate->ss.ss_currentRelation = currentRelation; |
| 190 | fdwroutine = GetFdwRoutineForRelation(currentRelation, true); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | /* We can't use the relcache, so get fdwroutine the hard way */ |
| 195 | fdwroutine = GetFdwRoutineByServerId(node->fs_server); |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Determine the scan tuple type. If the FDW provided a targetlist |
| 200 | * describing the scan tuples, use that; else use base relation's rowtype. |
| 201 | */ |
| 202 | if (node->fdw_scan_tlist != NIL || currentRelation == NULL) |
| 203 | { |
| 204 | TupleDesc scan_tupdesc; |
| 205 | |
| 206 | scan_tupdesc = ExecTypeFromTL(node->fdw_scan_tlist); |
| 207 | ExecInitScanTupleSlot(estate, &scanstate->ss, scan_tupdesc, |
| 208 | &TTSOpsHeapTuple); |
| 209 | /* Node's targetlist will contain Vars with varno = INDEX_VAR */ |
| 210 | tlistvarno = INDEX_VAR; |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | TupleDesc scan_tupdesc; |
no test coverage detected