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

Function ExecLookupResultRelByOid

src/backend/executor/nodeModifyTable.c:3075–3118  ·  view source on GitHub ↗

* ExecLookupResultRelByOid * If the table with given OID is among the result relations to be * updated by the given ModifyTable node, return its ResultRelInfo. * * If not found, return NULL if missing_ok, else raise error. * * If update_cache is true, then upon successful lookup, update the node's * one-element cache. ONLY ExecModifyTable may pass true for this. */

Source from the content-addressed store, hash-verified

3073 * one-element cache. ONLY ExecModifyTable may pass true for this.
3074 */
3075ResultRelInfo *
3076ExecLookupResultRelByOid(ModifyTableState *node, Oid resultoid,
3077 bool missing_ok, bool update_cache)
3078{
3079 if (node->mt_resultOidHash)
3080 {
3081 /* Use the pre-built hash table to locate the rel */
3082 MTTargetRelLookup *mtlookup;
3083
3084 mtlookup = (MTTargetRelLookup *)
3085 hash_search(node->mt_resultOidHash, &resultoid, HASH_FIND, NULL);
3086 if (mtlookup)
3087 {
3088 if (update_cache)
3089 {
3090 node->mt_lastResultOid = resultoid;
3091 node->mt_lastResultIndex = mtlookup->relationIndex;
3092 }
3093 return node->resultRelInfo + mtlookup->relationIndex;
3094 }
3095 }
3096 else
3097 {
3098 /* With few target rels, just search the ResultRelInfo array */
3099 for (int ndx = 0; ndx < node->mt_nrels; ndx++)
3100 {
3101 ResultRelInfo *rInfo = node->resultRelInfo + ndx;
3102
3103 if (RelationGetRelid(rInfo->ri_RelationDesc) == resultoid)
3104 {
3105 if (update_cache)
3106 {
3107 node->mt_lastResultOid = resultoid;
3108 node->mt_lastResultIndex = ndx;
3109 }
3110 return rInfo;
3111 }
3112 }
3113 }
3114
3115 if (!missing_ok)
3116 elog(ERROR, "incorrect result relation OID %u", resultoid);
3117 return NULL;
3118}
3119
3120/* ----------------------------------------------------------------
3121 * ExecInitModifyTable

Callers 2

ExecModifyTableFunction · 0.85
ExecFindPartitionFunction · 0.85

Calls 1

hash_searchFunction · 0.85

Tested by

no test coverage detected