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

Function add_expr_subquery_rte

src/backend/cdb/cdbsubselect.c:839–881  ·  view source on GitHub ↗

* Pulls up the expr sublink subquery into the top-level range table. */

Source from the content-addressed store, hash-verified

837 * Pulls up the expr sublink subquery into the top-level range table.
838 */
839static int
840add_expr_subquery_rte(Query *parse, Query *subselect)
841{
842 int subq_indx;
843 ParseNamespaceItem *pni;
844 ParseState *pstate;
845
846 /**
847 * Generate column names.
848 * TODO: improve this to keep old names around
849 */
850 ListCell *lc = NULL;
851 int teNum = 0;
852
853 foreach(lc, subselect->targetList)
854 {
855 TargetEntry *te = (TargetEntry *) lfirst(lc);
856
857 te->resname = psprintf("csq_c%d", teNum);
858 teNum++;
859 }
860
861 /* Create a dummy ParseState for addRangeTableEntryForSubquery */
862 pstate = make_parsestate(NULL);
863
864 /*
865 * Create a RTE entry in the parent query for the subquery.
866 * It is marked as lateral, because any correlation quals will
867 * refer to other RTEs in the parent query.
868 */
869 pni = addRangeTableEntryForSubquery(pstate,
870 subselect,
871 makeAlias("Expr_SUBQUERY", NIL),
872 true, /* lateral */
873 false /* inFromClause */ );
874 parse->rtable = lappend(parse->rtable, pni->p_rte);
875
876 /* assume new rte is at end */
877 subq_indx = list_length(parse->rtable);
878 Assert(pni->p_rte == rt_fetch(subq_indx, parse->rtable));
879
880 return subq_indx;
881}
882
883
884/* Create a join expression linking the supplied larg node

Callers 1

convert_EXPR_to_joinFunction · 0.85

Calls 7

psprintfFunction · 0.85
make_parsestateFunction · 0.85
makeAliasFunction · 0.85
lappendFunction · 0.85
list_lengthFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected