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

Function transformSetOperationTree

src/backend/parser/analyze.c:2091–2125  ·  view source on GitHub ↗

* transformSetOperationTree * Recursively transform leaves and internal nodes of a set-op tree * * In addition to returning the transformed node, if targetlist isn't NULL * then we return a list of its non-resjunk TargetEntry nodes. For a leaf * set-op node these are the actual targetlist entries; otherwise they are * dummy entries created to carry the type, typmod, collation, and location

Source from the content-addressed store, hash-verified

2089 * replace UNKNOWN Consts with properly-coerced constants.
2090 */
2091static Node *
2092transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
2093 bool isTopLevel, List **targetlist)
2094{
2095 setop_types_ctx ctx;
2096 Node *top;
2097 List *selected_types;
2098 List *selected_typmods;
2099
2100 /*
2101 * Transform all the subtrees.
2102 */
2103 ctx.ncols = -1;
2104 ctx.leafinfos = NULL;
2105 top = transformSetOperationTree_internal(pstate, stmt, isTopLevel, &ctx);
2106 Assert(ctx.ncols >= 0);
2107
2108 /*
2109 * We have now transformed all the subtrees, and collected all the
2110 * data types and typmods of the columns from each leaf node.
2111 *
2112 * In PostgreSQL, we also choose the result type for each subtree as we
2113 * recurse, but in GPDB, we do that here as a separate pass. That way, we
2114 * have can make the decision globally based on every leaf, rather
2115 * separately for each subtree.
2116 *
2117 * There are also some hacks to more leniently coerce between types, to
2118 * make some cases not error out.
2119 */
2120 select_setop_types(pstate, &ctx, stmt->op, &selected_types, &selected_typmods);
2121
2122 coerceSetOpTypes(pstate, top, selected_types, selected_typmods, targetlist);
2123
2124 return top;
2125}
2126
2127static void
2128select_setop_types(ParseState *pstate, setop_types_ctx *ctx, SetOperation op, List **selected_types, List **selected_typmods)

Callers 1

Calls 3

select_setop_typesFunction · 0.85
coerceSetOpTypesFunction · 0.85

Tested by

no test coverage detected