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

Function GetFdwRoutineForRelation

src/backend/foreign/foreign.c:695–726  ·  view source on GitHub ↗

* GetFdwRoutineForRelation - look up the handler of the foreign-data wrapper * for the given foreign table, and retrieve its FdwRoutine struct. * * This function is preferred over GetFdwRoutineByRelId because it caches * the data in the relcache entry, saving a number of catalog lookups. * * If makecopy is true then the returned data is freshly palloc'd in the * caller's memory context. Ot

Source from the content-addressed store, hash-verified

693 * which will be lost in any relcache reset --- so don't rely on it long.
694 */
695FdwRoutine *
696GetFdwRoutineForRelation(Relation relation, bool makecopy)
697{
698 FdwRoutine *fdwroutine;
699 FdwRoutine *cfdwroutine;
700
701 if (relation->rd_fdwroutine == NULL)
702 {
703 /* Get the info by consulting the catalogs and the FDW code */
704 fdwroutine = GetFdwRoutineByRelId(RelationGetRelid(relation));
705
706 /* Save the data for later reuse in CacheMemoryContext */
707 cfdwroutine = (FdwRoutine *) MemoryContextAlloc(CacheMemoryContext,
708 sizeof(FdwRoutine));
709 memcpy(cfdwroutine, fdwroutine, sizeof(FdwRoutine));
710 relation->rd_fdwroutine = cfdwroutine;
711
712 /* Give back the locally palloc'd copy regardless of makecopy */
713 return fdwroutine;
714 }
715
716 /* We have valid cached data --- does the caller want a copy? */
717 if (makecopy)
718 {
719 fdwroutine = (FdwRoutine *) palloc(sizeof(FdwRoutine));
720 memcpy(fdwroutine, relation->rd_fdwroutine, sizeof(FdwRoutine));
721 return fdwroutine;
722 }
723
724 /* Only a short-lived reference is needed, so just hand back cached copy */
725 return relation->rd_fdwroutine;
726}
727
728
729/*

Callers 12

relation_is_updatableFunction · 0.85
pg_relation_sizeFunction · 0.85
cbdb_relation_sizeFunction · 0.85
analyze_rel_internalFunction · 0.85
CheckValidRowMarkRelFunction · 0.85
InitResultRelInfoFunction · 0.85
EvalPlanQualFetchRowMarkFunction · 0.85
ExecLockRowsFunction · 0.85
add_row_identity_columnsFunction · 0.85
get_relation_infoFunction · 0.85

Calls 3

GetFdwRoutineByRelIdFunction · 0.85
MemoryContextAllocFunction · 0.85
pallocFunction · 0.50

Tested by

no test coverage detected