* GetForeignTable - look up the foreign table definition by relation oid. */
| 459 | * GetForeignTable - look up the foreign table definition by relation oid. |
| 460 | */ |
| 461 | ForeignTable * |
| 462 | GetForeignTable(Oid relid) |
| 463 | { |
| 464 | Form_pg_foreign_table tableform; |
| 465 | ForeignTable *ft; |
| 466 | HeapTuple tp; |
| 467 | Datum datum; |
| 468 | bool isnull; |
| 469 | |
| 470 | tp = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(relid)); |
| 471 | if (!HeapTupleIsValid(tp)) |
| 472 | elog(ERROR, "cache lookup failed for foreign table %u", relid); |
| 473 | tableform = (Form_pg_foreign_table) GETSTRUCT(tp); |
| 474 | |
| 475 | ft = (ForeignTable *) palloc(sizeof(ForeignTable)); |
| 476 | ft->relid = relid; |
| 477 | ft->serverid = tableform->ftserver; |
| 478 | |
| 479 | /* Extract the ftoptions */ |
| 480 | datum = SysCacheGetAttr(FOREIGNTABLEREL, |
| 481 | tp, |
| 482 | Anum_pg_foreign_table_ftoptions, |
| 483 | &isnull); |
| 484 | if (isnull) |
| 485 | ft->options = NIL; |
| 486 | else |
| 487 | ft->options = untransformRelOptions(datum); |
| 488 | |
| 489 | ReleaseSysCache(tp); |
| 490 | |
| 491 | ft->exec_location = SeparateOutMppExecute(&ft->options); |
| 492 | |
| 493 | if (ft->exec_location == FTEXECLOCATION_ALL_SEGMENTS && |
| 494 | OidIsValid(ft->serverid) && |
| 495 | Gp_role == GP_ROLE_EXECUTE) |
| 496 | { |
| 497 | ForeignTable *segFt; |
| 498 | segFt = GetForeignTableOnSegment(relid); |
| 499 | if (segFt) |
| 500 | { |
| 501 | ft->serverid = segFt->serverid; |
| 502 | |
| 503 | pfree(segFt); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | ForeignServer *server = GetForeignServer(ft->serverid); |
| 508 | |
| 509 | if (ft->exec_location == FTEXECLOCATION_NOT_DEFINED) |
| 510 | { |
| 511 | ft->exec_location = server->exec_location; |
| 512 | } |
| 513 | |
| 514 | ft->num_segments = SeparateOutNumSegments(&ft->options); |
| 515 | |
| 516 | if (ft->num_segments <= 0) |
| 517 | ft->num_segments = GetForeignTableSegNumbers(relid); |
| 518 |
no test coverage detected