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

Function scanNameSpaceForRelid

src/backend/parser/parse_relation.c:225–259  ·  view source on GitHub ↗

* Search the query's table namespace for a relation item matching the * given relation OID. Return the nsitem if a unique match, or NULL * if no match. Raise error if multiple matches. * * See the comments for refnameNamespaceItem to understand why this * acts the way it does. */

Source from the content-addressed store, hash-verified

223 * acts the way it does.
224 */
225static ParseNamespaceItem *
226scanNameSpaceForRelid(ParseState *pstate, Oid relid, int location)
227{
228 ParseNamespaceItem *result = NULL;
229 ListCell *l;
230
231 foreach(l, pstate->p_namespace)
232 {
233 ParseNamespaceItem *nsitem = (ParseNamespaceItem *) lfirst(l);
234 RangeTblEntry *rte = nsitem->p_rte;
235
236 /* Ignore columns-only items */
237 if (!nsitem->p_rel_visible)
238 continue;
239 /* If not inside LATERAL, ignore lateral-only items */
240 if (nsitem->p_lateral_only && !pstate->p_lateral_active)
241 continue;
242
243 /* yes, the test for alias == NULL should be there... */
244 if (rte->rtekind == RTE_RELATION &&
245 rte->relid == relid &&
246 rte->alias == NULL)
247 {
248 if (result)
249 ereport(ERROR,
250 (errcode(ERRCODE_AMBIGUOUS_ALIAS),
251 errmsg("table reference %u is ambiguous",
252 relid),
253 parser_errposition(pstate, location)));
254 check_lateral_ref_ok(pstate, nsitem, location);
255 result = nsitem;
256 }
257 }
258 return result;
259}
260
261/*
262 * Search the query's CTE namespace for a CTE matching the given unqualified

Callers 1

refnameNamespaceItemFunction · 0.85

Calls 5

parser_errpositionFunction · 0.85
check_lateral_ref_okFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected