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

Function transformWholeRowRef

src/backend/parser/parse_expr.c:2677–2736  ·  view source on GitHub ↗

* Construct a whole-row reference to represent the notation "relation.*". */

Source from the content-addressed store, hash-verified

2675 * Construct a whole-row reference to represent the notation "relation.*".
2676 */
2677static Node *
2678transformWholeRowRef(ParseState *pstate, ParseNamespaceItem *nsitem,
2679 int sublevels_up, int location)
2680{
2681 /*
2682 * Build the appropriate referencing node. Normally this can be a
2683 * whole-row Var, but if the nsitem is a JOIN USING alias then it contains
2684 * only a subset of the columns of the underlying join RTE, so that will
2685 * not work. Instead we immediately expand the reference into a RowExpr.
2686 * Since the JOIN USING's common columns are fully determined at this
2687 * point, there seems no harm in expanding it now rather than during
2688 * planning.
2689 *
2690 * Note that if the RTE is a function returning scalar, we create just a
2691 * plain reference to the function value, not a composite containing a
2692 * single column. This is pretty inconsistent at first sight, but it's
2693 * what we've done historically. One argument for it is that "rel" and
2694 * "rel.*" mean the same thing for composite relations, so why not for
2695 * scalar functions...
2696 */
2697 if (nsitem->p_names == nsitem->p_rte->eref)
2698 {
2699 Var *result;
2700
2701 result = makeWholeRowVar(nsitem->p_rte, nsitem->p_rtindex,
2702 sublevels_up, true);
2703
2704 /* location is not filled in by makeWholeRowVar */
2705 result->location = location;
2706
2707 /* mark relation as requiring whole-row SELECT access */
2708 markVarForSelectPriv(pstate, result);
2709
2710 return (Node *) result;
2711 }
2712 else
2713 {
2714 RowExpr *rowexpr;
2715 List *fields;
2716
2717 /*
2718 * We want only as many columns as are listed in p_names->colnames,
2719 * and we should use those names not whatever possibly-aliased names
2720 * are in the RTE. We needn't worry about marking the RTE for SELECT
2721 * access, as the common columns are surely so marked already.
2722 */
2723 expandRTE(nsitem->p_rte, nsitem->p_rtindex,
2724 sublevels_up, location, false,
2725 NULL, &fields);
2726 rowexpr = makeNode(RowExpr);
2727 rowexpr->args = list_truncate(fields,
2728 list_length(nsitem->p_names->colnames));
2729 rowexpr->row_typeid = RECORDOID;
2730 rowexpr->row_format = COERCE_IMPLICIT_CAST;
2731 rowexpr->colnames = copyObject(nsitem->p_names->colnames);
2732 rowexpr->location = location;
2733
2734 return (Node *) rowexpr;

Callers 1

transformColumnRefFunction · 0.85

Calls 5

makeWholeRowVarFunction · 0.85
markVarForSelectPrivFunction · 0.85
expandRTEFunction · 0.85
list_truncateFunction · 0.85
list_lengthFunction · 0.85

Tested by

no test coverage detected