diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-10-04 14:03:37 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-10-04 14:03:42 -0400 |
commit | 9ddef36278a9f676c07d0b4d9f33fa22e48ce3b5 (patch) | |
tree | ec564a5f9c1cd536a6af60a0971bf7e9900ae36c /src/include/nodes/execnodes.h | |
parent | fb9e93a2c5cf99e59a7e9362afd462f29e71bc1e (diff) |
Centralize executor's opening/closing of Relations for rangetable entries.
Create an array estate->es_relations[] paralleling the es_range_table,
and store references to Relations (relcache entries) there, so that any
given RT entry is opened and closed just once per executor run. Scan
nodes typically still call ExecOpenScanRelation, but ExecCloseScanRelation
is no more; relation closing is now done centrally in ExecEndPlan.
This is slightly more complex than one would expect because of the
interactions with relcache references held in ResultRelInfo nodes.
The general convention is now that ResultRelInfo->ri_RelationDesc does
not represent a separate relcache reference and so does not need to be
explicitly closed; but there is an exception for ResultRelInfos in the
es_trig_target_relations list, which are manufactured by
ExecGetTriggerResultRel and have to be cleaned up by
ExecCleanUpTriggerState. (That much was true all along, but these
ResultRelInfos are now more different from others than they used to be.)
To allow the partition pruning logic to make use of es_relations[] rather
than having its own relcache references, adjust PartitionedRelPruneInfo
to store an RT index rather than a relation OID.
Amit Langote, reviewed by David Rowley and Jesper Pedersen,
some mods by me
Discussion: https://postgr.es/m/468c85d9-540e-66a2-1dde-fec2b741e688@lab.ntt.co.jp
Diffstat (limited to 'src/include/nodes/execnodes.h')
-rw-r--r-- | src/include/nodes/execnodes.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 020ecdcd404..35646231a4c 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -386,12 +386,19 @@ typedef struct OnConflictSetState * Whenever we update an existing relation, we have to update indexes on the * relation, and perhaps also fire triggers. ResultRelInfo holds all the * information needed about a result relation, including indexes. + * + * Normally, a ResultRelInfo refers to a table that is in the query's + * range table; then ri_RangeTableIndex is the RT index and ri_RelationDesc + * is just a copy of the relevant es_relations[] entry. But sometimes, + * in ResultRelInfos used only for triggers, ri_RangeTableIndex is zero + * and ri_RelationDesc is a separately-opened relcache pointer that needs + * to be separately closed. See ExecGetTriggerResultRel. */ typedef struct ResultRelInfo { NodeTag type; - /* result relation's range table index */ + /* result relation's range table index, or 0 if not in range table */ Index ri_RangeTableIndex; /* relation descriptor for result relation */ @@ -479,6 +486,8 @@ typedef struct EState Snapshot es_snapshot; /* time qual to use */ Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */ List *es_range_table; /* List of RangeTblEntry */ + Relation *es_relations; /* Array of per-es_range_table-entry Relation + * pointers, or NULL if not yet opened */ PlannedStmt *es_plannedstmt; /* link to top of plan tree */ const char *es_sourceText; /* Source text from QueryDesc */ |