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

Function ExecGetRangeTableRelation

src/backend/executor/execUtils.c:838–881  ·  view source on GitHub ↗

* ExecGetRangeTableRelation * Open the Relation for a range table entry, if not already done * * The Relations will be closed again in ExecEndPlan(). */

Source from the content-addressed store, hash-verified

836 * The Relations will be closed again in ExecEndPlan().
837 */
838Relation
839ExecGetRangeTableRelation(EState *estate, Index rti)
840{
841 Relation rel;
842
843 Assert(rti > 0 && rti <= estate->es_range_table_size);
844
845 rel = estate->es_relations[rti - 1];
846 if (rel == NULL)
847 {
848 /* First time through, so open the relation */
849 RangeTblEntry *rte = exec_rt_fetch(rti, estate);
850
851 Assert(rte->rtekind == RTE_RELATION);
852
853 /* GPDB: a QE process is not holding the locks yet, same as a parallel worker. */
854 if (!IsParallelWorker() && Gp_role != GP_ROLE_EXECUTE)
855 {
856 /*
857 * In a normal query, we should already have the appropriate lock,
858 * but verify that through an Assert. Since there's already an
859 * Assert inside table_open that insists on holding some lock, it
860 * seems sufficient to check this only when rellockmode is higher
861 * than the minimum.
862 */
863 rel = table_open(rte->relid, NoLock);
864 Assert(rte->rellockmode == AccessShareLock ||
865 CheckRelationLockedByMe(rel, rte->rellockmode, false));
866 }
867 else
868 {
869 /*
870 * If we are a parallel worker, we need to obtain our own local
871 * lock on the relation. This ensures sane behavior in case the
872 * parent process exits before we do.
873 */
874 rel = table_open(rte->relid, rte->rellockmode);
875 }
876
877 estate->es_relations[rti - 1] = rel;
878 }
879
880 return rel;
881}
882
883/*
884 * ExecInitResultRelation

Callers 4

InitPlanFunction · 0.85
ExecOpenScanRelationFunction · 0.85
ExecInitResultRelationFunction · 0.85

Calls 3

exec_rt_fetchFunction · 0.85
table_openFunction · 0.85
CheckRelationLockedByMeFunction · 0.85

Tested by

no test coverage detected