1919#include "aqo.h"
2020#include "access/parallel.h"
2121#include "optimizer/optimizer.h"
22+ #include "postgres_fdw.h"
2223#include "utils/queryenvironment.h"
2324
2425typedef struct
@@ -544,7 +545,7 @@ aqo_ExecutorEnd(QueryDesc *queryDesc)
544545void
545546aqo_copy_generic_path_info (PlannerInfo * root ,Plan * dest ,Path * src )
546547{
547- bool is_join_path ;
548+ bool is_join_path ;
548549
549550if (prev_copy_generic_path_info_hook )
550551prev_copy_generic_path_info_hook (root ,dest ,src );
@@ -569,6 +570,23 @@ aqo_copy_generic_path_info(PlannerInfo *root, Plan *dest, Path *src)
569570dest -> path_clauses = ((JoinPath * )src )-> joinrestrictinfo ;
570571dest -> path_jointype = ((JoinPath * )src )-> jointype ;
571572}
573+ else if (src -> type == T_ForeignPath )
574+ {
575+ ForeignPath * fpath = (ForeignPath * )src ;
576+ PgFdwRelationInfo * fpinfo = (PgFdwRelationInfo * )fpath -> path .parent -> fdw_private ;
577+
578+ /*
579+ * Pushed down foreign join keeps clauses in special fdw_private
580+ * structure.
581+ * I'm not sure what fpinfo structure keeps clauses for sufficient time.
582+ * So, copy clauses.
583+ */
584+ dest -> path_clauses = list_concat (list_copy (fpinfo -> joinclauses ),
585+ list_copy (fpinfo -> remote_conds ));
586+ dest -> path_clauses = list_concat (dest -> path_clauses ,
587+ list_copy (fpinfo -> local_conds ));
588+ dest -> path_jointype = ((JoinPath * )src )-> jointype ;
589+ }
572590else
573591{
574592dest -> path_clauses = list_concat (