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

Function create_foreign_modify

contrib/postgres_fdw/postgres_fdw.c:3965–4079  ·  view source on GitHub ↗

* create_foreign_modify * Construct an execution state of a foreign insert/update/delete * operation */

Source from the content-addressed store, hash-verified

3963 * operation
3964 */
3965static PgFdwModifyState *
3966create_foreign_modify(EState *estate,
3967 RangeTblEntry *rte,
3968 ResultRelInfo *resultRelInfo,
3969 CmdType operation,
3970 Plan *subplan,
3971 char *query,
3972 List *target_attrs,
3973 int values_end,
3974 bool has_returning,
3975 List *retrieved_attrs)
3976{
3977 PgFdwModifyState *fmstate;
3978 Relation rel = resultRelInfo->ri_RelationDesc;
3979 TupleDesc tupdesc = RelationGetDescr(rel);
3980 Oid userid;
3981 ForeignTable *table;
3982 UserMapping *user;
3983 AttrNumber n_params;
3984 Oid typefnoid;
3985 bool isvarlena;
3986 ListCell *lc;
3987
3988 /* Begin constructing PgFdwModifyState. */
3989 fmstate = (PgFdwModifyState *) palloc0(sizeof(PgFdwModifyState));
3990 fmstate->rel = rel;
3991
3992 /*
3993 * Identify which user to do the remote access as. This should match what
3994 * ExecCheckRTEPerms() does.
3995 */
3996 userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
3997
3998 /* Get info about foreign table. */
3999 table = GetForeignTable(RelationGetRelid(rel));
4000 user = GetUserMapping(userid, table->serverid);
4001
4002 /* Open connection; report that we'll create a prepared statement. */
4003 fmstate->conn = GetConnection(user, true, &fmstate->conn_state);
4004 fmstate->p_name = NULL; /* prepared statement not made yet */
4005
4006 /* Set up remote query information. */
4007 fmstate->query = query;
4008 if (operation == CMD_INSERT)
4009 {
4010 fmstate->query = pstrdup(fmstate->query);
4011 fmstate->orig_query = pstrdup(fmstate->query);
4012 }
4013 fmstate->target_attrs = target_attrs;
4014 fmstate->values_end = values_end;
4015 fmstate->has_returning = has_returning;
4016 fmstate->retrieved_attrs = retrieved_attrs;
4017
4018 /* Create context for per-tuple temp workspace. */
4019 fmstate->temp_cxt = AllocSetContextCreate(estate->es_query_cxt,
4020 "postgres_fdw temporary data",
4021 ALLOCSET_SMALL_SIZES);
4022

Callers 2

Calls 13

GetUserIdFunction · 0.85
GetForeignTableFunction · 0.85
GetUserMappingFunction · 0.85
list_lengthFunction · 0.85
getTypeOutputInfoFunction · 0.85
fmgr_infoFunction · 0.85
get_batch_size_optionFunction · 0.85
GetConnectionFunction · 0.70
palloc0Function · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected