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

Function addRangeTableEntryForSubquery

src/backend/parser/parse_relation.c:1654–1736  ·  view source on GitHub ↗

* Add an entry for a subquery 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 subquery RTE. * Note that an alias clause *must* be supplied. */

Source from the content-addressed store, hash-verified

1652 * Note that an alias clause *must* be supplied.
1653 */
1654ParseNamespaceItem *
1655addRangeTableEntryForSubquery(ParseState *pstate,
1656 Query *subquery,
1657 Alias *alias,
1658 bool lateral,
1659 bool inFromCl)
1660{
1661 RangeTblEntry *rte = makeNode(RangeTblEntry);
1662 char *refname = alias->aliasname;
1663 Alias *eref;
1664 int numaliases;
1665 List *coltypes,
1666 *coltypmods,
1667 *colcollations;
1668 int varattno;
1669 ListCell *tlistitem;
1670
1671 rte->rtekind = RTE_SUBQUERY;
1672 rte->subquery = subquery;
1673 rte->alias = alias;
1674
1675 eref = copyObject(alias);
1676 numaliases = list_length(eref->colnames);
1677
1678 /* fill in any unspecified alias columns, and extract column type info */
1679 coltypes = coltypmods = colcollations = NIL;
1680 varattno = 0;
1681 foreach(tlistitem, subquery->targetList)
1682 {
1683 TargetEntry *te = (TargetEntry *) lfirst(tlistitem);
1684
1685 if (te->resjunk)
1686 continue;
1687 varattno++;
1688 Assert(varattno == te->resno);
1689 if (varattno > numaliases)
1690 {
1691 char *attrname;
1692
1693 attrname = pstrdup(te->resname);
1694 eref->colnames = lappend(eref->colnames, makeString(attrname));
1695 }
1696 coltypes = lappend_oid(coltypes,
1697 exprType((Node *) te->expr));
1698 coltypmods = lappend_int(coltypmods,
1699 exprTypmod((Node *) te->expr));
1700 colcollations = lappend_oid(colcollations,
1701 exprCollation((Node *) te->expr));
1702 }
1703 if (varattno < numaliases)
1704 ereport(ERROR,
1705 (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
1706 errmsg("table \"%s\" has %d columns available but %d columns specified",
1707 refname, varattno, numaliases)));
1708
1709 rte->eref = eref;
1710
1711 /*

Callers 7

transformInsertStmtFunction · 0.85
transformRangeSubselectFunction · 0.85
add_notin_subquery_rteFunction · 0.85
add_expr_subquery_rteFunction · 0.85
make_sirvf_subqueryFunction · 0.85

Calls 13

list_lengthFunction · 0.85
lappendFunction · 0.85
makeStringFunction · 0.85
lappend_oidFunction · 0.85
exprTypeFunction · 0.85
lappend_intFunction · 0.85
exprTypmodFunction · 0.85
exprCollationFunction · 0.85
buildNSItemFromListsFunction · 0.85
foreachFunction · 0.50
pstrdupFunction · 0.50
errcodeFunction · 0.50

Tested by

no test coverage detected