v1-0001-Include-local-conds-in-epq-pathtarget.patch

application/octet-stream

Filename: v1-0001-Include-local-conds-in-epq-pathtarget.patch
Type: application/octet-stream
Part: 0
Message: Re: foreign join error "variable not found in subplan target list"

Patch

Format: format-patch
Series: patch v1-0001
Subject: Include local conds in epq pathtarget
File+
contrib/postgres_fdw/postgres_fdw.c 14 0
From 9a360fb23a30a7b79076dac8800963c0197f239a Mon Sep 17 00:00:00 2001
From: Richard Guo <guofenglinux@gmail.com>
Date: Wed, 10 Aug 2022 11:28:57 +0800
Subject: [PATCH v1] Include local conds in epq pathtarget

---
 contrib/postgres_fdw/postgres_fdw.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 16320170ce..4f16cfc7a1 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -5779,11 +5779,25 @@ static void
 add_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel,
 								Path *epq_path)
 {
+	PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) rel->fdw_private;
 	List	   *useful_pathkeys_list = NIL; /* List of all pathkeys */
 	ListCell   *lc;
 
 	useful_pathkeys_list = get_useful_pathkeys_for_relation(root, rel);
 
+	if (epq_path != NULL && useful_pathkeys_list != NIL)
+	{
+		/* Include columns required for evaluating the local conditions */
+		foreach(lc, fpinfo->local_conds)
+		{
+			RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
+
+			add_new_columns_to_pathtarget(epq_path->pathtarget,
+										  pull_var_clause((Node *) rinfo->clause,
+										  PVC_RECURSE_PLACEHOLDERS));
+		}
+	}
+
 	/* Create one path for each set of pathkeys we found above. */
 	foreach(lc, useful_pathkeys_list)
 	{
-- 
2.31.0