Hi,

While working on FDW DML pushdown, I ran into a copy-pasto in the
ExecForeignDelete documentation in fdwhandler.sgml:

     The data in the returned slot is used only if the <command>DELETE</>
     query has a <literal>RETURNING</> clause or the foreign table has
     an <literal>AFTER ROW</> trigger.  Triggers require all columns,
but the

I don't think the data is referenced by the AFTER ROW DELETE triggers.
Attached is a patch to fix that.  The patch also avoids adding an
unnecessary RETURNING clause to DELETE when deparsing a remote DELETE
statement in postgres_fdw.

I'll add this to the next CF.

Best regards,
Etsuro Fujita
*** a/contrib/postgres_fdw/deparse.c
--- b/contrib/postgres_fdw/deparse.c
***************
*** 1078,1085 **** deparseDeleteSql(StringInfo buf, PlannerInfo *root,
  	deparseRelation(buf, rel);
  	appendStringInfoString(buf, " WHERE ctid = $1");
  
! 	deparseReturningList(buf, root, rtindex, rel,
! 					   rel->trigdesc && rel->trigdesc->trig_delete_after_row,
  						 returningList, retrieved_attrs);
  }
  
--- 1078,1085 ----
  	deparseRelation(buf, rel);
  	appendStringInfoString(buf, " WHERE ctid = $1");
  
! 	/* No need to retrieve columns for AFTER ROW DELETE triggers */
! 	deparseReturningList(buf, root, rtindex, rel, false,
  						 returningList, retrieved_attrs);
  }
  
*** a/doc/src/sgml/fdwhandler.sgml
--- b/doc/src/sgml/fdwhandler.sgml
***************
*** 606,613 **** ExecForeignDelete (EState *estate,
  
      <para>
       The data in the returned slot is used only if the <command>DELETE</>
!      query has a <literal>RETURNING</> clause or the foreign table has
!      an <literal>AFTER ROW</> trigger.  Triggers require all columns, but the
       FDW could choose to optimize away returning some or all columns depending
       on the contents of the <literal>RETURNING</> clause.  Regardless, some
       slot must be returned to indicate success, or the query's reported row
--- 606,614 ----
  
      <para>
       The data in the returned slot is used only if the <command>DELETE</>
!      query has a <literal>RETURNING</> clause.  (Note that the data is not
!      referenced by <literal>AFTER ROW</> triggers on the foreign table in
!      the <command>DELETE</> case.)  The
       FDW could choose to optimize away returning some or all columns depending
       on the contents of the <literal>RETURNING</> clause.  Regardless, some
       slot must be returned to indicate success, or the query's reported row
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to