postgres_fdw: Remove duplicate code in DML execution callback functions.
authorEtsuro Fujita <efujita@postgresql.org>
Thu, 17 Jan 2019 05:37:33 +0000 (14:37 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Thu, 17 Jan 2019 05:37:33 +0000 (14:37 +0900)
postgresExecForeignInsert(), postgresExecForeignUpdate(), and
postgresExecForeignDelete() are coded almost identically, except that
postgresExecForeignInsert() does not need CTID.  Extract that code into
a separate function and use it in all the three function implementations.

Author: Ashutosh Bapat
Reviewed-By: Michael Paquier
Discussion: https://postgr.es/m/CAFjFpRcz8yoY7cBTYofcrCLwjaDeCcGKyTUivUbRiA57y3v-bw%40mail.gmail.com

contrib/postgres_fdw/postgres_fdw.c

index 64efbdff082227b2bdb9b7077de911eb4817663c..685259a00332085dde1e51cb85340e682f063dcf 100644 (file)
@@ -391,6 +391,11 @@ static PgFdwModifyState *create_foreign_modify(EState *estate,
                                          List *target_attrs,
                                          bool has_returning,
                                          List *retrieved_attrs);
+static TupleTableSlot *execute_foreign_modify(EState *estate,
+                                          ResultRelInfo *resultRelInfo,
+                                          CmdType operation,
+                                          TupleTableSlot *slot,
+                                          TupleTableSlot *planSlot);
 static void prepare_foreign_modify(PgFdwModifyState *fmstate);
 static const char **convert_prep_stmt_params(PgFdwModifyState *fmstate,
                                                 ItemPointer tupleid,
@@ -1776,58 +1781,8 @@ postgresExecForeignInsert(EState *estate,
                                                  TupleTableSlot *slot,
                                                  TupleTableSlot *planSlot)
 {
-       PgFdwModifyState *fmstate = (PgFdwModifyState *) resultRelInfo->ri_FdwState;
-       const char **p_values;
-       PGresult   *res;
-       int                     n_rows;
-
-       /* Set up the prepared statement on the remote server, if we didn't yet */
-       if (!fmstate->p_name)
-               prepare_foreign_modify(fmstate);
-
-       /* Convert parameters needed by prepared statement to text form */
-       p_values = convert_prep_stmt_params(fmstate, NULL, slot);
-
-       /*
-        * Execute the prepared statement.
-        */
-       if (!PQsendQueryPrepared(fmstate->conn,
-                                                        fmstate->p_name,
-                                                        fmstate->p_nums,
-                                                        p_values,
-