| From: | Kirill Reshke <reshkekirill(at)gmail(dot)com> |
|---|---|
| To: | Nitin Motiani <nitinmotiani(at)google(dot)com> |
| Cc: | Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, tharakan(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, etsuro(dot)fujita(at)gmail(dot)com, Richard Guo <guofenglinux(at)gmail(dot)com> |
| Subject: | Re: BUG #19931: postgres_fdw: FOR UPDATE over a pushed-down join ignores a pseudoconstant qual |
| Date: | 2026-11-27 08:32:18 |
| Message-ID: | CALdSSPjp+V2V6OGyAbv5sVp7GqAAub-6xdHgnsMp+fK9O2G_Ag@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Fri, 27 Nov 2026 at 12:17, Nitin Motiani <nitinmotiani(at)google(dot)com> wrote:
>
> Thanks for the review, Matheus. I have created a commitfest entry for
> this here https://commitfest.postgresql.org/patch/7737.
>
> On Tue, Nov 24, 2026 at 10:03 PM Matheus Alcantara
> <matheusssilv97(at)gmail(dot)com> wrote:
> >
> > A small comment: I think that the changes on add_foreign_final_paths()
> > can be simplified into:
> >
> > + ForeignPath *fpath;
> > +
> > + if (IsA(path, ProjectionPath))
> > + fpath = (ForeignPath *) ((ProjectionPath *) path)->subpath;
> > + else
> > + fpath = (ForeignPath *) path;
> >
> > And then use fpath->fdw_restrictinfo on create_foreign_upper_path().
> >
> > --
>
> Have made this change. Also added a test for a 3-way join. Attaching
> the v2 patch. Please take a look.
>
>
> Thanks & Regards,
> Nitin Motiani
> Google
Hi Nitin,
Looks like there is one more case in add_foreign_final_paths() with no
needs no row locking. A generic plan for a LEFT JOIN with LIMIT 1 can
loose a bool parameter from the WHERE clause: example:
SET plan_cache_mode = force_generic_plan;
PREPARE q(boolean) AS
SELECT 42 FROM ft1 LEFT JOIN ft2 ON ft1.a = ft2.b
WHERE $1 LIMIT 1;
EXECUTE q(false);
This returned one row containing 42. I expected zero rows. A NULL
argument also returned one row. The same query over the local tables
returned zero rows for both arguments and one row for true.
Looks like this diff will do
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -1456,6 +1456,15 @@ postgresGetForeignPlan(PlannerInfo *root,
remote_exprs = extract_actual_clauses(fpinfo->remote_conds, false);
local_exprs = extract_actual_clauses(fpinfo->local_conds, false);
+ /*
+ * A pushed-down LIMIT on a join has no local gating Result. Keep
+ * shippable pseudoconstant WHERE clauses below the remote LIMIT.
+ */
+ if (has_limit && IS_JOIN_REL(foreignrel))
+ remote_exprs = list_concat(remote_exprs,
+ extract_actual_clauses(fpinfo->remote_conds,
+ true));
+
/*
* We leave fdw_recheck_quals empty in this case, since we never need
* to apply EPQ recheck clauses. In the case of a joinrel, EPQ
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql
b/contrib/postgres_fdw/sql/postgres_fdw.sql
index b71771a..76d260e 100644
But I didn't have time to fully review yet
--
Best regards,
Kirill Reshke
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hayato Kuroda (Fujitsu) | 2026-11-27 08:59:03 | RE: BUG #19892: Logical replication skips UPDATE/DELETE of rows with NULL in a hash-indexed subscriber column |
| Previous Message | Nitin Motiani | 2026-11-27 07:18:54 | Re: BUG #19737: Empty `JSON_OBJECT` cannot use documented `ON NULL` or unique-key clauses |