* ExecGetRangeTableRelation * Open the Relation for a range table entry, if not already done * * The Relations will be closed again in ExecEndPlan(). */
| 836 | * The Relations will be closed again in ExecEndPlan(). |
| 837 | */ |
| 838 | Relation |
| 839 | ExecGetRangeTableRelation(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 |
no test coverage detected