pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p
4+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2021-09-07 6ac763f19a e66add755d  Fix missing words in comment.
* pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p
@ 2021-08-12 08:38 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  2021-09-06 08:50 ` Re: pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Amit Langote <amitlangote09@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Heikki Linnakangas @ 2021-08-12 08:38 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix segfault during EvalPlanQual with mix of local and foreign partitions.

It's not sensible to re-evaluate a direct-modify Foreign Update or Delete
during EvalPlanQual. However, ExecInitForeignScan() can still get called
if a table mixes local and foreign partitions. EvalPlanQualStart() left
the es_result_relations array uninitialized in the child EPQ EState, but
ExecInitForeignScan() still expected to find it. That caused a segfault.

Fix by skipping the es_result_relations lookup during EvalPlanQual
processing. To make things a bit more robust, also skip the
BeginDirectModify calls, and add a runtime check that ExecForeignScan()
is not called on direct-modify foreign scans during EvalPlanQual
processing.

This is new in v14, commit 1375422c782. Before that, EvalPlanQualStart()
copied the whole ResultRelInfo array to the EPQ EState. Backpatch to v14.

Report and diagnosis by Andrey Lepikhov.

Discussion: https://www.postgresql.org/message-id/cb2b808d-cbaa-4772-76ee-c8809bafcf3d%40postgrespro.ru

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c3928b467a4f0ed2b0ef21a33848e9fcdade37b4

Modified Files
--------------
src/backend/executor/nodeForeignscan.c | 46 ++++++++++++++++++++++++++++++----
1 file changed, 41 insertions(+), 5 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p
  2021-08-12 08:38 pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Heikki Linnakangas <heikki.linnakangas@iki.fi>
@ 2021-09-06 08:50 ` Amit Langote <amitlangote09@gmail.com>
  2021-09-07 09:35   ` Re: pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 1 reply; 4+ messages in thread

From: Amit Langote @ 2021-09-06 08:50 UTC (permalink / raw)
  To: Heikki Linnakangas <heikki.linnakangas@iki.fi>; +Cc: pgsql-committers@lists.postgresql.org

On Thu, Aug 12, 2021 at 5:39 PM Heikki Linnakangas
<heikki.linnakangas@iki.fi> wrote:
> Fix segfault during EvalPlanQual with mix of local and foreign partitions.
>
> It's not sensible to re-evaluate a direct-modify Foreign Update or Delete
> during EvalPlanQual. However, ExecInitForeignScan() can still get called
> if a table mixes local and foreign partitions. EvalPlanQualStart() left
> the es_result_relations array uninitialized in the child EPQ EState, but
> ExecInitForeignScan() still expected to find it. That caused a segfault.
>
> Fix by skipping the es_result_relations lookup during EvalPlanQual
> processing. To make things a bit more robust, also skip the
> BeginDirectModify calls, and add a runtime check that ExecForeignScan()
> is not called on direct-modify foreign scans during EvalPlanQual
> processing.
>
> This is new in v14, commit 1375422c782. Before that, EvalPlanQualStart()
> copied the whole ResultRelInfo array to the EPQ EState. Backpatch to v14.
>
> Report and diagnosis by Andrey Lepikhov.
>
> Discussion: https://www.postgresql.org/message-id/cb2b808d-cbaa-4772-76ee-c8809bafcf3d%40postgrespro.ru

Thanks Heikki and Andrey for this.

Quite late but to I was looking at this and noticed this comment:

+       /*
+        * Direct modifications cannot be re-evaluated by EvalPlanQual, so
+        * don't bother preparing the FDW.  There can ForeignScan nodes in the
+        * EvalPlanQual subtree, but ExecForeignScan should never be called.
+        */

The 2nd sentence seems to be missing a "be" between "can" and
"ForeignScan".  Also, does it mean the following?

"There can be ForeignScan nodes in the EvalPlanQual plan subtree, but
ExecForeignScan should never be called on them [during EvalPlanQual]."

I've attached a patch that changes the text like that.

-- 
Amit Langote
EDB: http://www.enterprisedb.com

Attachments:

comment-tweak.patch (application/octet-stream, 822B) download diff --git a/src/backend/executor/nodeForeignscan.c b/src/backend/executor/nodeForeignscan.c index ad9edd26f1..1abd906b16 100644 --- a/src/backend/executor/nodeForeignscan.c +++ b/src/backend/executor/nodeForeignscan.c @@ -265,8 +265,9 @@ ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags) { /* * Direct modifications cannot be re-evaluated by EvalPlanQual, so - * don't bother preparing the FDW. There can ForeignScan nodes in the - * EvalPlanQual subtree, but ExecForeignScan should never be called. + * don't bother preparing the FDW. There can be ForeignScan nodes in + * the EvalPlanQual subtree, but ExecForeignScan should never be + * called on them when EvalPlanQual is active. */ if (estate->es_epq_active == NULL) fdwroutine->BeginDirectModify(scanstate, eflags);
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p
  2021-08-12 08:38 pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Heikki Linnakangas <heikki.linnakangas@iki.fi>
  2021-09-06 08:50 ` Re: pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Amit Langote <amitlangote09@gmail.com>
@ 2021-09-07 09:35   ` Heikki Linnakangas <hlinnaka@iki.fi>
  0 siblings, 0 replies; 4+ messages in thread

From: Heikki Linnakangas @ 2021-09-07 09:35 UTC (permalink / raw)
  To: Amit Langote <amitlangote09@gmail.com>; +Cc: pgsql-committers@lists.postgresql.org

On 06/09/2021 11:50, Amit Langote wrote:
> Quite late but to I was looking at this and noticed this comment:
> 
> +       /*
> +        * Direct modifications cannot be re-evaluated by EvalPlanQual, so
> +        * don't bother preparing the FDW.  There can ForeignScan nodes in the
> +        * EvalPlanQual subtree, but ExecForeignScan should never be called.
> +        */
> 
> The 2nd sentence seems to be missing a "be" between "can" and
> "ForeignScan".  Also, does it mean the following?
> 
> "There can be ForeignScan nodes in the EvalPlanQual plan subtree, but
> ExecForeignScan should never be called on them [during EvalPlanQual]."
> 
> I've attached a patch that changes the text like that.

Applied, thanks!

- Heikki





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p
@ 2021-08-12 08:38 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 4+ messages in thread

From: Heikki Linnakangas @ 2021-08-12 08:38 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix segfault during EvalPlanQual with mix of local and foreign partitions.

It's not sensible to re-evaluate a direct-modify Foreign Update or Delete
during EvalPlanQual. However, ExecInitForeignScan() can still get called
if a table mixes local and foreign partitions. EvalPlanQualStart() left
the es_result_relations array uninitialized in the child EPQ EState, but
ExecInitForeignScan() still expected to find it. That caused a segfault.

Fix by skipping the es_result_relations lookup during EvalPlanQual
processing. To make things a bit more robust, also skip the
BeginDirectModify calls, and add a runtime check that ExecForeignScan()
is not called on direct-modify foreign scans during EvalPlanQual
processing.

This is new in v14, commit 1375422c782. Before that, EvalPlanQualStart()
copied the whole ResultRelInfo array to the EPQ EState. Backpatch to v14.

Report and diagnosis by Andrey Lepikhov.

Discussion: https://www.postgresql.org/message-id/cb2b808d-cbaa-4772-76ee-c8809bafcf3d%40postgrespro.ru

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6458ed18fe40ac91f29496128dd1a49c0ef2db5b

Modified Files
--------------
src/backend/executor/nodeForeignscan.c | 46 ++++++++++++++++++++++++++++++----
1 file changed, 41 insertions(+), 5 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-09-07 09:35 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 08:38 pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Heikki Linnakangas <heikki.linnakangas@iki.fi>
2021-09-06 08:50 ` Amit Langote <amitlangote09@gmail.com>
2021-09-07 09:35   ` Heikki Linnakangas <hlinnaka@iki.fi>
2021-08-12 08:38 pgsql: Fix segfault during EvalPlanQual with mix of local and foreign p Heikki Linnakangas <heikki.linnakangas@iki.fi>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox