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

Function copy_plpgsql_datums

src/pl/plpgsql/src/pl_exec.c:1271–1338  ·  view source on GitHub ↗

---------- * Support function for initializing local execution variables * ---------- */

Source from the content-addressed store, hash-verified

1269 * ----------
1270 */
1271static void
1272copy_plpgsql_datums(PLpgSQL_execstate *estate,
1273 PLpgSQL_function *func)
1274{
1275 int ndatums = estate->ndatums;
1276 PLpgSQL_datum **indatums;
1277 PLpgSQL_datum **outdatums;
1278 char *workspace;
1279 char *ws_next;
1280 int i;
1281
1282 /* Allocate local datum-pointer array */
1283 estate->datums = (PLpgSQL_datum **)
1284 palloc(sizeof(PLpgSQL_datum *) * ndatums);
1285
1286 /*
1287 * To reduce palloc overhead, we make a single palloc request for all the
1288 * space needed for locally-instantiated datums.
1289 */
1290 workspace = palloc(func->copiable_size);
1291 ws_next = workspace;
1292
1293 /* Fill datum-pointer array, copying datums into workspace as needed */
1294 indatums = func->datums;
1295 outdatums = estate->datums;
1296 for (i = 0; i < ndatums; i++)
1297 {
1298 PLpgSQL_datum *indatum = indatums[i];
1299 PLpgSQL_datum *outdatum;
1300
1301 /* This must agree with plpgsql_finish_datums on what is copiable */
1302 switch (indatum->dtype)
1303 {
1304 case PLPGSQL_DTYPE_VAR:
1305 case PLPGSQL_DTYPE_PROMISE:
1306 outdatum = (PLpgSQL_datum *) ws_next;
1307 memcpy(outdatum, indatum, sizeof(PLpgSQL_var));
1308 ws_next += MAXALIGN(sizeof(PLpgSQL_var));
1309 break;
1310
1311 case PLPGSQL_DTYPE_REC:
1312 outdatum = (PLpgSQL_datum *) ws_next;
1313 memcpy(outdatum, indatum, sizeof(PLpgSQL_rec));
1314 ws_next += MAXALIGN(sizeof(PLpgSQL_rec));
1315 break;
1316
1317 case PLPGSQL_DTYPE_ROW:
1318 case PLPGSQL_DTYPE_RECFIELD:
1319
1320 /*
1321 * These datum records are read-only at runtime, so no need to
1322 * copy them (well, RECFIELD contains cached data, but we'd
1323 * just as soon centralize the caching anyway).
1324 */
1325 outdatum = indatum;
1326 break;
1327
1328 default:

Callers 3

plpgsql_exec_functionFunction · 0.85
plpgsql_exec_triggerFunction · 0.85

Calls 1

pallocFunction · 0.50

Tested by

no test coverage detected