* create_foreign_modify * Construct an execution state of a foreign insert/update/delete * operation */
| 3963 | * operation |
| 3964 | */ |
| 3965 | static PgFdwModifyState * |
| 3966 | create_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 |
no test coverage detected