MCPcopy Create free account
hub / github.com/apache/cloudberry / GetForeignTable

Function GetForeignTable

src/backend/foreign/foreign.c:461–525  ·  view source on GitHub ↗

* GetForeignTable - look up the foreign table definition by relation oid. */

Source from the content-addressed store, hash-verified

459 * GetForeignTable - look up the foreign table definition by relation oid.
460 */
461ForeignTable *
462GetForeignTable(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

Callers 15

deparseRelationFunction · 0.85
postgresBeginForeignScanFunction · 0.85
create_foreign_modifyFunction · 0.85
get_batch_size_optionFunction · 0.85
fileGetOptionsFunction · 0.85

Calls 12

SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
SysCacheGetAttrFunction · 0.85
untransformRelOptionsFunction · 0.85
ReleaseSysCacheFunction · 0.85
SeparateOutMppExecuteFunction · 0.85
GetForeignTableOnSegmentFunction · 0.85
GetForeignServerFunction · 0.85
SeparateOutNumSegmentsFunction · 0.85
pallocFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected