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

Function addRangeTableEntryForJoin

src/backend/parser/parse_relation.c:2366–2462  ·  view source on GitHub ↗

* Add an entry for a join to the pstate's range table (p_rtable). * Then, construct and return a ParseNamespaceItem for the new RTE. * * This is much like addRangeTableEntry() except that it makes a join RTE. * Also, it's more convenient for the caller to construct the * ParseNamespaceColumn array, so we pass that in. */

Source from the content-addressed store, hash-verified

2364 * ParseNamespaceColumn array, so we pass that in.
2365 */
2366ParseNamespaceItem *
2367addRangeTableEntryForJoin(ParseState *pstate,
2368 List *colnames,
2369 ParseNamespaceColumn *nscolumns,
2370 JoinType jointype,
2371 int nummergedcols,
2372 List *aliasvars,
2373 List *leftcols,
2374 List *rightcols,
2375 Alias *join_using_alias,
2376 Alias *alias,
2377 bool inFromCl)
2378{
2379 RangeTblEntry *rte = makeNode(RangeTblEntry);
2380 Alias *eref;
2381 int numaliases;
2382 ParseNamespaceItem *nsitem;
2383
2384 Assert(pstate != NULL);
2385
2386 /*
2387 * Fail if join has too many columns --- we must be able to reference any
2388 * of the columns with an AttrNumber.
2389 */
2390 if (list_length(aliasvars) > MaxAttrNumber)
2391 ereport(ERROR,
2392 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2393 errmsg("joins can have at most %d columns",
2394 MaxAttrNumber)));
2395
2396 rte->rtekind = RTE_JOIN;
2397 rte->relid = InvalidOid;
2398 rte->subquery = NULL;
2399 rte->jointype = jointype;
2400 rte->joinmergedcols = nummergedcols;
2401 rte->joinaliasvars = aliasvars;
2402 rte->joinleftcols = leftcols;
2403 rte->joinrightcols = rightcols;
2404 rte->join_using_alias = join_using_alias;
2405 rte->alias = alias;
2406
2407 eref = alias ? copyObject(alias) : makeAlias("unnamed_join", NIL);
2408 numaliases = list_length(eref->colnames);
2409
2410 /* fill in any unspecified alias columns */
2411 if (numaliases < list_length(colnames))
2412 eref->colnames = list_concat(eref->colnames,
2413 list_copy_tail(colnames, numaliases));
2414
2415 if (numaliases > list_length(colnames))
2416 ereport(ERROR,
2417 (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2418 errmsg("join expression \"%s\" has %d columns available but %d columns specified",
2419 eref->aliasname, list_length(colnames), numaliases)));
2420
2421 rte->eref = eref;
2422
2423 /*

Callers 2

transformFromClauseItemFunction · 0.85

Calls 8

list_lengthFunction · 0.85
makeAliasFunction · 0.85
list_concatFunction · 0.85
list_copy_tailFunction · 0.85
lappendFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
pallocFunction · 0.50

Tested by

no test coverage detected