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

Function buildNSItemFromTupleDesc

src/backend/parser/parse_relation.c:1249–1294  ·  view source on GitHub ↗

* buildNSItemFromTupleDesc * Build a ParseNamespaceItem, given a tupdesc describing the columns. * * rte: the new RangeTblEntry for the rel * rtindex: its index in the rangetable list * tupdesc: the physical column information */

Source from the content-addressed store, hash-verified

1247 * tupdesc: the physical column information
1248 */
1249static ParseNamespaceItem *
1250buildNSItemFromTupleDesc(RangeTblEntry *rte, Index rtindex, TupleDesc tupdesc)
1251{
1252 ParseNamespaceItem *nsitem;
1253 ParseNamespaceColumn *nscolumns;
1254 int maxattrs = tupdesc->natts;
1255 int varattno;
1256
1257 /* colnames must have the same number of entries as the nsitem */
1258 Assert(maxattrs == list_length(rte->eref->colnames));
1259
1260 /* extract per-column data from the tupdesc */
1261 nscolumns = (ParseNamespaceColumn *)
1262 palloc0(maxattrs * sizeof(ParseNamespaceColumn));
1263
1264 for (varattno = 0; varattno < maxattrs; varattno++)
1265 {
1266 Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno);
1267
1268 /* For a dropped column, just leave the entry as zeroes */
1269 if (attr->attisdropped)
1270 continue;
1271
1272 nscolumns[varattno].p_varno = rtindex;
1273 nscolumns[varattno].p_varattno = varattno + 1;
1274 nscolumns[varattno].p_vartype = attr->atttypid;
1275 nscolumns[varattno].p_vartypmod = attr->atttypmod;
1276 nscolumns[varattno].p_varcollid = attr->attcollation;
1277 nscolumns[varattno].p_varnosyn = rtindex;
1278 nscolumns[varattno].p_varattnosyn = varattno + 1;
1279 }
1280
1281 /* ... and build the nsitem */
1282 nsitem = (ParseNamespaceItem *) palloc(sizeof(ParseNamespaceItem));
1283 nsitem->p_names = rte->eref;
1284 nsitem->p_rte = rte;
1285 nsitem->p_rtindex = rtindex;
1286 nsitem->p_nscolumns = nscolumns;
1287 /* set default visibility flags; might get changed later */
1288 nsitem->p_rel_visible = true;
1289 nsitem->p_cols_visible = true;
1290 nsitem->p_lateral_only = false;
1291 nsitem->p_lateral_ok = true;
1292
1293 return nsitem;
1294}
1295
1296/*
1297 * buildNSItemFromLists

Callers 4

addRangeTableEntryFunction · 0.85
addRangeTableEntryForENRFunction · 0.85

Calls 3

list_lengthFunction · 0.85
palloc0Function · 0.50
pallocFunction · 0.50

Tested by

no test coverage detected