Re: BUG #19484: Segmentation fault triggered by FDW

From: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, Rafia Sabih <rafia(dot)pghackers(at)gmail(dot)com>, 798604270(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Amit Langote <amitlan(at)postgresql(dot)org>
Subject: Re: BUG #19484: Segmentation fault triggered by FDW
Date: 2026-06-24 17:02:41
Message-ID: CAPmGK15do2D1YJFR2VST6+8BnADyZbiiY1hk+HhMGgFyBkE70Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Amit-san,

On Wed, Jun 24, 2026 at 8:20 PM Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> On Wed, Jun 24, 2026 at 6:15 PM Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com> wrote:
> > + /*
> > + * node->fdwPrivLists is indexed by the original, pre-pruning
> > + * result relation order and is parallel to node->resultRelations.
> > + * Initial pruning may have dropped earlier relations, so the kept
> > + * index j need not match the original position; find this
> > + * relation's entry by its range table index instead.
> > + */
> > + forboth(lc1, node->resultRelations, lc2, node->fdwPrivLists)
> > + {
> > + if (lfirst_int(lc1) == (int) rti)
> > + {
> > + fdw_private = (List *) lfirst(lc2);
> > + break;
> > + }
> > + }
> >
> > I think it's good to skip this for efficiency, when there are no
> > pruned result relations.
>
> Thanks for the review. v2 attached implements your suggestion: it
> indexes node->fdwPrivLists directly with j when no result relations
> were pruned, and only falls back to matching by range table index when
> pruning appears to have dropped some.

Thank you for doing that work!

This might be nitpicking, but:

+ if (list_length(node->resultRelations) == mtstate->mt_nrels)
+ fdw_private = (List *) list_nth(node->fdwPrivLists, j);
+ else
+ {
+ Index rti = resultRelInfo->ri_RangeTableIndex;
+ ListCell *lc1;
+ ListCell *lc2;
+
+ fdw_private = NIL;
+ forboth(lc1, node->resultRelations, lc2, node->fdwPrivLists)
+ {
+ if (lfirst_int(lc1) == (int) rti)
+ {
+ fdw_private = (List *) lfirst(lc2);
+ break;
+ }
+ }
+ }

I'd put the if-test outside of the outer loop to save cycles.

Other than that v2 looks good to me.

(The forboth loop actually causes an n-squared calculation, but it's
done only when pruning occurs, in which case the number of remaining
result relations would be reduced, so that wouldn't be a problem.)

Best regards,
Etsuro Fujita

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Masahiko Sawada 2026-06-24 17:46:54 Re: uuidv7 improperly accepts dates before 1970-01-01
Previous Message Baji Shaik 2026-06-24 15:25:11 Re: uuidv7 improperly accepts dates before 1970-01-01