public inbox for [email protected]  
help / color / mirror / Atom feed
From: Etsuro Fujita <[email protected]>
To: Amit Langote <[email protected]>
Cc: Richard Guo <[email protected]>
Cc: Matheus Alcantara <[email protected]>
Cc: Ayush Tiwari <[email protected]>
Cc: Rafia Sabih <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Amit Langote <[email protected]>
Subject: Re: BUG #19484: Segmentation fault triggered by FDW
Date: Thu, 25 Jun 2026 02:02:41 +0900
Message-ID: <CAPmGK15do2D1YJFR2VST6+8BnADyZbiiY1hk+HhMGgFyBkE70Q@mail.gmail.com> (raw)
In-Reply-To: <CA+HiwqFd61sXgUWijKg8DfRQDtwYEGSdxuEPDb8rq22rxzxN_g@mail.gmail.com>
References: <[email protected]>
	<CAJTYsWXY9C3B-7NZw72OKen2L2rZt=c-t6=kjTJzgj=ZaNPe8g@mail.gmail.com>
	<[email protected]>
	<CA+FpmFc10Dtnr9dr=xqK2cNYQ4-1VuOyvOT7-eqXPmiQJoyPew@mail.gmail.com>
	<[email protected]>
	<CAJTYsWWUfgCZau2fvrZVruXmC+dyOx45L=TyaGzXdywsywDyHQ@mail.gmail.com>
	<[email protected]>
	<CA+HiwqHVMY1a5E+6Ei369+RqQ8qKSSgon_C=3yBk-TPJDwZ2nQ@mail.gmail.com>
	<CA+HiwqHjUO0uXFZ2dECJiNime6B1FDL5+mJ=XN+1XgzkY=m9DA@mail.gmail.com>
	<CAPmGK16GNiwcnAxM3XU=ZTOP_8oiv7_FOUwo5hZp8b+qfv2L7g@mail.gmail.com>
	<CA+HiwqEVwEPSE4yMvuwVT5bb+ziMHLfqd_HuiQPAFAixNHbhrQ@mail.gmail.com>
	<CA+HiwqHO0Bbi6cyk4F+UGvZEV3NEo7o0YT3-Js7K7hvasoWBVw@mail.gmail.com>
	<CAPmGK16fALJqbyR1Oir7-TsN8k_yAR-JcOg5nWOUmDmivTmDtA@mail.gmail.com>
	<CAPmGK14Qh_Wb4GNPNkZ1o9=vTcMKShzPNSWa=wNf9vJpg8qT+Q@mail.gmail.com>
	<CA+HiwqHRDsYDqJ-7f5P_QpJo=U1BYzMnfDnNOr6Vx3Rw36O0iQ@mail.gmail.com>
	<CAPmGK15nR_pePb9QAMViq+AGuWeJSqPnLTJVLsr96aU2TFmcmw@mail.gmail.com>
	<CA+HiwqFT0VDOCAdN1bcVZTOF0oBbR4kzLF-OwEcgPOf01me-Kw@mail.gmail.com>
	<CAPmGK15nx4a_QkTcbD2BwsDuDPtbS25Pzmq_sc-xM4EitoHaxw@mail.gmail.com>
	<CA+HiwqHTsZmceNHxVfmD0VVN-F1eMSuVQYVDWfsz3OSe+qoO7A@mail.gmail.com>
	<CA+HiwqEhe7-v5Q0-oOoW3RaO4voYcGK-JfinbYEWXwutDGSOtQ@mail.gmail.com>
	<CAMbWs4-hBR6H3AEv1LkcnRt04Q4zgVVUeOqmA6-W=DSP65s3Xw@mail.gmail.com>
	<CA+HiwqEbqW_957S9UAEoZJ5aYyBF_Bp+ON+6thQNCySxSwv+Fg@mail.gmail.com>
	<CAPmGK14CFGgCSCor1DHe6GVVQpjj+zDq755K5_vgc32U2+OGYQ@mail.gmail.com>
	<CA+HiwqFd61sXgUWijKg8DfRQDtwYEGSdxuEPDb8rq22rxzxN_g@mail.gmail.com>

Amit-san,

On Wed, Jun 24, 2026 at 8:20 PM Amit Langote <[email protected]> wrote:
> On Wed, Jun 24, 2026 at 6:15 PM Etsuro Fujita <[email protected]> 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






view thread (32+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: BUG #19484: Segmentation fault triggered by FDW
  In-Reply-To: <CAPmGK15do2D1YJFR2VST6+8BnADyZbiiY1hk+HhMGgFyBkE70Q@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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